I am trying to create layout using ContraintsLayout.
In my layout I have added horizontal GuideLine
.
But when I run the app it crashes and if I remove the GuideLine
it works.
I also checked the APK and there is a class java.awt.Rectagle
StackStrace
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)
Layout xml file
<?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>
These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.
constraintlayout:constraintlayout:2.1. 0 is released. This is the final release for 2.1. 0.
Open the layout file (activity_main. xml) in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click LinearLayout and then choose Convert layout to ConstraintLayout from the context menu.
Select an app. On the left menu, select Quality > Android vitals > Crashes and ANRs. Near the center of your screen, use the filters to help you find and diagnose issues. Alternatively, select a cluster to get more details about a specific crash or ANR error.
Update:
This issue is fixed in Android Studio 2.2 preview 2 (download from this page).
Fixed guidelines crash on device
From the changelog.
Note that you will have to change app:orientation
to android:orientation
Changed orientation attribute namespace from app to android to fix a conflict with GridLayout
(also mentioned in changelog).
The problem is that the Guideline class internally uses java.awt.Rectangle
, and java.awt
libraries are not available for android (apart from the java.awt.font class).
You cannot edit the Guideline class manually, and you shouldn't want to. The best thing for now is to report the issue at https://code.google.com/p/android/issues like Selvin said, and wait for a fix. In the meantime you cannot use the Guideline class.
Fortunately Guideline is more a convenience class so you should be able to live without it for now. If you really need something like this then you could temporarily use a regular View element that is 0dp
thick and hook up constraints to that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With