找不到活动来处理Intent异常

时间:2014-06-11 23:41:07

标签: android android-intent android-activity

我遇到了问题。当我尝试拨打新的Activity时,在这种情况下com.joaocarreira.familylocator.prefs,应用程序崩溃了:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.joaocarreira.familylocator.Prefs } 

我一直在网上搜索,似乎都与我的AndroidManifest文件有关。

AndroidManifest

<activity
        android:name="com.joaocarreira.familylocator.Prefs"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.PREFS" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

活动电话

case R.id.action_settings:
            Intent prefs = new Intent("com.joaocarreira.familylocator.Prefs");
            startActivity(prefs);
            break;

Prefs Class

public class Prefs extends PreferenceActivity{

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.xml.prefs);
}
}

logcat的

06-11 17:43:47.422    1097-1097/com.joaocarreira.familylocator E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.joaocarreira.familylocator, PID: 1097
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.joaocarreira.familylocator.Prefs }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
        at android.app.Activity.startActivityForResult(Activity.java:3424)
        at android.app.Activity.startActivityForResult(Activity.java:3385)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
        at android.app.Activity.startActivity(Activity.java:3627)
        at android.app.Activity.startActivity(Activity.java:3595)
        at com.joaocarreira.familylocator.MainActivity.onOptionsItemSelected(MainActivity.java:164)
        at android.app.Activity.onMenuItemSelected(Activity.java:2600)
        at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:372)
        at android.support.v7.app.ActionBarActivity.superOnMenuItemSelected(ActionBarActivity.java:244)
        at android.support.v7.app.ActionBarActivityDelegateICS.onMenuItemSelected(ActionBarActivityDelegateICS.java:164)
        at android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:130)
        at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onMenuItemSelected(ActionBarActivityDelegateICS.java:308)
        at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1012)
        at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
        at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
        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:299)
        at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
        at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
        at android.widget.AbsListView$3.run(AbsListView.java:3638)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

而不是

Intent prefs = new Intent("com.joaocarreira.familylocator.Prefs");

使用

Intent prefs = new Intent(CallingActivity.this, Prefs.class);

或尝试完整的合格名称:

Intent prefs = new Intent(CallingActivity.this, com.joaocarreira.familylocator.Prefs.class);