gpt4 book ai didi

java - onOptionsItemSelected 发生致命异常

转载 作者:行者123 更新时间:2023-12-01 13:44:22 29 4
gpt4 key购买 nike

使用 Android Studio,我正在为我的应用程序创建设置(这是我第一次这样做)。我遇到了 onOptionsItemSelected 问题,我不知道如何继续。这是我的 LogCat:

FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ultimate.app.test/com.ultimate.app.SettingsActivity}; have you declared this activity in your AndroidManifest.xml? <!-- I have declareted it -->
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
at android.app.Activity.startActivityFromChild(Activity.java:3843)
at android.app.Activity.startActivityFromChild(Activity.java:3819)
at android.app.Activity.startActivityForResult(Activity.java:3395)
at android.app.Activity.startActivityForResult(Activity.java:3331)
at android.app.Activity.startActivity(Activity.java:3566)
at android.app.Activity.startActivity(Activity.java:3534)
at com.ultimate.app.Tab1Activity.onOptionsItemSelected(Tab1Activity.java:106)
at android.app.Activity.onMenuItemSelected(Activity.java:2548)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:166)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
at android.widget.AbsListView$1.run(AbsListView.java:3423)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5191)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)

list :

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
<activity android:name=".SettingsActivity"
android:screenOrientation="portrait"/>
</application>

这就是我的 java.class 中的内容:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {

int i = item.getItemId();
if (i == R.id.actiorn) {
Intent intent = new Intent(Tab1Activity.this,SettingsActivity.class);
Tab1Activity.this.startActivity(intent);
finish();
}
return true;

}

最佳答案

试试这个:

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
<activity android:name="com.ultimate.app.SettingsActivity"
android:screenOrientation="portrait"/>

关于java - onOptionsItemSelected 发生致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20460196/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com