0
我使用的ListView我的佈局,但在itemClick事件就說明這個錯誤:「不幸的是myappname已停止」的ListView onItemClick「不幸的myapp已停止」錯誤的Android
這是我的java代碼booking.java的onCreate方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.booking);
lv = (ListView) findViewById(R.id.list);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(), "Hello " + i, Toast.LENGTH_SHORT).show();
}
});
}
而且我的佈局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/booking"
>
<TextView
android:id="@+id/textView"
android:layout_width="302dp"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="8dp"
android:layout_marginTop="60dp"
android:text="TextView"
android:textAlignment="textStart"
android:textColor="#f0f0f0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.011" />
<ListView
android:id="@+id/list"
android:layout_width="302dp"
android:layout_height="398dp"
android:layout_marginLeft="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="11dp"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteY="97dp" />
</android.support.constraint.ConstraintLayout>
誰能幫我解決這個問題?
請給我一個日誌詳細 – redAllocator