我正在用SearchView开发应用程序。
当我打开搜索视图,按“主页”并恢复启用“不要保持活动”选项的应用程序时,它会崩溃,但异常:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.github.ndczz.searchviewtest, PID: 20393
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.github.ndczz.searchviewtest/com.github.ndczz.searchviewtest.MainActivity}: java.lang.RuntimeException: Parcel android.os.Parcel@42e2e0b: Unmarshalling unknown type code 3801188 at offset 1980
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@42e2e0b: Unmarshalling unknown type code 3801188 at offset 1980
at android.os.Parcel.readValue(Parcel.java:2319)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2592)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:856)
at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2033)
at android.app.Activity.onRestoreInstanceState(Activity.java:1004)
at android.app.Activity.performRestoreInstanceState(Activity.java:959)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1163)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
菜单/ search.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/search"
android:icon="@android:drawable/ic_search_category_default"
android:title="Search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView" />
</menu>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search, menu);
return true;
}
}
答案 0 :(得分:2)
错误已在 appcompat 23.2.1
中修复答案 1 :(得分:0)
实际上这是 Support library 23.2.0
的错误,有两个解决方案
1)删除/禁用proguard
2)使用支持库23.2.1
所以用{/ p>替换com.android.support:appcompat-v7:23.2.0
com.android.support:appcompat-v7:23.2.1