我正在尝试使用 ContraintsLayout 创建布局。
在我的布局中,我添加了 Horizontal GuideLine
。
但是当我运行应用程序时它会崩溃,如果我删除GuideLine
它就可以了。
我还检查了 APK 并且有一个类java.awt.Rectagle
堆栈跟踪
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Rectangle;
at android.support.constraint.solver.widgets.Guideline.<init>(Guideline.java:43)
at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:128)
at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:106)
at android.support.constraint.ConstraintLayout.onFinishInflate(ConstraintLayout.java:87)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.infostretch.app.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:6669)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2578)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2686)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5969)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Rectangle" on path: DexPathList[[zip file "/data/app/com.infostretch.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.infostretch.app-1/lib/x86_64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.support.constraint.solver.widgets.Guideline.<init>(Guideline.java:43)
at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:128)
at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:106)
at android.support.constraint.ConstraintLayout.onFinishInflate(ConstraintLayout.java:87)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.infostretch.app.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:6669)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2578)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2686)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5969)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
布局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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="80dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:src="@color/accent_material_light"
app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
tools:layout_constraintLeft_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="16dp" />
<TextView
android:id="@+id/textView11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintLeft_toRightOf="@+id/imageView"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
tools:layout_constraintLeft_creator="0"
tools:layout_constraintRight_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="80dp"
tools:layout_editor_absoluteY="16dp" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:src="@color/abc_input_method_navigation_guard"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
app:layout_constraintTop_toBottomOf="@+id/textView11"
tools:layout_constraintRight_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="367dp"
tools:layout_editor_absoluteY="40dp" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:orientation="horizontal"
app:relativeBegin="83dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="83dp" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
app:layout_constraintTop_toTopOf="@+id/guideline"
tools:layout_constraintLeft_creator="0"
tools:layout_constraintRight_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="99dp">
<TextView
android:id="@+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="MapView"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="230dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
app:layout_constraintTop_toBottomOf="@+id/linearLayout"
tools:layout_constraintLeft_creator="0"
tools:layout_constraintRight_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="227dp">
<TextView
android:id="@+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Alert View"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="358dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
app:layout_constraintTop_toBottomOf="@+id/linearLayout2"
tools:layout_constraintBottom_creator="0"
tools:layout_constraintLeft_creator="0"
tools:layout_constraintRight_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="355dp">
<TextView
android:id="@+id/textView14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Recycler View"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="522dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="48dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"
app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
tools:layout_constraintBottom_creator="0"
tools:layout_constraintLeft_creator="0"
tools:layout_constraintRight_creator="0"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="554dp">
</LinearLayout>
</android.support.constraint.ConstraintLayout>