Hi i'm trying to set up a quick search for my application but i only get a ClassNotFoundException after clicking the search button. I just want to show the user input in a Log. Here's what i got so far:
Manifets.xml
<activity android:name=".SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<!-- declare the default searchable Activity for the whole app -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity"/>
searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:hint="@string/search_hint" >
</searchable>
SearchActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchresults);
final Intent queryIntent = getIntent();
final String queryAction = queryIntent.getAction();
if (Intent.ACTION_SEARCH.equals(queryAction)) {
String searchKeywords = queryIntent.getStringExtra(SearchManager.QUERY);
Log.i("YOU ENTERED", searchKeywords);
}
}
What i'm i doing wrong? Any help will be really appreciated.
Thanks!!
EDIT: here is the log file:
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{se.madcoderz.searchExample/se.madcoderz.searchExample.SearchActivity}: java.lang.ClassNotFoundException: se.madcoderz.searchExample.SearchActivity in loader dalvik.system.PathClassLoader[/data/app/se.madcoderz.searchExample-2.apk]
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.os.Looper.loop(Looper.java:123)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at ja开发者_开发技巧va.lang.reflect.Method.invoke(Method.java:521)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at dalvik.system.NativeStart.main(Native Method)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): Caused by: java.lang.ClassNotFoundException: se.madcoderz.searchExample.SearchActivity in loader dalvik.system.PathClassLoader[/data/app/se.madcoderz.searchExample-2.apk]
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-18 13:34:03.479: ERROR/AndroidRuntime(28349): ... 11 more
The SDK version i'm using is 1.6
Well i solved my own problem. In the Mainefest.xml i changed the activity name to <activity android:name=".searchExample.SearchActivity">
i did the same in the meta-data outside the activity:
<!-- declare the default searchable Activity for the whole app -->
<meta-data android:name="android.app.default_searchable"
android:value=".searchExample.SearchActivity"/>
the thing is that android defines the package name in the Manifest under Manifest General Attributes and i changed some packages names in my project, but the manifest didn't got updated with my changes. So that's why i had to add this ".searchExample" which is the last name in the package where this activity is.
But anyways this is also the reason why we have to add a dot at the start of an activity name in the manifest, which i hadn't until today.
精彩评论