我試圖調試我的菜單活動,但它似乎不能顯示輸出。屏幕上的錯誤信息表示儲蓄指南(我的應用程序名稱)已停止工作。如果我從android菜單手動點擊我的應用程序,它說我的應用程序沒有安裝。但是,我的代碼中沒有錯誤。任何人都可以幫助我?android應用程序不會啓動
我的菜單活動代碼:
public class SavingsGuiderMenuActivity extends SavingsActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
ListView menuList = (ListView) findViewById(R.id.ListView_Menu);
String[] items = { getResources().getString(R.string.start),
getResources().getString(R.string.about),
getResources().getString(R.string.help) };
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, R.layout.menu_item, items);
menuList.setAdapter(adapt);
menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
// Note: if the list was built "by hand" the id could be used.
// As-is, though, each item has the same id
TextView textView = (TextView) itemClicked;
String strText = textView.getText().toString();
if (strText.equalsIgnoreCase(getResources().getString(R.string.start))) {
// Launch the app Activity
startActivity(new Intent(SavingsGuiderMenuActivity.this, SavingsGuiderAppActivity.class));
} else if (strText.equalsIgnoreCase(getResources().getString(R.string.help))) {
// Launch the Help Activity
startActivity(new Intent(SavingsGuiderMenuActivity.this, SavingsGuiderHelpActivity.class));
} else if (strText.equalsIgnoreCase(getResources().getString(R.string.about))) {
// Launch the about Activity
startActivity(new Intent(SavingsGuiderMenuActivity.this, SavingsGuiderAboutActivity.class));
}
}
});
}
}
我的清單:
<application
android:label="@string/splash"
android:debuggable="true"
android:icon="@drawable/saving">
<activity
android:name=".SavingsGuiderMenuActivity"
android:label="@string/splash">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
logcat的錯誤
07-22 03:18:24.712: E/ArrayAdapter(806): You must supply a resource ID for a TextView
07-22 03:18:24.772: E/AndroidRuntime(806): FATAL EXCEPTION: main
07-22 03:18:24.772: E/AndroidRuntime(806): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:386)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.ListView.onMeasure(ListView.java:1155)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.View.measure(View.java:12581)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:579)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:392)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.View.measure(View.java:12581)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4671)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.View.measure(View.java:12581)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4671)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.View.measure(View.java:12581)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.View.measure(View.java:12581)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4671)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-22 03:18:24.772: E/AndroidRuntime(806): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2062)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.View.measure(View.java:12581)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1038)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2382)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.os.Looper.loop(Looper.java:137)
07-22 03:18:24.772: E/AndroidRuntime(806): at android.app.ActivityThread.main(ActivityThread.java:4340)
07-22 03:18:24.772: E/AndroidRuntime(806): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 03:18:24.772: E/AndroidRuntime(806): at java.lang.reflect.Method.invoke(Method.java:511)
07-22 03:18:24.772: E/AndroidRuntime(806): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-22 03:18:24.772: E/AndroidRuntime(806): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-22 03:18:24.772: E/AndroidRuntime(806): at dalvik.system.NativeStart.main(Native Method)
07-22 03:18:24.772: E/AndroidRuntime(806): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
07-22 03:18:24.772: E/AndroidRuntime(806): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379)
07-22 03:18:24.772: E/AndroidRuntime(806): ... 33 more
查看logcat並從強制關閉應用程序的異常中發佈堆棧跟蹤。 – FoamyGuy 2012-07-22 02:41:38
我的logcat有很多錯誤,而且我看到他們中的大多數與數組適配器有關,還有線性佈局,相對等等,就好像我的xml佈局是我的問題的原因。那可能嗎? – honeybee 2012-07-22 03:10:04
可能是,編輯你的問題,併發布logcat我們將能夠幫助你更多。 – FoamyGuy 2012-07-22 03:11:02