Androind 2.2预览1 – 使用ConstraintsLayout和GuideLine应用程序崩溃

我正在尝试使用ContraintsLayout创建布局。

在我的布局中,我添加了水平GuideLine

但是,当我运行该应用程序时,它会崩溃,如果我删除了GuideLine它就可以运行。

我还检查了APK,并且有一个类java.awt.Rectagle

StackStrace

 java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Rectangle; at android.support.constraint.solver.widgets.Guideline.(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.(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文件

                   

更新:
此问题已在Android Studio 2.2预览2中修复(从此页面下载)。

固定指南在设备上崩溃

来自changelog 。

请注意,您必须将app:orientation更改为android:orientation

将方向属性命名空间从app更改为android以修复与GridLayout的冲突

(也在changelog中提到)。


问题是Guideline类内部使用java.awt.Rectangle ,并且java.awt库不适用于android(除了java.awt.font类)。

您无法手动编辑Guideline类,也不应该这样做。 现在最好的事情是在https://code.google.com/p/android/issues上报告问题,比如Selvin说,并等待修复。 在此期间,您无法使用Guideline类。

幸运的是,Guideline更像是一个便利课程,所以你现在应该可以没有它。 如果你确实需要这样的东西,那么你可以暂时使用0dp厚的常规View元素并将约束连接起来。