Android: Force close when trying to call Preferences.java
-
04-10-2019 - |
Question
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!
Solution
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.
OTHER TIPS
Same problem...I accidentally imported the "java.utils.prefs.Preferences" into my Main class and I had it imported into my Preferences class.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow