我正在开发一个 Android 应用程序。在我的应用程序中,我向另一个类发起了一个 Intent。一旦发生这种情况,应用程序就会崩溃。它说它不能实例化我的类。我的代码如下:
public class CustomObject extends Activity{
ArrayList<String> Alerts;
ArrayList<String> Names;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Names = intent.getExtras().getStringArrayList("Names");
Alerts = intent.getExtras().getStringArrayList("Alerts");
}
public CustomObject(ArrayList<String> prop1, ArrayList<String> prop2) {
this.Names = prop1;
this.Alerts = prop2;
}
public ArrayList<String> getProp1() {
return Names;
}
public ArrayList<String> getProp2() {
return Alerts;
}
}
这是我的 LogCat:
10-24 19:56:25.234: E/AndroidRuntime(12982): FATAL EXCEPTION: main
10-24 19:56:25.234: E/AndroidRuntime(12982): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dev.chicagotraintracker/com.dev.chicagotraintracker.CustomObject}: java.lang.InstantiationException: can't instantiate class com.dev.chicagotraintracker.CustomObject; no empty constructor
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.os.Looper.loop(Looper.java:137)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-24 19:56:25.234: E/AndroidRuntime(12982): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 19:56:25.234: E/AndroidRuntime(12982): at java.lang.reflect.Method.invoke(Method.java:525)
10-24 19:56:25.234: E/AndroidRuntime(12982): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-24 19:56:25.234: E/AndroidRuntime(12982): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-24 19:56:25.234: E/AndroidRuntime(12982): at dalvik.system.NativeStart.main(Native Method)
10-24 19:56:25.234: E/AndroidRuntime(12982): Caused by: java.lang.InstantiationException: can't instantiate class com.dev.chicagotraintracker.CustomObject; no empty constructor
10-24 19:56:25.234: E/AndroidRuntime(12982): at java.lang.Class.newInstanceImpl(Native Method)
10-24 19:56:25.234: E/AndroidRuntime(12982): at java.lang.Class.newInstance(Class.java:1130)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-24 19:56:25.234: E/AndroidRuntime(12982): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
10-24 19:56:25.234: E/AndroidRuntime(12982): ... 11 more
我在我的代码中找不到问题。其他一些问题已经说明了无参数构造函数,但我该如何实现呢?这还是我的问题吗?谢谢您的帮助。