扩展AppCompatActivity会使应用程序崩溃

时间:2018-05-01 21:28:04

标签: android android-appcompat appcompatactivity appcompat-v7

我正在创建一个简单的应用来测试 structure(list(F0 = structure(list(rst1 = structure(list(algo = c("Mean", "gbm1", "GAM2", "gbm2", "ran2", "nai1", "GAM3", "GAM1", "ran1", "svm2", "svm1"), rst = c(56.4, 41.8, 37.2, 36.8, 35, 29.8, 28.8, 21.8, 19.4, 14, 0.8), prec = c(0.45, 0.438, 0.512, 0.422, 0.442, 0.544, 0.403, 0.405, 0.406, 0.385, 0.359), rorac = c(25.872, 22.595, 43.256, 18.039, 23.81, 52.281, 12.743, 13.374, 13.566, 7.692, 0.471), prPo = c(91.2, 77.4, 50, 85.4, 61.5, 33.1, 94.6, 68.2, 59.8, 76.2, 71.1), pos = c(239L, 239L, 172L, 239L, 239L, 172L, 239L, 239L, 239L, 239L, 239L)), .Names = c("algo", "rst", "prec", "rorac", "prPo", "pos"), row.names = c(1L, 6L, 4L, 7L, 11L, 2L, 5L, 3L, 10L, 9L, 8L), class = "data.frame"), rst5 = structure(list( algo = c("Mean", "gbm2", "gbm1", "GAM3", "GAM2", "ran2", "nai1", "GAM1", "svm2", "ran1", "svm1"), rst = c(52.4, 46.4, 31.2, 28.8, 28.2, 26.6, 23.6, 20.6, 14.4, 14, 6.2), prec = c(0.441, 0.44, 0.416, 0.403, 0.481, 0.422, 0.519, 0.398, 0.386, 0.39, 0.37), rorac = c(23.604, 23.2, 16.421, 12.743, 34.815, 18.095, 45.385, 11.381, 8.182, 9.091, 3.584), prPo = c(92.9, 83.7, 79.5, 94.6, 47.1, 61.5, 30.2, 75.7, 73.6, 64.4, 72.4), pos = c(239L, 239L, 239L, 239L, 172L, 239L, 172L, 239L, 239L, 239L, 239L )), .Names = c("algo", "rst", "prec", "rorac", "prPo", "pos" ), row.names = c(1L, 7L, 6L, 5L, 4L, 11L, 2L, 3L, 9L, 10L, 8L ), class = "data.frame")), .Names = c("rst1", "rst5")), T0 = structure(list( rst1 = structure(list(algo = c("Mean", "ran1", "GAM1", "GAM2", "gbm1", "svm1", "nai1", "gbm2", "svm2", "ran2"), rst = c(22.6, 19.4, 13.6, 10.2, 9.6, 8, 5.6, 3.4, -0.4, -0.6), prec = c(0.478, 0.452, 0.5, 0.421, 0.423, 0.833, 0.429, 0.373, 0.355, 0.356 ), rorac = c(33.731, 26.575, 40, 17.895, 18.462, 133.333, 20, 4.533, -0.526, -0.368), prPo = c(34.4, 52.1, 24.3, 40.7, 37.1, 3.1, 14.4, 53.6, 54.3, 116.4), pos = c(195L, 140L, 140L, 140L, 140L, 195L, 195L, 140L, 140L, 140L)), .Names = c("algo", "rst", "prec", "rorac", "prPo", "pos"), row.names = c(1L, 9L, 3L, 4L, 5L, 7L, 2L, 6L, 8L, 10L), class = "data.frame"), rst5 = structure(list(algo = c("gbm1", "ran1", "Mean", "GAM1", "GAM2", "svm1", "nai1", "svm2", "gbm2", "ran2"), rst = c(17.6, 16.4, 15, 12.8, 9, 6.2, 5.8, -2.6, -3, -9.2), prec = c(0.466, 0.434, 0.435, 0.5, 0.41, 0.8, 0.44, 0.346, 0.345, 0.337), rorac = c(30.345, 21.579, 21.739, 40, 14.754, 124, 23.2, -3.21, -3.448, -5.542), prPo = c(41.4, 54.3, 35.4, 22.9, 43.6, 2.6, 12.8, 57.9, 62.1, 118.6), pos = c(140L, 140L, 195L, 140L, 140L, 195L, 195L, 140L, 140L, 140L)), .Names = c("algo", "rst", "prec", "rorac", "prPo", "pos"), row.names = c(5L, 9L, 1L, 3L, 4L, 7L, 2L, 8L, 6L, 10L), class = "data.frame")), .Names = c("rst1", "rst5"))), .Names = c("F0", "T0")) ,当我延长AppCompat应用崩溃时,以及当我运行不带AppCompatActivity的应用时(扩展AppCompat和一切都保持不变),

