gpt4 book ai didi

android - 构建apk后的错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:51:47 25 4
gpt4 key购买 nike

操作栏 View (共享操作提供程序和搜索 View )在生成签名的 apk 后崩溃。当我从 android studio 调试应用程序时,它正在运行,但是当我生成签名的 apk 并将应用程序安装到设备时,我收到如下错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setQueryHint(java.lang.CharSequence)' on a null object reference
at tm.veriloft.ertir.ui.SearchActivity.onCreateOptionsMenu(Unknown Source)
at android.app.Activity.onCreatePanelMenu(Activity.java:2820)
at android.support.v4.app.o.onCreatePanelMenu(Unknown Source)
at android.support.v7.app.e.a(Unknown Source)
at android.support.v7.app.g.a(Unknown Source)
at android.support.v7.widget.as.a(Unknown Source)
at android.support.v7.internal.a.a.j(Unknown Source)
at android.support.v7.internal.a.b.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.ah.a(android.content.Intent)' on a null object reference
at tm.veriloft.ertir.ui.BlogViewActivity.onCreateOptionsMenu(Unknown Source)
at android.app.Activity.onCreatePanelMenu(Activity.java:2820)
at android.support.v4.app.o.onCreatePanelMenu(Unknown Source)
at android.support.v7.app.e.a(Unknown Source)
at android.support.v7.app.g.a(Unknown Source)
at android.support.v7.widget.as.a(Unknown Source)
at android.support.v7.internal.a.a.j(Unknown Source)
at android.support.v7.internal.a.b.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我使用的是最新版本的支持库和工具栏。 (通过设置 setSupportActionBar(mToolbar))。

搜索 View xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ertir="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:title="@string/title_activity_search"
ertir:showAsAction="always"
ertir:actionViewClass="android.support.v7.widget.SearchView" />
</menu>

java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
mSearchView = (SearchView) searchItem.getActionView();
mSearchView.setQueryHint(getString(R.string.search_hint));
mSearchView.setFocusable(true);
mSearchView.setIconified(false);
mSearchView.requestFocusFromTouch();
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
mSearchView.clearFocus(); //Hide keyboard
search(query, searchTypeArray.get(searchTypeSpinner.getSelectedItemPosition()).getType());
return false;
}

@Override
public boolean onQueryTextChange(String query) {
if (searchTypeArray.get(searchTypeSpinner.getSelectedItemPosition()).getType().equals("blogs"))
searchAfter(1100, query, searchTypeArray.get(searchTypeSpinner.getSelectedItemPosition()).getType());
else
search(query, searchTypeArray.get(searchTypeSpinner.getSelectedItemPosition()).getType());
return false;
}
});
return true;
}

我该如何解决这个问题?就像上面说的,我只有在签署 apk 后才会出错。

最佳答案

在 proguard-rules.pro 中,添加以下行以排除 SearchView 类:'-保持类 android.support.v7.widget.** { *; }' 然后创建构建。我是这样解决的。

关于android - 构建apk后的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27335608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com