微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

应用程序在运行时在android中崩溃?

如何解决应用程序在运行时在android中崩溃?

| 我正在用android制作一个小型应用程序以缩放图像,但该应用程序在运行时崩溃。这是代码
package new1.zoom;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;


    public class newzoom extends View {
        private Drawable image;
        private int zoomControler=200;
        public newzoom(Context context)
        {
        super(context);
        image=context.getResources().getDrawable(R.drawable.me);
        setFocusable(true);
        }
    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //here u can control the width and height of the images........ this line is very important
    image.setBounds((getWidth()/2)-zoomControler,(getHeight()/2)-zoomControler,(getWidth()/2)+zoomControler,(getHeight()/2)+zoomControler);
    image.draw(canvas);
    }
    @Override
    public boolean onKeyDown(int keyCode,KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
    zoomControler+=10;
    if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
    zoomControler-=10;
    if(zoomControler<10)
    zoomControler=10;
    invalidate();
    return true;
    }
    } 
有人可以帮我解决这个问题吗? 这是我的logcat文件
06-14 11:30:14.640: ERROR/AndroidRuntime(985): FATAL EXCEPTION: main
06-14 11:30:14.640: ERROR/AndroidRuntime(985): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{new1.zoom/new1.zoom.newzoom}: java.lang.InstantiationException: new1.zoom.newzoom
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2585)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.os.Looper.loop(Looper.java:123)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at java.lang.reflect.Method.invoke(Method.java:521)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at dalvik.system.NativeStart.main(Native Method)
06-14 11:30:14.640: ERROR/AndroidRuntime(985): Caused by: java.lang.InstantiationException: new1.zoom.newzoom
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at java.lang.class.newInstanceImpl(Native Method)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at java.lang.class.newInstance(Class.java:1429)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2577)
06-14 11:30:14.640: ERROR/AndroidRuntime(985):     ... 11 more
    

解决方法

        请通过给定的链接。它使用多点触控并点按以缩放图像:Android多点触控缩放。那里有一个链接:http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/它对我有用。请也尝试这个。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?