Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

android - java.lang.InstantiationException: class com.example.camera.MainActivity has no zero argument constructor

03-02 12:03:23.564: D/AndroidRuntime(9302): Shutting down VM
03-02 12:03:23.570: E/AndroidRuntime(9302): FATAL EXCEPTION: main
03-02 12:03:23.570: E/AndroidRuntime(9302): Process: com.example.camera, PID: 9302
03-02 12:03:23.570: E/AndroidRuntime(9302): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.camera/com.example.camera.MainActivity}: java.lang.InstantiationException: class com.example.camera.MainActivity has no zero argument constructor
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.app.ActivityThread.access$800(ActivityThread.java:148)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.os.Handler.dispatchMessage(Handler.java:102)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.os.Looper.loop(Looper.java:135)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.app.ActivityThread.main(ActivityThread.java:5312)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at java.lang.reflect.Method.invoke(Native Method)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at java.lang.reflect.Method.invoke(Method.java:372)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
03-02 12:03:23.570: E/AndroidRuntime(9302): Caused by: java.lang.InstantiationException: class com.example.camera.MainActivity has no zero argument constructor
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at java.lang.Class.newInstance(Class.java:1563)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1088)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	... 10 more
03-02 12:03:23.570: E/AndroidRuntime(9302): Caused by: java.lang.NoSuchMethodException: <init> []
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at java.lang.Class.getConstructor(Class.java:531)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at java.lang.Class.getDeclaredConstructor(Class.java:510)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	at java.lang.Class.newInstance(Class.java:1561)
03-02 12:03:23.570: E/AndroidRuntime(9302): 	... 12 more
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Get rid of your MainActivity(Context context, Camera camera) constructor. No code will ever use it. Move its code somewhere else.

Then, get rid of your MainActivity() constructor, and just inherit the superclass' constructor.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...