-2
TextView t =(TextView)findViewById(R.id.place);
t.setText("A");
我在onCreate()
方法中調用上面的代碼。我的活動是一個ListActivity。但是,爲什麼這給了我下面的錯誤空指針設置值爲TextView的例外
05-04 14:21:40.840: E/AndroidRuntime(16168): Caused by: java.lang.NullPointerException
這裏是我定義的TextView
<TextView android:id="@+id/place"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16sp"
android:textStyle="bold"
android:focusable="false"
android:text=""
android:layout_gravity="left"/>
,以及如何解決它的XML?
發佈一些更多代碼 –
findViewById()返回視圖如果找到,否則返回null。 – yorkw
@ dinesh707可以發佈你的onCreate方法代碼 – AndroidDev