Java Android Searchview导致应用程序崩溃

Java Android Searchview导致应用程序崩溃,java,android,android-intent,searchview,Java,Android,Android Intent,Searchview,谢谢你看这篇文章。我正试图在我的android应用程序actionbar中实现一个搜索视图(我将使用Parse来存储数据)。我遵循了谷歌的,以及我在网上找到的其他一些教程,但它不会起作用。每次我尝试在eclipse中启动应用程序时,它都会崩溃而不打开(之前没有searchview,它工作得很好) main.xml: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://s

谢谢你看这篇文章。我正试图在我的android应用程序actionbar中实现一个搜索视图(我将使用Parse来存储数据)。我遵循了谷歌的,以及我在网上找到的其他一些教程,但它不会起作用。每次我尝试在eclipse中启动应用程序时,它都会崩溃而不打开(之前没有searchview,它工作得很好)

main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.trashed.MainActivity" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
     <item
        android:id="@+id/action_toprated"
        android:icon="@drawable/ic_action_toprated"
        android:title="@string/action_toprated"
        app:showAsAction="always"/>

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:title="@string/action_search"
        app:showAsAction="always"
        android:actionViewClass="android.widget.SearchView"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_name"
        android:hint="@string/search_hint" />
import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class SearchResultsActivity extends Activity {

    private TextView txtQuery;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_results);

        // get the action bar
        ActionBar actionBar = getActionBar();

        // Enabling Back navigation on Action Bar icon
        actionBar.setDisplayHomeAsUpEnabled(true);

        txtQuery = (TextView) findViewById(R.id.txtQuery);

        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        handleIntent(intent);
    }

    /**
     * Handling intent data
     */
    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);

            /**
             * Use this query to display search results like
             * 1. Getting the data from SQLite and showing in listview
             * 2. Making webrequest and displaying the data
             * For now we just display the query only
             */
            txtQuery.setText("Search Query: " + query);

        }

    }
}
07-18 02:05:13.803: D/AndroidRuntime(2307): Shutting down VM
07-18 02:05:13.803: W/dalvikvm(2307): threadid=1: thread exiting with uncaught exception (group=0xb3ad8ba8)
07-18 02:05:13.833: E/AndroidRuntime(2307): FATAL EXCEPTION: main
07-18 02:05:13.833: E/AndroidRuntime(2307): Process: com.example.trashed, PID: 2307
07-18 02:05:13.833: E/AndroidRuntime(2307): java.lang.NullPointerException
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.example.trashed.MainActivity.onCreateOptionsMenu(MainActivity.java:55)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:233)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:200)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doFrame(Choreographer.java:543)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.handleCallback(Handler.java:733)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.dispatchMessage(Handler.java:95)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Looper.loop(Looper.java:136)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.ActivityThread.main(ActivityThread.java:5017)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invoke(Method.java:515)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at dalvik.system.NativeStart.main(Native Method)
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
错误日志:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.trashed.MainActivity" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
     <item
        android:id="@+id/action_toprated"
        android:icon="@drawable/ic_action_toprated"
        android:title="@string/action_toprated"
        app:showAsAction="always"/>

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:title="@string/action_search"
        app:showAsAction="always"
        android:actionViewClass="android.widget.SearchView"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_name"
        android:hint="@string/search_hint" />
import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class SearchResultsActivity extends Activity {

    private TextView txtQuery;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_results);

        // get the action bar
        ActionBar actionBar = getActionBar();

        // Enabling Back navigation on Action Bar icon
        actionBar.setDisplayHomeAsUpEnabled(true);

        txtQuery = (TextView) findViewById(R.id.txtQuery);

        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        handleIntent(intent);
    }

    /**
     * Handling intent data
     */
    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);

            /**
             * Use this query to display search results like
             * 1. Getting the data from SQLite and showing in listview
             * 2. Making webrequest and displaying the data
             * For now we just display the query only
             */
            txtQuery.setText("Search Query: " + query);

        }

    }
}
07-18 02:05:13.803: D/AndroidRuntime(2307): Shutting down VM
07-18 02:05:13.803: W/dalvikvm(2307): threadid=1: thread exiting with uncaught exception (group=0xb3ad8ba8)
07-18 02:05:13.833: E/AndroidRuntime(2307): FATAL EXCEPTION: main
07-18 02:05:13.833: E/AndroidRuntime(2307): Process: com.example.trashed, PID: 2307
07-18 02:05:13.833: E/AndroidRuntime(2307): java.lang.NullPointerException
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.example.trashed.MainActivity.onCreateOptionsMenu(MainActivity.java:55)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:233)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:200)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doFrame(Choreographer.java:543)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.handleCallback(Handler.java:733)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.dispatchMessage(Handler.java:95)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Looper.loop(Looper.java:136)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.ActivityThread.main(ActivityThread.java:5017)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invoke(Method.java:515)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at dalvik.system.NativeStart.main(Native Method)
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);

提前感谢

尝试编辑您的proguard并添加此行

-keep class android.support.v7.widget.SearchView { *; }

它对我很有用。

而不是使用
android:actionViewClass=“android.widget.SearchView”
使用
app:actionViewClass=“android.support.v7.SearchView”


旁注:确保在必要时使用支持库调用,而不是普通的调用。

