Android简单绘图应用教程无法运行

时间:2017-06-24 19:03:09

标签: java android drawing

我正在使用此处找到的代码: https://github.com/codepath/android_guides/wiki/Basic-Painting-with-Views

我已经复制并粘贴了活动xml文件和java文件中的所有内容。当我尝试运行它时,应用程序立即崩溃。

<_>在activity_simple_drawing_view.xml中 第6行:工具:context =“。MainActivity”&gt; .MainActivity是红色的,这让我觉得作者忘了在教程中包含一个主要的活动。

android monitor:

06-24 14:41:29.140 1981-1981/? I/art: Late-enabling -Xcheck:jni

                                      [ 06-24 14:41:29.140   135:  375 I/         ]
                                      HWComposer -> eventControl
06-24 14:41:29.451 1981-1981/com.codepath.example.simpledrawapp D/ActivityThread: installProvider: context.getPackageName()=com.codepath.example.simpledrawapp
06-24 14:41:29.457 1981-1981/com.codepath.example.simpledrawapp I/InstantRun: starting instant run server: is main process
06-24 14:41:29.462 1981-1981/com.codepath.example.simpledrawapp D/ActivityThread: BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{191fcf34 com.codepath.example.simpledrawapp}}
06-24 14:41:29.465 1981-1981/com.codepath.example.simpledrawapp D/AndroidRuntime: Shutting down VM
06-24 14:41:29.466 1981-1981/com.codepath.example.simpledrawapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: com.codepath.example.simpledrawapp, PID: 1981
                                                                                  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.codepath.example.simpledrawapp/com.codepath.example.simpledrawapp.SimpleDrawingView}: java.lang.InstantiationException: class com.codepath.example.simpledrawapp.SimpleDrawingView has no zero argument constructor
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2366)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
                                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:162)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                      at android.os.Looper.loop(Looper.java:189)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:5532)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
                                                                                   Caused by: java.lang.InstantiationException: class com.codepath.example.simpledrawapp.SimpleDrawingView has no zero argument constructor
                                                                                      at java.lang.Class.newInstance(Class.java:1563)
                                                                                      at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2356)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519) 
                                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:162) 
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) 
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                      at android.os.Looper.loop(Looper.java:189) 
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:5532) 
                                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                                      at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950) 
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) 
                                                                                   Caused by: java.lang.NoSuchMethodException: <init> []
                                                                                      at java.lang.Class.getConstructor(Class.java:531)
                                                                                      at java.lang.Class.getDeclaredConstructor(Class.java:510)
                                                                                      at java.lang.Class.newInstance(Class.java:1561)
                                                                                      at android.app.Instrumentation.newActivity(Instrumentation.java:1065) 
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2356) 
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519) 
                                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:162) 
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) 
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                      at android.os.Looper.loop(Looper.java:189) 
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:5532) 
                                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                                      at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950) 
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) 
06-24 14:41:46.418 1981-1981/? I/Process: Sending signal. PID: 1981 SIG: 9

0 个答案:

没有答案