Android: Force close when trying to call Preferences.java

落花浮王杯 提交于 2019-12-11 18:46:54

问题


Been trying to call Preferences.java class using:

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

I have this in my Manifest.xml (outside the main app class activity):

<application>
   ........

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

      </activity>
    </application>

And I still get force close for "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)

No Compiling errors... just this Runtime error... Any ideas why it's force closing even though I have the Activity defined in the Manifest.xml?

Appreciate any help!


回答1:


It looks like you have an import statement mix-up. Look at the 2nd line about "java.util.prefs.Preferences". Either change your imports or fully qualify your reference to your Preference activity.




回答2:


Same problem...I accidentally imported the "java.utils.prefs.Preferences" into my Main class and I had it imported into my Preferences class.



来源:https://stackoverflow.com/questions/3781097/android-force-close-when-trying-to-call-preferences-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!