Android 应用程序崩溃,无法找出问题所在

Android App crash, can't figure out the issue

我有 2 部手机,一部三星 S8 运行ning v8.0 和一部 LG G4 运行ning v6.0。我都连接到同一台计算机并构建了应用程序,并 运行 它在手机上。在三星上一切似乎都很好,在 LG 上所有安装和看起来都很好,直到我按下第一个 Activity 上的菜单按钮。

我的第一个 activity 加载了一个片段,该片段将三点菜单放在右上角。我在菜单中只有 1 个项目,它会打开一个新的 activity,其中包含 select 的项目列表。在 LG 上,当按下这个 3 点菜单时,应用程序崩溃,但在 S8 上,它打开菜单并允许我 select 第一个项目并打开下一个 activity.

正在寻找有关如何使用它的任何想法。

我得到的错误:

I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
I/AudioManagerEx: AudioManagerEx created
I/ListPopupWindow: Could not find method setEpicenterBounds(Rect) on PopupWindow. Oh well.
W/ResourceType: Failure getting entry for 0x7f07013a (t=6 e=314) (error -75)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.czdev.booktimeline, PID: 15910
                  android.content.res.Resources$NotFoundException: Resource ID #0x7f07013a
                      at android.content.res.Resources.getValue(Resources.java:1401)
                      at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:332)
                      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
                      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
                      at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
                      at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:425)
                      at android.support.v7.view.menu.ListMenuItemView.initialize(ListMenuItemView.java:116)
                      at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:100)
                      at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:160)
                      at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:153)
                      at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:187)
                      at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:290)
                      at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175)
                      at android.support.v7.widget.ActionMenuPresenter$OpenOverflowRunnable.run(ActionMenuPresenter.java:803)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5525)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Application terminated.

这是我的 Gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.oss.licenses.plugin'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "<com.android.application>"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 25
        versionName "0.8"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.gms:play-services-oss-licenses:15.0.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'

}
repositories {
    mavenCentral()
}

这是我的第一个片段:

public class HomeFrag extends Fragment {

    View rootView;

    public HomeFrag() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_home, container, false);

        Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
        toolbar.setTitle(R.string.app_name);

        ((MainActivity) Objects.requireNonNull(getActivity())).setSupportActionBar(toolbar);
        setHasOptionsMenu(true);

        return rootView;
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.main_menu, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.menu_action_info) {
            startActivity(new Intent(getContext(), InfoMenu.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

这是我的菜单:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >
    <item
        android:id="@+id/menu_action_info"
        android:icon="@drawable/ic_info_outline_white_24dp"
        android:orderInCategory="100"
        android:title="@string/menu_info_action"
        app:showAsAction="never" />
</menu>

任何想法都会很棒。

从崩溃日志来看,似乎加载图标失败

在 android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100) 在 android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:425)

你能检查一下你的 R.java 资源 ID #0x7f07013a 吗,它会准确告诉你哪个资源加载失败,我猜是某个特定的可绘制文件夹中缺少图标。

Ankit