-1

我正在编写一个应用程序,在我的主菜单类中有一个菜单 Inflater,我在这个菜单中有三个选项,即 Exit、AboutUs 和 Preferences。退出菜单项有效,但是当我触摸其他两个应用程序崩溃时。

任何修复它的帮助将不胜感激,我已经查看了清单,对我来说一切看起来都是正确的,并且所有类都已定义。

MenuInflater 代码:-

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    MenuInflater blowUp = getMenuInflater();
    blowUp.inflate(R.menu.main_menu, menu);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()){
        case R.id.aboutUs:
            Intent i = new Intent(MainMenu.this, AboutUs.class);
            startActivity(i);
            break;
        case R.id.prefs:
            Intent p = new Intent(MainMenu.this, Prefs.class);
            startActivity(p);
            break;
        case R.id.exit:
            finish();
            break;
    }
    return false;
}

每个项目的类:-

public class AboutUs extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
    }
}

public class Prefs extends PreferenceActivity{

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.prefs);
    }
}

日志猫:-

03-06 16:39:21.040: E/AndroidRuntime(23894): FATAL EXCEPTION: main
03-06 16:39:21.040: E/AndroidRuntime(23894): android.content.ActivityNotFoundException:  Unable to find explicit activity class {coursework.android.travelapp/coursework.android.travelapp.AboutUs}; have you declared this   activity in your AndroidManifest.xml?
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.app.Activity.startActivityForResult(Activity.java:3446)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at  android.app.Activity.startActivityForResult(Activity.java:3407)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.app.Activity.startActivity(Activity.java:3617)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.app.Activity.startActivity(Activity.java:3585)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at coursework.android.travelapp.MainMenu.onOptionsItemSelected(MainMenu.java:63)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.app.Activity.onMenuItemSelected(Activity.java:2629)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1047)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:180)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.widget.AdapterView.performItemClick(AdapterView.java:301)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.widget.AbsListView.performItemClick(AbsListView.java:1276)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3067)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.widget.AbsListView$1.run(AbsListView.java:3963)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.os.Handler.handleCallback(Handler.java:615)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.os.Looper.loop(Looper.java:137)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at android.app.ActivityThread.main(ActivityThread.java:4898)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at java.lang.reflect.Method.invokeNative(Native Method)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at java.lang.reflect.Method.invoke(Method.java:511)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-06 16:39:21.040: E/AndroidRuntime(23894):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

1

.ActivityNotFoundException:找不到明确的活动类

当您未在 androidmanifest.xml 中定义活动时,会发生此异常

像它一样定义它。

<activity android:name=".AboutUs" android:label="@string/app_name">
于 2013-03-06T16:50:20.533 回答
1

从您的 LogCat 中:

android.content.ActivityNotFoundException:  Unable to find explicit activity class 
    {coursework.android.travelapp/coursework.android.travelapp.AboutUs}; 
    have you declared this activity in your AndroidManifest.xml?

你?我推荐它。

于 2013-03-06T16:50:23.600 回答