应用程序崩溃错误'不幸的是,计算器已停止'在Android KitKat 4.4.4版移动版中

问题描述 投票:-2回答:1

我在KitKat 4.4.4版手机中从Android工作室运行我的计算器应用程序,我收到错误'不幸的是,计算器已停止'。以下是从Android Studio的Logcat获得的错误:

03-03 10:18:14.279 3583-3583/com.saashtechs.saashcalculator E/dalvikvm: Could not find class 'java.util.Locale$Builder', referenced from method com.android.calculator2.CalculatorNumericPadLayout.onFinishInflate
03-03 10:18:14.319 3583-3583/com.saashtechs.saashcalculator E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.saashtechs.saashcalculator, PID: 3583
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.saashtechs.saashcalculator/com.android.calculator2.CalculatorGB}: android.view.InflateException: Binary XML file line #26: Error inflating class Button
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:166)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:136)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5590)
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
                                                                                  at dalvik.system.NativeStart.main(Native Method)
                                                                               Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class Button
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:720)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                                  at com.android.calculator2.Calculator.onCreate(Calculator.java:149)
                                                                                  at com.android.calculator2.CalculatorGB.onCreate(CalculatorGB.java:27)
                                                                                  at android.app.Activity.performCreate(Activity.java:5447)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:166) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5590) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                                               Caused by: android.content.res.Resources$NotFoundException: File res/drawable/pad_button_background.xml from drawable resource ID #0x7f060060
                                                                                  at android.content.res.Resources.loadDrawable(Resources.java:3453)
                                                                                  at android.content.res.TypedArray.getDrawable(TypedArray.java:614)
                                                                                  at android.view.View.<init>(View.java:3585)
                                                                                  at android.widget.TextView.<init>(TextView.java:698)
                                                                                  at android.widget.Button.<init>(Button.java:107)
                                                                                  at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
                                                                                  at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:62)
                                                                                  at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                                                  at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:762) 
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:771) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:771) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:499) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                  at com.android.calculator2.Calculator.onCreate(Calculator.java:149) 
                                                                                  at com.android.calculator2.CalculatorGB.onCreate(CalculatorGB.java:27) 
                                                                                  at android.app.Activity.performCreate(Activity.java:5447) 
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) 
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:166) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5590) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                                               Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #18: invalid drawable tag ripple
                                                                                  at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:969)
                                                                                  at android.graphics.drawable.Drawable.createFromXml(Drawable.java:913)
                                                                                  at android.content.res.Resources.loadDrawable(Resources.java:3449)
                                                                                  at android.content.res.TypedArray.getDrawable(TypedArray.java:614) 
                                                                                  at android.view.View.<init>(View.java:3585) 
                                                                                  at android.widget.TextView.<init>(TextView.java:698) 
                                                                                  at android.widget.Button.<init>(Button.java:107) 
                                                                                  at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66) 
                                                                                  at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:62) 
                                                                                  at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109) 
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029) 
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087) 
                                                                                  at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47) 
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:762) 
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:771) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:771) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:499) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                  at com.android.calculator2.Calculator.onCreate(Calculator.java:149) 
                                                                                  at com.android.calculator2.CalculatorGB.onCreate(CalculatorGB.java:27) 
                                                                                  at android.app.Activity.performCreate(Activity.java:5447) 
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) 
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:166) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5590) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 

任何人都可以帮助我为什么会收到此错误?

另外,请让我知道我需要在这里显示哪些文件,以便你们可以解决这个错误

下面是'build.gradle'文件代码:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:3.0.1"
    }
}

apply plugin: "com.android.application"

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.2"

    defaultConfig {
        applicationId "com.sg.calculator"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }

    sourceSets {
        main {
            manifest.srcFile "AndroidManifest.xml"
            java.srcDirs = ["src"]
            res.srcDirs = ["res"]
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

repositories {
    mavenLocal()
    maven {
        url "https://maven.google.com"
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.android.support:recyclerview-v7:25.4.0'
    compile files('exp4j-0.4.8.jar')
    compile files('nineoldandroids-2.4.0.jar')
}

XML文件:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/display"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/display_background_color"
    android:elevation="4dip">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:id="@+id/tb"
        android:theme="@style/CalculatorTheme"
        android:title=""
        xmlns:android="http://schemas.android.com/apk/res/android">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RAD"
            android:background="@null"
            android:id="@+id/rad"
            android:textSize="20sp"
            android:onClick="onButtonClick"
            android:theme="?android:attr/borderlessButtonStyle"
            android:minWidth="5dp"
            android:minHeight="5dp" />
    </android.support.v7.widget.Toolbar>

    <com.android.calculator2.CalculatorEditText
        android:id="@+id/formula"
        android:layout_below="@+id/tb"
        style="@style/DisplayEditTextStyle.Formula"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text|textNoSuggestions"
        android:textColor="@color/display_formula_text_color" />

    <com.android.calculator2.CalculatorEditText
        android:id="@+id/result"
        style="@style/DisplayEditTextStyle.Result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/formula"
        android:inputType="text"
        android:focusable="false"
        android:textColor="@color/display_result_text_color" />

</RelativeLayout>

'res / drawable / pad_button_background.xml'文件代码:

<ripple xmlns:
android="http://schemas.android.com/apk/res/android"
android:color="@color/pad_button_ripple_color" />

提前致谢

android android-resources
1个回答
0
投票

RippleDrawable - 在API级别21中添加

因此,您需要将该XML文件移动到至少一个res/drawable-v21文件夹。 (如果不存在则生效)

另见 - How to achieve ripple animation using support library?

© www.soinside.com 2019 - 2024. All rights reserved.