简体   繁体   English

快速搜索android的问题

[英]problem with quick search android

Hi i'm trying to set up a quick search for my application but i only get a ClassNotFoundException after clicking the search button. 嗨,我正在尝试为我的应用程序设置快速搜索,但是单击搜索按钮后,我只会收到ClassNotFoundException。 I just want to show the user input in a Log. 我只想在日志中显示用户输入。 Here's what i got so far: 这是我到目前为止所得到的:

Manifets.xml 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.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_label"
    android:hint="@string/search_hint" >
</searchable>

SearchActivity.java 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 java.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 我使用的SDK版本是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: 在Mainefest.xml中,我将活动名称更改为<activity android:name=".searchExample.SearchActivity">我在活动之外的元数据中执行了相同的操作:

<!-- 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. 事实是,android在“ 清单常规属性 ”下的“清单”中定义了程序包名称,并且我在项目中更改了一些程序包名称,但清单未随我的更改进行更新。 So that's why i had to add this ".searchExample" which is the last name in the package where this activity is. 因此,这就是为什么我必须添加此“ .searchExample”的原因,这是此活动所在的程序包中的姓氏。

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. 但是无论如何,这也是为什么我们必须在清单中活动名称的开头添加点的原因,而我直到今天才知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM