zadorinka
zadorinka

Reputation: 11

Could not found the reason of ActivityNotFoundException

I get ActivityNotFoundException without any visible reasons. I'm new at Android, so I need help.

I created menu and run activity from onOptionsItemSelected:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
   public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
      case R.id.settings:
         startActivity(new Intent(this, Settings.class));
         return true;
      }
      return false;
   }

Settings class:

public class Settings extends PreferenceActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.settings);
   }
}

menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/settings"
    android:title="@string/action_settings"/>
</menu>

settings.xml :

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory>
<ListPreference
   android:title="@string/menu_language_settings"
   android:key="languagePreferences"
   android:entries="@array/langPreferencesArray"
   android:entryValues="@array/langPreferencesValues" />
<Preference
   android:title="@string/menu_help"
   android:key="helpPreferences" /> 
</PreferenceCategory>
</PreferenceScreen>  

And of course I've added activity declaration in manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.symbolrecogniser"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.symbolrecogniser.StartAppActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.symbolrecogniser.Settings"
        android:label="@string/settings_title">
    </activity>
</application>

>

Does somebody have any ideas?

Here is the logCat:

05-13 01:07:44.169: E/AndroidRuntime(23122): FATAL EXCEPTION: main
05-13 01:07:44.169: E/AndroidRuntime(23122): android.content.ActivityNotFoundException:  Unable to find explicit activity class {com.example.symbolrecogniser/android.provider.Settings}; have you declared this activity in your AndroidManifest.xml?
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.app.Activity.startActivityForResult(Activity.java:2827)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.app.Activity.startActivity(Activity.java:2933)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.example.symbolrecogniser.StartAppActivity.onOptionsItemSelected(StartAppActivity.java:34)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.app.Activity.onMenuItemSelected(Activity.java:2205)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:756)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.view.View$PerformClick.run(View.java:9080)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.os.Handler.handleCallback(Handler.java:587)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.os.Looper.loop(Looper.java:123)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at android.app.ActivityThread.main(ActivityThread.java:3729)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at java.lang.reflect.Method.invokeNative(Native Method)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at java.lang.reflect.Method.invoke(Method.java:507)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
05-13 01:07:44.169: E/AndroidRuntime(23122):    at dalvik.system.NativeStart.main(Native Method)

Upvotes: 1

Views: 220

Answers (2)

Michael Butscher
Michael Butscher

Reputation: 10959

Check the "import" statements of the file where the first code snippet is from. Somewhere there is probably

import android.provider.Settings;

which imports the wrong Settings class.

Upvotes: 1

Michael Butscher
Michael Butscher

Reputation: 10959

Are you sure that the package declared in "package" attribute of the <manifest> tag is the same where Settings class is in (not a subpackage)?

If not, you must declare the activity class with full name including package in "android:name" attribute in the manifest.

Upvotes: 2

Related Questions