InstantiationException:无法实例化类..没有空构造函数

时间:2012-12-13 19:07:15

标签: android

在以下代码中,它显示run()处的错误,因此,如果我将@override置于run()之上,则应用会在draw()显示错误。有人帮助完成基本步骤。这是代码:

    private class MyWallpaperEngine extends Engine {
            private final Handler handler = new Handler();
            private final Runnable drawRunner = new Runnable() {
                public void run() {
                    draw();
                }
            };
    }

12-14 00:55:24.111: W/dalvikvm(7141): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-14 00:55:24.181: E/AndroidRuntime(7141): FATAL EXCEPTION: main
12-14 00:55:24.181: E/AndroidRuntime(7141): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sri.alinwallpaper/com.sri.alinwallpaper.MyPoint}: java.lang.InstantiationException: can't instantiate class com.sri.alinwallpaper.MyPoint; no empty constructor
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.os.Looper.loop(Looper.java:137)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.app.ActivityThread.main(ActivityThread.java:4340)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at java.lang.reflect.Method.invokeNative(Native Method)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at java.lang.reflect.Method.invoke(Method.java:511)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at dalvik.system.NativeStart.main(Native Method)
12-14 00:55:24.181: E/AndroidRuntime(7141): Caused by: java.lang.InstantiationException: can't instantiate class com.sri.alinwallpaper.MyPoint; no empty constructor
12-14 00:55:24.181: E/AndroidRuntime(7141):     at java.lang.Class.newInstanceImpl(Native Method)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at java.lang.Class.newInstance(Class.java:1319)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
12-14 00:55:24.181: E/AndroidRuntime(7141):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
12-14 00:55:24.181: E/AndroidRuntime(7141):     ... 11 more
12-14 00:55:37.751: I/Process(7141): Sending signal. PID: 7141 SIG: 9

1 个答案:

答案 0 :(得分:1)

删除@Override注释。没有它应该可以正常工作。

根据the answer in this question,这是因为Java 5中的你不能将@Override注释与实现接口的方法一起使用,只能实现超类中方法的覆盖。