我正在嘗試構建一個活動,其中列表視圖中的每個列表項都打開一個新活動。但每次運行應用程序,它都被迫關閉。請幫助guyzz。我正在嘗試它很長一段時間!下面是佈局文件:Android - 列表視圖 - 開始新的活動
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="C++ PROGRAMS"
android:textStyle="bold"
android:textSize="25sp" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
這裏是Java類:
public class Second_listview extends ListActivity{
static final String[] type = new String[]{
"Array", "Strings"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second_listview);
// setting up list view
setListAdapter (new ArrayAdapter<String>(this, android.R.id.list, type));
ListView list = getListView();
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
// TODO Auto-generated method stub
//linking each list item to start a new activity
switch(arg2)
{
case 1 : Intent myIntent1 = new Intent(view.getContext(), Array_list.class);
startActivityForResult(myIntent1, 0);
break;
case 2 : Intent myIntent2 = new Intent(view.getContext(), String_list.class);
startActivityForResult(myIntent2, 0);
break;
}
}
});
}
}
這裏是logcat的:
01-19 13:26:03.123: E/AndroidRuntime(1323): FATAL EXCEPTION: Thread-132
01-19 13:26:03.123: E/AndroidRuntime(1323): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.c_progams.CLEARSCREEN }
01-19 13:26:03.123: E/AndroidRuntime(1323): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
01-19 13:26:03.123: E/AndroidRuntime(1323): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-19 13:26:03.123: E/AndroidRuntime(1323): at android.app.Activity.startActivityForResult(Activity.java:3370)
01-19 13:26:03.123: E/AndroidRuntime(1323): at android.app.Activity.startActivityForResult(Activity.java:3331)
01-19 13:26:03.123: E/AndroidRuntime(1323): at android.app.Activity.startActivity(Activity.java:3566)
01-19 13:26:03.123: E/AndroidRuntime(1323): at android.app.Activity.startActivity(Activity.java:3534)
01-19 13:26:03.123: E/AndroidRuntime(1323): at com.example.c_progams.First_screen$1.run(First_screen.java:27)
這裏是清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.c_progams"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.c_progams.First_screen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.c_progams.Second_listview"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SECOND_LISTVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.c_progams.Array_list"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ARRAY_LIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.c_progams.String_list"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.STRING_LIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
貓在哪裏被稱爲登錄? (什麼是異常消息?) – Tobrun
我已經編輯它在我的問題! – user1977768
你可以發佈你的清單文件嗎? – 2013-01-19 14:05:42