简体   繁体   English

super.onCreate(savedInstanceState)在第一次运行时崩溃

[英]super.onCreate(savedInstanceState) crashes in first run

Exception that caught by Firebase Crash Reporting: Firebase崩溃报告捕获的异常:

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.talmir.mickinet/com.talmir.mickinet.activities.HomeActivity}: android.content.res.Resources$NotFoundException: Resource ID 0x7f080058 android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2249) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2299) android.app.ActivityThread.access$700 (ActivityThread.java:154) android.app.ActivityThread$H.handleMessage ... 异常java.lang.RuntimeException:无法启动活动ComponentInfo {com.talmir.mickinet / com.talmir.mickinet.activities.HomeActivity}:android.content.res.Resources $ NotFoundException:资源ID 0x7f080058 android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2249)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)android.app.ActivityThread.access $ 700(ActivityThread.java:154)android.app.ActivityThread $ H.handleMessage ...

Caused by android.content.res.Resources$NotFoundException: Resource ID 0x7f080058 android.content.res.Resources.getValue (Resources.java:1883) android.support.v7.widget.AppCompatDrawableManager.c (SourceFile:332) android.support.v7.widget.AppCompatDrawableManager.a (SourceFile:197) android.support.v7.widget.AppCompatDrawableManager.getDrawable ... 由android.content.res.Resources $ NotFoundException引起:资源ID 0x7f080058 android.content.res.Resources.getValue(Resources.java:1883) android.support.v7.widget.AppCompatDrawableManager.c(SourceFile:332)android.support .v7.widget.AppCompatDrawableManager.a(SourceFile:197)android.support.v7.widget.AppCompatDrawableManager.getDrawable ...

HomeActivity.java HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home); // line 238
FirebaseCrash.log("HomeActivity");

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    if (!canAccessCamera() || !canAccessExternalStorage() || !canAccessContacts())
        requestPermissions(INITIAL_PERMISSIONS, INITIAL_REQUEST);

copyRawFile(R.raw.file_receive);
// other codes...

activity_home.xml activity_home.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context="com.talmir.mickinet.activities.HomeActivity"
        android:background="@color/snow">

    <fragment
            android:id="@+id/frag_list"
            class="com.talmir.mickinet.fragments.DeviceListFragment"
            android:layout_width="match_parent"
            android:layout_height="@dimen/phone_list_height">
    </fragment>

    <fragment
            android:id="@+id/frag_detail"
            class="com.talmir.mickinet.fragments.DeviceDetailFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    </fragment>

</RelativeLayout>

AndroidManifest.xml AndroidManifest.xml中

<activity
    android:name=".activities.HomeActivity"
    android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

build.gradle 的build.gradle

apply plugin: 'com.android.application'

android {
    signingConfigs {
        config {
            // my config
        }
    }
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.talmir.mickinet"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        signingConfig signingConfigs.config
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable false
            jniDebuggable false
            signingConfig signingConfigs.config
            renderscriptDebuggable false
            zipAlignEnabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.github.paolorotolo:appintro:4.1.0'
    compile 'com.android.support:support-vector-drawable:25.3.1'
    implementation 'com.google.firebase:firebase-crash:11.0.2'
}

apply plugin: 'com.google.gms.google-services'

What I tested: this , this , this , this one(s). 我测试的是: 这个这个这个这个 The question in this link looks like more close to my problem than others. 这个链接中的问题看起来比我的问题更接近我的问题。

Moreover, the same application installed in API 23 and API 17 (both are physical devices), but error occurs only in API 17 (when it launches). 此外,API 23和API 17中安装的应用程序相同(均为物理设备),但仅在API 17(启动时)中发生错误。

Main question: 主要问题:

Why this exception happens and how can I solve it? 为什么会发生此异常,我该如何解决?

This exception happens to me when I update the Android Studio from Canary 5 to canary 6 当我将Canary 5中的Android Studio更新为canary 6时,会发生此异常

I return to Android Studio 2.3.2 and changed the class path back to Gradle 2.3.2 and the problem was solved. 我返回Android Studio 2.3.2并将类路径更改回Gradle 2.3.2并解决了问题。

Update: I tried with 3 of my applications and I get the same error, but solved it like described. 更新:我试过我的3个应用程序,我得到了同样的错误,但解决了它就像描述的那样。

I also had the same issue today. 我今天也遇到了同样的问题。 After some research, I found this: 经过一番研究,我发现了这个:

android.enableAapt2=false

Add this line into your "gradle.properties" file. 将此行添加到“gradle.properties”文件中。

Reference is here . 参考在这里

I think it's caused by a bug in latest version (3.0 Canary 6) of Android Studio. 我认为这是由Android Studio的最新版本(3.0 Canary 6)中的错误引起的。

Improved incremental resource processing with AAPT2. 使用AAPT2改进了增量资源处理。 To enable AAPT2, add the following to your gradle.properties file: android.enableAapt2=true 要启用AAPT2,请将以下内容添加到gradle.properties文件中:android.enableAapt2 = true

The text above is from android studio preview link. 上面的文字来自android studio预览链接。

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

相关问题 Android App一开始在Super.onCreate(savedInstanceState)中崩溃 - Android App is crashing in Super.onCreate(savedInstanceState) at the very begining super.onCreate()改变我的变量 - super.onCreate() changes my variables 不使用super.oncreate()停止循环并扩展MainActivity - Not stopping loop with super.oncreate() and extending MainActivity OCR Tesseract没有调用super.OnCreate(),即使它是 - OCR Tesseract did not call through super.OnCreate() even though it is 如何使用类和子类修复 setContentView 和 super.onCreate 方法? - How to fix setContentView and super.onCreate methods using a class and subclass? android.app.SuperNotCalledException:Activity没有调用super.onCreate() - android.app.SuperNotCalledException: Activity did not call through to super.onCreate() Android-只能在onRestoreInstanceState()中还原saveInstanceState,而不能在onCreate()中还原 - Android - savedInstanceState can be restored only in onRestoreInstanceState() not in onCreate() 在onCreate(Bundle savedInstanceState)中创建捆绑对象的位置在哪里 - Where is Bundle object created in onCreate(Bundle savedInstanceState) 在墙纸服务中使用onCreate Bundle savedInstanceState吗? (表面) - Using onCreate Bundle savedInstanceState with wallpaper service? (Watchface) 两个 oncreate(bundle savedinstancestate) 在同一个活动中? - Two oncreate(bundle savedinstancestate) in the same activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM