我的問題是開始新的活動。 我有ListView
,它的項目是從字符串數組這段代碼定義:開始新活動時出現LogCATError
listBanksUA = getResources().getStringArray(R.array.list_banks_ua);
setListAdapter(new ArrayAdapter<String(this,android.R.layout.simple_list_item_1,listBanksUA));
列表在佈局定義爲:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
所以,我想以後開始新的活動點擊ListView
的項目。當然,我已經創造了新的XML佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/listRegions"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
和Java的類是:ListRegionsActivity.class
。 在我的第一Activity
我使用的後續代碼開始新Activity
:
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
startActivity(new Intent(MainActivity.this,ListRegionsActivity.class));
}
和點擊後啓動的應用程序,我得到一個錯誤,我的應用程序已經關閉與建議再試一次。悲傷...
所以,真的,我會很高興爲我的任何幫助。順便說一句:當然,我添加了新的活動清單文件。
UPD:我logcat的,錯誤標誌
08-15 13:46:45.458: ERROR/AndroidRuntime(516): Uncaught handler: thread main exiting due to uncaught exception
08-15 13:46:45.488: ERROR/AndroidRuntime(516): java.lang.RuntimeException: Unable to start activity ComponentInfo{ua.donetsk.jeston.android/ua.donetsk.jeston.android.ListRegionsActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.os.Looper.loop(Looper.java:123)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.main(ActivityThread.java:4203)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at java.lang.reflect.Method.invoke(Method.java:521)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at dalvik.system.NativeStart.main(Native Method)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ListActivity.onContentChanged(ListActivity.java:236)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.Activity.setContentView(Activity.java:1620)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at ua.donetsk.jeston.android.ListRegionsActivity.onCreate(ListRegionsActivity.java:15)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): ... 11 more
UPD:問題就解決了。原因是在打開avtivity錯誤的錯誤 - setContentView應該被刪除。
Logcat中有什麼錯誤? – Kurru
java.lang.RuntimeException:你的內容必須有一個ListView,它的id屬性是'android.R.id.list' – Eugene