0
當我開始我的活動我收到一個錯誤。這裏是我的活動:錯誤聲明TextViews
public class DebtList extends Activity {
String debtNames1, debtNames2, debtNames3, debtNames4, debtNames5 = null;
Double debtAmount1, debtAmount2, debtAmount3, debtAmount4, debtAmount5;
Double debtRate1, debtRate2, debtRate3, debtRate4, debtRate5;
Integer debtTerm1, debtTerm2, debtTerm3, debtTerm4, debtTerm5;
//Name Displays
TextView debtName1 = (TextView) findViewById(R.id.dispName1); //logcat states this is the location of the error
TextView debtName2 = (TextView) findViewById(R.id.dispName2);
TextView debtName3 = (TextView) findViewById(R.id.dispName3);
TextView debtName4 = (TextView) findViewById(R.id.dispName4);
TextView debtName5 = (TextView) findViewById(R.id.dispName5);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.debtlist);
這裏是logcat的副本:
10-20 05:59:15.014: D/AndroidRuntime(389): Shutting down VM
10-20 05:59:15.014: W/dalvikvm(389): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-20 05:59:15.094: D/dalvikvm(389): GC_FOR_MALLOC freed 5706 objects/305808 bytes in 68ms
10-20 05:59:15.094: E/AndroidRuntime(389): FATAL EXCEPTION: main
10-20 05:59:15.094: E/AndroidRuntime(389): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{biz.midl.debttracking/biz.midl.debttracking.DebtList}: java.lang.NullPointerException
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.os.Handler.dispatchMessage(Handler.java:99)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.os.Looper.loop(Looper.java:123)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-20 05:59:15.094: E/AndroidRuntime(389): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 05:59:15.094: E/AndroidRuntime(389): at java.lang.reflect.Method.invoke(Method.java:521)
10-20 05:59:15.094: E/AndroidRuntime(389): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-20 05:59:15.094: E/AndroidRuntime(389): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-20 05:59:15.094: E/AndroidRuntime(389): at dalvik.system.NativeStart.main(Native Method)
10-20 05:59:15.094: E/AndroidRuntime(389): Caused by: java.lang.NullPointerException
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.Activity.findViewById(Activity.java:1637)
10-20 05:59:15.094: E/AndroidRuntime(389): at biz.midl.debttracking.DebtList.<init>(DebtList.java:16)
10-20 05:59:15.094: E/AndroidRuntime(389): at java.lang.Class.newInstanceImpl(Native Method)
10-20 05:59:15.094: E/AndroidRuntime(389): at java.lang.Class.newInstance(Class.java:1429)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-20 05:59:15.094: E/AndroidRuntime(389): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
我試着做最後的TextView debtName1 = ......,它提供了相同的錯誤消息。
請讓我知道什麼可以做,以減輕錯誤。