TableLayout table = (TableLayout) findViewById(R.id.TableLayout1);
TableRow row = new TableRow(this);
TextView t = new TextView(this);
t.setText(String.valueOf(day[i]));
row.addView(t);
table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
最后一条指令是给我"Unable to start activity component info: java.lang.NullPointerException"
. 但是,具有相同指令的干净项目中的相同代码不是......
是table.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
</TableLayout>
</LinearLayout>
日志:
04-27 14:19:27.267: E/AndroidRuntime(2503): FATAL EXCEPTION: main
04-27 14:19:27.267: E/AndroidRuntime(2503): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.seapredictions/com.seapredictions.ShowData}: java.lang.NullPointerException
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.os.Looper.loop(Looper.java:137)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-27 14:19:27.267: E/AndroidRuntime(2503): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 14:19:27.267: E/AndroidRuntime(2503): at java.lang.reflect.Method.invoke(Method.java:511)
04-27 14:19:27.267: E/AndroidRuntime(2503): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-27 14:19:27.267: E/AndroidRuntime(2503): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-27 14:19:27.267: E/AndroidRuntime(2503): at dalvik.system.NativeStart.main(Native Method)
04-27 14:19:27.267: E/AndroidRuntime(2503): Caused by: java.lang.NullPointerException
04-27 14:19:27.267: E/AndroidRuntime(2503): at com.seapredictions.ShowData.onCreate(ShowData.java:33)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.Activity.performCreate(Activity.java:4465)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-27 14:19:27.267: E/AndroidRuntime(2503): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-27 14:19:27.267: E/AndroidRuntime(2503): ... 11 more
04-27 14:19:27.636: I/dalvikvm(2503): threadid=3: reacting to signal 3
04-27 14:19:27.676: I/dalvikvm(2503): Wrote stack traces to '/data/anr/traces.txt'
04-27 14:19:27.807: I/dalvikvm(2503): threadid=3: reacting to signal 3
04-27 14:19:27.827: I/dalvikvm(2503): Wrote stack traces to '/data/anr/traces.txt'
04-27 14:19:27.887: D/dalvikvm(2503): GC_CONCURRENT freed 230K, 4% free 9243K/9543K, paused 3ms+3ms