当前位置: 首页 > 知识库问答 >
问题:

应用程序在API26上工作,但在API23上崩溃(Marshmallow)

云胤
2023-03-14

该应用程序在API26模拟器中运行良好,没有任何意外行为,但在API23中崩溃。当应用程序启动时。我对android相当陌生,所以不太确定要做什么改变来适应API23。

这是我的年级

apply plugin: 'com.android.application'



    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "com.set.www.assignment_1_mobile"
            minSdkVersion 15
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            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.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.set.www.assignment_1_mobile/com.set.www.assignment_1_mobile.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
    at android.app.Activity.setContentView(Activity.java:2166)
    at com.set.www.assignment_1_mobile.MainActivity.onCreate(MainActivity.java:46)
    at android.app.Activity.performCreate(Activity.java:6237)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:645)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
    at android.app.Activity.setContentView(Activity.java:2166) 
    at com.set.www.assignment_1_mobile.MainActivity.onCreate(MainActivity.java:46) 
    at android.app.Activity.performCreate(Activity.java:6237) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
    at android.app.Activity.setContentView(Activity.java:2166) 
    at com.set.www.assignment_1_mobile.MainActivity.onCreate(MainActivity.java:46) 
    at android.app.Activity.performCreate(Activity.java:6237) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.content.res.Resources$NotFoundException: Resource "com.set.www.assignment_1_mobile:drawable/nyteimg" (7f030004) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f030004 a=-1 r=0x7f030004}
    at android.content.res.Resources.loadDrawableForCookie(Resources.java:2602)
    at android.content.res.Resources.loadDrawable(Resources.java:2540)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
    at android.view.View.<init>(View.java:3948)
    at android.view.ViewGroup.<init>(ViewGroup.java:573)
    at android.widget.LinearLayout.<init>(LinearLayout.java:203)
    at android.widget.LinearLayout.<init>(LinearLayout.java:199)
    at android.widget.LinearLayout.<init>(LinearLayout.java:195)
    at java.lang.reflect.Constructor.newInstance(Native Method) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
    at android.app.Activity.setContentView(Activity.java:2166) 
    at com.set.www.assignment_1_mobile.MainActivity.onCreate(MainActivity.java:46) 
    at android.app.Activity.performCreate(Activity.java:6237) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/nyteimg"
    tools:context="com.setconestoga.www.assignment_1_mobile.MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="49dp"
        android:fontFamily="sans-serif"
        android:text="@string/main_menu"
        android:textAlignment="center"
        android:textColor="#FFFFFF"
        android:textSize="30sp"
        android:textStyle="bold"
        android:visibility="visible" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="26dp" />

    <Button
        android:id="@+id/PlaceOrder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/_place_order"
        android:textColor="@android:color/white" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="27dp" />

    <Button
        android:id="@+id/Settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/settingScreenTitle"
        android:textColor="@android:color/white" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="30dp" />

    <Button
        android:id="@+id/ViewOrders"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/txtViewOrder"
        android:textColor="@android:color/white" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="24dp" />

    <Button
        android:id="@+id/VisitWebsite"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Visit Website"
        android:textColor="@android:color/white" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="28dp" />

    <Button
        android:id="@+id/Notes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Feedback"
        android:textColor="@android:color/white" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="29dp" />

    <Button
        android:id="@+id/ExitButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/exit"
        android:textColor="@android:color/white" />
</LinearLayout>

共有1个答案

施振海
2023-03-14

放置在drawable-v26中的每个图像只能与Android api版本26一起工作。因此,您需要将其移动到drawable或创建多个图像到drawable-hdpi、drawable-xhdpi等。

 类似资料:
  • 我创建了一个应用程序,在Android marshmallow中崩溃,而在under版本中我的应用程序正常工作。 这怎么可能?这是我的清单代码: 这是分级代码: 我读到你必须在代码中修改一些东西,使其与AndroidMarshmallow兼容。 我该如何解决问题呢?

  • 这是我按下电话上的按钮后的logcat: 我已经在清单中插入了请求权限的命令,但可能需要更多的东西: Logcat 2.9:

  • 编辑3:添加包含错误的代码的一部分 编辑4:更多代码。下面是onCreate()方法。对checkForNewBooking()方法的调用来自于此。

  • 我有一个使用Twitter API开发的Nodejs应用程序。当托管在Heroku上时,它会出现以下错误: 2018-12-14T10:00:03.678180 00:00 heroku[web.1]:错误 R10(启动超时)- 在搜索时,我遇到了这些StackOverflow问题q1 q2,但它们都使用ExpressJS并监听固定端口,而不是Heroku提供的端口,而我的应用程序没有使用Expr

  • 自定义datePicker代码: 这就是我如何在我的主要活动中使用这个类: Logcat:

  • 我制作了一个OpenGL应用程序,用于测试Framebuffer Objects,该应用程序适用于我制作的笔记本电脑,我拥有的另一台笔记本电脑和我的台式PC。但是,对于我要求为我测试该应用程序的其他人来说,它似乎崩溃了。 到目前为止,我已经将它缩小到在我调用的第一个扩展(在本例中为glGenBuffers)上崩溃,我100%确定在调用该函数(见下文)之前不会调用该扩展。在浏览了许多答案后,我确定了