0

I want a menu when I click the menu button on an android device and I have created a method and other stuff in this. It was on another project bt I took the code and adapted it into my new project! earlier it worked fine bt, now the activity force closes! I could'nt find the error! please help me!

the method ---->

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    case R.id.about:
        Intent contextmenu = new Intent("com.sliit.droidman.main.About");
        startActivity(contextmenu);
        break;
    case R.id.exit:
        finish();
        break;
    }
    return false;
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    MenuInflater droidmenu = getMenuInflater();
    droidmenu.inflate(R.menu.contextmenu, menu);
    return true;
}

The logcat log, from where the error occures!

 07-05 17:11:43.419: W/dalvikvm(4546): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
 07-05 17:11:43.448: E/AndroidRuntime(4546): FATAL EXCEPTION: main
 07-05 17:11:43.448: E/AndroidRuntime(4546): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.sliit.droidman.main.About }
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.app.Activity.startActivityForResult(Activity.java:3351)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.app.Activity.startActivityForResult(Activity.java:3312)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.app.Activity.startActivity(Activity.java:3522)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.app.Activity.startActivity(Activity.java:3490)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at com.sliit.droidman.main.MainActivity.onMenuItemSelected(MainActivity.java:130)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:958)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:166)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at      android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.widget.AbsListView$1.run(AbsListView.java:3529)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.os.Handler.handleCallback(Handler.java:615)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.os.Handler.dispatchMessage(Handler.java:92)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.os.Looper.loop(Looper.java:137)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at android.app.ActivityThread.main(ActivityThread.java:4745)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at java.lang.reflect.Method.invokeNative(Native Method)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at java.lang.reflect.Method.invoke(Method.java:511)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at      com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
 07-05 17:11:43.448: E/AndroidRuntime(4546):    at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

1

To start your "About"-activity, simply use

startActivity(new Intent(this, About.class));

The logcat error means that either your Activity com.sliit.droidman.main.About doesn't exist, is in another project, or not defined in the manifest.

于 2012-07-07T15:43:53.363 回答
0

You need to define the Activity in your manifest file, look in your manifest and look at the previously defined Activity and create a new one and make changes where you need them.

于 2012-07-07T15:42:45.470 回答
0

try as:

    Intent intent = new Intent("com.sliit.droidman.main.About");
    final ComponentName cn = new 
    ComponentName("com.sliit.droidman.main","com.sliit.droidman.main.About");
    intent.setComponent(cn);
    startActivity(intent);


and make sure you have added android.intent.action.DEFAULT intent-filter with About as:

<activity android:name=".About"
          android:label="@string/app_name">
 </intent-filter>
     <intent-filter>
          <action android:name="com.sliit.droidman.main.About" />
          <category android:name="android.intent.category.DEFAULT" />
     </intent-filter>
</activity>

于 2012-07-07T15:56:12.727 回答