android.app.Activity - 有效 MainActivity extends Activity - 崩溃

MainActivity extends AppCompat Activity

上进行测试

logcat的:

android 4.4

添加

------------------------------------------------

05-01 23:03:44.916 E/dalvikvm(23031): heapsize Dalvik_dalvik_system_VMRuntime_nativeMinimumHeapSize 0
05-01 23:03:44.916 E/dalvikvm(23031): heapsize Dalvik_dalvik_system_VMRuntime_nativeMinimumHeapSize 15301176
05-01 23:03:44.966 E/dalvikvm(23031): Could not find class 'android.arch.core.internal.FastSafeIterableMap', referenced from method android.arch.lifecycle.LifecycleRegistry.<init>
05-01 23:03:44.986 E/AndroidRuntime(23031): FATAL EXCEPTION: main
05-01 23:03:44.986 E/AndroidRuntime(23031): Process: com.android.xDrawer, PID: 23031
05-01 23:03:44.986 E/AndroidRuntime(23031): java.lang.NoClassDefFoundError: android.arch.core.internal.FastSafeIterableMap
05-01 23:03:44.986 E/AndroidRuntime(23031):     at android.arch.lifecycle.LifecycleRegistry.<init>(LifecycleRegistry.java:59)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at android.support.v4.app.SupportActivity.<init>(SupportActivity.java:47)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at android.support.v4.app.BaseFragmentActivityApi14.<init>(BaseFragmentActivityApi14.java:28)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at android.support.v4.app.BaseFragmentActivityApi16.<init>(BaseFragmentActivityApi16.java:34)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java:68)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at android.support.v7.app.AppCompatActivity.<init>(AppCompatActivity.java:61)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at com.android.xDrawer.MainActivity.<init>(MainActivity.java:49)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at java.lang.Class.newInstanceImpl(Native Method)
05-01 23:03:44.986 E/AndroidRuntime(23031):     at java.lang.Class.newInstance(Class.java:1208)

-----------------------------------------

在应用程序的gradls中没有解决问题

更新:

完整的gradle文件:

 vectorDrawables.useSupportLibrary = true

的活动:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        applicationId "com.mycompany.myapp"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
              useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
        compile "com.android.support:appcompat-v7:27.1.1"
}

XML:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
         super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

样式:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

   <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

3 个答案:

答案 0 :(得分:3)

解决了,问题是我有android SDK 21(android.jar)与appcompat 27.1.1,尝试了Android SDK 24,25,26,27appcompat 27.1.1但仍然没有运气,然后尝试{ {1}}使用android SDK 25,它就像一个魅力。 希望这可以帮助任何有同样问题的人。

答案 1 :(得分:1)

检查您是否使用Proguard?如果是这样,您可以自定义您的Proguard规则配置,如下所示:

-keep class android.arch.** { *; }

或完全关闭它:

debug {
    minifyEnabled false
    useProguard false
}

希望它适合你

答案 2 :(得分:0)

我有同样的问题:启动扩展AppCompatActivity的Activity时,应用程序崩溃了。

解决:

基本应用程序主题:

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowBackground">@drawable/windows_background</item>
    </style>

我添加了主题:

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

并在AndroidManifest.xml中为扩展AppCompatActivity的Activity应用此主题:

    <activity android:name=".LoadGameActivity"
    android:theme="@style/AppTheme.NoActionBar"
    android:label="@string/label_LoadGameActivity"></activity>