Android:尝试调用Preferences.java时强制关闭

时间:2010-09-23 17:41:36

标签: android android-manifest android-preferences

尝试使用以下方法调用Preferences.java类:

Intent settingsActivity = new Intent(getBaseContext(), Preferences.class);
startActivity(settingsActivity);

我在Manifest.xml中有这个(在主app类活动之外):

<application>
   ........

    <activity android:name=".Preferences" android:label="Preferences">

      </activity>
    </application>

我仍然为“android.content.ActivityNotFound ...”强行关闭:

E/AndroidRuntime(25644): FATAL EXCEPTION: main
E/AndroidRuntime(25644): android.content.ActivityNotFoundException: Unable to fi
nd explicit activity class {com./java.util.prefs.Preferences};
 have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime(25644):        at android.app.Instrumentation.checkStartActivit
yResult(Instrumentation.java:1404)
E/AndroidRuntime(25644):        at android.app.Instrumentation.execStartActivity
(Instrumentation.java:1378)
E/AndroidRuntime(25644):        at android.app.Activity.startActivityForResult(A
ctivity.java:2817)
E/AndroidRuntime(25644):        at android.app.Activity.startActivity(Activity.j
ava:2923)
E/AndroidRuntime(25644):        at com.droidil.droidmarks.Dmarks.onOptionsItemSe
lected(Dmarks.java:337)
E/AndroidRuntime(25644):        at android.app.Activity.onMenuItemSelected(Activ
ity.java:2195)
E/AndroidRuntime(25644):        at com.android.internal.policy.impl.PhoneWindow.
onMenuItemSelected(PhoneWindow.java:730)
E/AndroidRuntime(25644):        at com.android.internal.view.menu.MenuItemImpl.i
nvoke(MenuItemImpl.java:143)
E/AndroidRuntime(25644):        at com.android.internal.view.menu.MenuBuilder.pe
rformItemAction(MenuBuilder.java:855)
E/AndroidRuntime(25644):        at com.android.internal.view.menu.IconMenuView.i
nvokeItem(IconMenuView.java:532)
E/AndroidRuntime(25644):        at com.android.internal.view.menu.IconMenuItemVi
ew.performClick(IconMenuItemView.java:122)
E/AndroidRuntime(25644):        at android.view.View$PerformClick.run(View.java:
8818)
E/AndroidRuntime(25644):        at android.os.Handler.handleCallback(Handler.jav
a:587)
E/AndroidRuntime(25644):        at android.os.Handler.dispatchMessage(Handler.ja
va:92)
E/AndroidRuntime(25644):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(25644):        at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime(25644):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(25644):        at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime(25644):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(25644):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime(25644):        at dalvik.system.NativeStart.main(Native Method)

没有编译错误......只是这个运行时错误...... 即使我在Manifest.xml中定义了Activity,也有任何关于它为什么会强制关闭的想法?

感谢任何帮助!

2 个答案:

答案 0 :(得分:3)

看起来你有一个import语句混淆。看看关于“java.util.prefs.Preferences”的第二行。您可以更改导入或完全限定对Preference活动的引用。

答案 1 :(得分:0)

同样的问题......我不小心将“java.utils.prefs.Preferences”导入了我的Main类,并将其导入到我的Preferences类中。