gpt4 book ai didi

android - 由于约束布局,Android应用在启动时崩溃

转载 作者:行者123 更新时间:2023-12-03 14:19:57 26 4
gpt4 key购买 nike

我尝试运行我的应用程序,但仍然出现此错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nachum.pap/com.example.nachum.pap.MainMap}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout

我按照说明实施了约束布局,但没有帮助

我的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:background="@android:color/white"
tools:context=".MainMap">

<android.support.constraint.ConstraintLayout
android:layout_width="@dimen/map_width"
android:layout_height="@dimen/map_height"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/menu_map"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">


<!--
The function "go to map" that activates in the onClick goes to the google maps activity and exists in MainMap java file
The tag helps discern where on the map should the maps activity open.
-->
<Button
android:id="@+id/MaalotButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="32dp"
android:layout_height="10dp"
android:layout_marginLeft="96dp"
android:layout_marginTop="28dp"
android:onClick="goToMap" android:tag="0"
android:text="@string/PaPMaalot"
android:textSize="8sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/ShderotButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="32dp"
android:layout_height="10dp"
android:layout_marginTop="24dp"
android:layout_marginRight="10dp"
android:onClick="goToMap" android:tag="1"
android:text="@string/PaPShderot"
android:textSize="8sp"
app:layout_constraintRight_toRightOf="@+id/AshdodButton"
app:layout_constraintTop_toBottomOf="@+id/AshdodButton" />

<Button
android:id="@+id/KfarVardimButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="46dp"
android:layout_height="10dp"
android:layout_marginRight="6dp"
android:onClick="goToMap" android:tag="2"
android:text="@string/PaPKfarVradim"
android:textSize="8sp"
app:layout_constraintRight_toRightOf="@+id/MaalotButton"
app:layout_constraintTop_toBottomOf="@+id/MaalotButton" />

<Button
android:id="@+id/TalElButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="32dp"
android:layout_height="10dp"
android:layout_marginRight="8dp"
android:onClick="goToMap" android:tag="3"
android:text="@string/PaPTalEl"
android:textSize="8sp"
app:layout_constraintRight_toRightOf="@+id/KfarVardimButton"
app:layout_constraintTop_toBottomOf="@+id/KfarVardimButton" />

<Button
android:id="@+id/CholonButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="32dp"
android:layout_height="10dp"
android:layout_marginTop="110dp"
android:layout_marginRight="12dp"
android:onClick="goToMap" android:tag="4"
android:text="@string/PaPCholon"
android:textSize="8sp"
app:layout_constraintRight_toLeftOf="@+id/TalElButton"
app:layout_constraintTop_toBottomOf="@+id/TalElButton" />

<Button
android:id="@+id/AshdodButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="32dp"
android:layout_height="10dp"
android:layout_marginTop="18dp"
android:layout_marginRight="14dp"
android:onClick="goToMap" android:tag="5"
android:text="@string/PaPAshdod"
android:textSize="8sp"
app:layout_constraintRight_toRightOf="@+id/CholonButton"
app:layout_constraintTop_toBottomOf="@+id/CholonButton" />

<Button
android:id="@+id/TfachotButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="32dp"
android:layout_height="10dp"
android:layout_marginTop="7dp"
android:layout_marginRight="8dp"
android:onClick="goToMap" android:tag="6"
android:text="@string/PaPTfachot"
android:textSize="8sp"
app:layout_constraintRight_toRightOf="@+id/BarYochayButton7"
app:layout_constraintTop_toBottomOf="@+id/BarYochayButton7" />

<Button
android:id="@+id/DaltonButton"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="32dp"
android:layout_height="10dp"
android:layout_marginLeft="8dp"
android:onClick="goToMap" android:tag="7"
android:text="@string/PaPDalton"
android:textSize="8sp"
app:layout_constraintLeft_toRightOf="@+id/MaalotButton"
app:layout_constraintTop_toTopOf="@+id/MaalotButton" />