您正在使用:
import android.Support.v7.widget.SearchView来自
支持库
,如果您查看日志,会发现:

at com.example.trashed.MainActivity.onCreateOptionsMenu(MainActivity.java:55)
问题来自
main活动
和此方法
oncreateoptions菜单

用以下内容替换搜索菜单:来自

就这样换了吧

另外,
ActionBarActivity
已被弃用,请改用
AppCompatActivity

而不是:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
         // Associate searchable configuration with the SearchView
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
                .getActionView();
        searchView.setSearchableInfo(searchManager
                .getSearchableInfo(getComponentName()));
        return super.onCreateOptionsMenu(menu);

    }
试着这样使用它:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.trashed.MainActivity" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
     <item
        android:id="@+id/action_toprated"
        android:icon="@drawable/ic_action_toprated"
        android:title="@string/action_toprated"
        app:showAsAction="always"/>

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:title="@string/action_search"
        app:showAsAction="always"
        android:actionViewClass="android.widget.SearchView"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_name"
        android:hint="@string/search_hint" />
import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class SearchResultsActivity extends Activity {

    private TextView txtQuery;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_results);

        // get the action bar
        ActionBar actionBar = getActionBar();

        // Enabling Back navigation on Action Bar icon
        actionBar.setDisplayHomeAsUpEnabled(true);

        txtQuery = (TextView) findViewById(R.id.txtQuery);

        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        handleIntent(intent);
    }

    /**
     * Handling intent data
     */
    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);

            /**
             * Use this query to display search results like
             * 1. Getting the data from SQLite and showing in listview
             * 2. Making webrequest and displaying the data
             * For now we just display the query only
             */
            txtQuery.setText("Search Query: " + query);

        }

    }
}
07-18 02:05:13.803: D/AndroidRuntime(2307): Shutting down VM
07-18 02:05:13.803: W/dalvikvm(2307): threadid=1: thread exiting with uncaught exception (group=0xb3ad8ba8)
07-18 02:05:13.833: E/AndroidRuntime(2307): FATAL EXCEPTION: main
07-18 02:05:13.833: E/AndroidRuntime(2307): Process: com.example.trashed, PID: 2307
07-18 02:05:13.833: E/AndroidRuntime(2307): java.lang.NullPointerException
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.example.trashed.MainActivity.onCreateOptionsMenu(MainActivity.java:55)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:233)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:200)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doFrame(Choreographer.java:543)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.handleCallback(Handler.java:733)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.dispatchMessage(Handler.java:95)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Looper.loop(Looper.java:136)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.ActivityThread.main(ActivityThread.java:5017)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invoke(Method.java:515)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at dalvik.system.NativeStart.main(Native Method)
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
相反:

SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
                .getActionView();
使用:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.trashed.MainActivity" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
     <item
        android:id="@+id/action_toprated"
        android:icon="@drawable/ic_action_toprated"
        android:title="@string/action_toprated"
        app:showAsAction="always"/>

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:title="@string/action_search"
        app:showAsAction="always"
        android:actionViewClass="android.widget.SearchView"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_name"
        android:hint="@string/search_hint" />
import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class SearchResultsActivity extends Activity {

    private TextView txtQuery;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_results);

        // get the action bar
        ActionBar actionBar = getActionBar();

        // Enabling Back navigation on Action Bar icon
        actionBar.setDisplayHomeAsUpEnabled(true);

        txtQuery = (TextView) findViewById(R.id.txtQuery);

        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        handleIntent(intent);
    }

    /**
     * Handling intent data
     */
    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);

            /**
             * Use this query to display search results like
             * 1. Getting the data from SQLite and showing in listview
             * 2. Making webrequest and displaying the data
             * For now we just display the query only
             */
            txtQuery.setText("Search Query: " + query);

        }

    }
}
07-18 02:05:13.803: D/AndroidRuntime(2307): Shutting down VM
07-18 02:05:13.803: W/dalvikvm(2307): threadid=1: thread exiting with uncaught exception (group=0xb3ad8ba8)
07-18 02:05:13.833: E/AndroidRuntime(2307): FATAL EXCEPTION: main
07-18 02:05:13.833: E/AndroidRuntime(2307): Process: com.example.trashed, PID: 2307
07-18 02:05:13.833: E/AndroidRuntime(2307): java.lang.NullPointerException
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.example.trashed.MainActivity.onCreateOptionsMenu(MainActivity.java:55)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:233)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:200)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer.doFrame(Choreographer.java:543)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.handleCallback(Handler.java:733)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Handler.dispatchMessage(Handler.java:95)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.os.Looper.loop(Looper.java:136)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at android.app.ActivityThread.main(ActivityThread.java:5017)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at java.lang.reflect.Method.invoke(Method.java:515)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-18 02:05:13.833: E/AndroidRuntime(2307):     at dalvik.system.NativeStart.main(Native Method)
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
重要的是:
MenuItemCompat
,因为您使用的是v7库

也请勾选此问题:


您能记录错误吗?@Haresh是的,很抱歉我没有添加它。MainActivity中的哪一行是55?searchView.setSearchableInfo(searchManagerNow我只有在发布时提交搜索时才会出错(在调试中工作正常)我看不到此“searchMenuItem”的定义