我正在嘗試創建一個列出與會者的註冊應用程序(位於TextView
)。點擊與會者後,應該看到另一個視圖。在運行期間在OnclickListener
處獲得NullpointerException
。TextView中的NullPointerException OnclickListener
郵件視圖佈局的xml:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#ffffff"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textStyle="bold"
android:clickable="true"
android:text="text1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#ffffff"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textStyle="bold"
android:clickable="true"
android:text="text2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#ffffff"
android:layout_weight="1"
android:textStyle="bold"
android:clickable="true"
android:gravity="center_horizontal"
android:text="text3" />
的OnClick查看XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal"
android:src="@drawable/img1"/>
主要活動:
public class MenuActivity extends ListActivity {
TextView text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
text1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.onclickview);
}
});
}
}
的重複:http://stackoverflow.com/questions/41321754/android-null-pointer-exception -on-my-database –
http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it的副本 – Noorul