<Button
android:id="@+id/BarYochayButton7"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="38dp"
android:layout_height="10dp"
android:layout_marginTop="7dp"
android:layout_marginRight="8dp"
android:onClick="goToMap" android:tag="8"
android:text="@string/PaPBarYochay"
android:textSize="8sp"
app:layout_constraintRight_toRightOf="@+id/DaltonButton"
app:layout_constraintTop_toBottomOf="@+id/DaltonButton" />
</android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

Java的
package com.example.nachum.pap;

import android.content.Intent;
import android.view.View;
import android.os.Bundle;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainMap extends AppCompatActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_map);
}

/** Called when the user taps the Send button */
public void goToMap(View view) {
Intent intent = new Intent(this, NAVDRAW.class);
intent.putExtra("num", view.getTag().toString());
startActivity(intent);
}


}


日志猫:
07-15 06:13:44.064 20107-20107/? I/art: Late-enabling -Xcheck:jni
07-15 06:13:44.604 20107-20107/com.example.nachum.pap W/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
07-15 06:13:44.604 20107-20107/com.example.nachum.pap I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
07-15 06:13:44.634 20107-20107/com.example.nachum.pap I/InstantRun: starting instant run server: is main process
07-15 06:13:44.804 20107-20107/com.example.nachum.pap D/ContextHelper: convertTheme. context->name=com.example.nachum.pap themeResourceId=2131689478
07-15 06:13:44.874 20107-20107/com.example.nachum.pap W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-15 06:13:44.944 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:44.944 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:44.944 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:44.944 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:44.944 20107-20107/com.example.nachum.pap I/PhoneWindow: [generateLayout] setColorNavigationBar => color=0x ff000001
07-15 06:13:44.944 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:45.004 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:45.004 20107-20107/com.example.nachum.pap D/PhoneWindowEx: [PWEx][generateLayout] setNavigationBarColor2 : colors=0xff000000
07-15 06:13:45.004 20107-20107/com.example.nachum.pap I/PhoneWindow: [setNavigationBarColor2] color=0x ff000000
07-15 06:13:45.004 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:45.004 20107-20107/com.example.nachum.pap D/PhoneWindow: [updateColorViews] sysUiVisibility=0x0
07-15 06:13:45.054 20107-20107/com.example.nachum.pap I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
07-15 06:13:45.054 20107-20107/com.example.nachum.pap I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
07-15 06:13:45.214 20107-20107/com.example.nachum.pap D/AndroidRuntime: Shutting down VM
07-15 06:13:45.214 20107-20107/com.example.nachum.pap E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.nachum.pap, PID: 20107
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nachum.pap/com.example.nachum.pap.MainMap}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.nachum.pap.MainMap.onCreate(MainMap.java:17)
at android.app.Activity.performCreate(Activity.java:6020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366) 
at android.app.ActivityThread.access$800(ActivityThread.java:149) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5297) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.nachum.pap-1/base.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.nachum.pap-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.nachum.pap.MainMap.onCreate(MainMap.java:17) 
at android.app.Activity.performCreate(Activity.java:6020) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366) 
at android.app.ActivityThread.access$800(ActivityThread.java:149) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5297) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) 
Suppressed: java.lang.ClassNotFoundException: android.support.constraint.ConstraintLayout
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 22 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available


编辑:
应用程式gradle:
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.nachum.pap"
minSdkVersion 15
targetSdkVersion 28
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:support-compat:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.android.support:design:28.1.0'
implementation 'com.google.firebase:firebase-database:18.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
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'
}

项目级别gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
maven { url "https://maven.google.com/"}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

最佳答案

您正在使用androidx.appcompat.app.AppCompatActivity,因此应使用androidx.constraintlayout.widget.ConstraintLayout而不是android.support.constraint.ConstraintLayout

build.gradle文件中,将implementation 'com.android.support.constraint:constraint-layout:1.1.3'替换为implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

关于android - 由于约束布局,Android应用在启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57032937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com