无法转换为维度:type = 0x1

时间:2018-04-19 10:08:18

标签: java android typedarray

我用我的android studio 3.0.1 创建一个新的应用程序 我的主要活动如下所示:

public class MainActivity extends AppCompatActivity {

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

主要活动的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"
  tools:context="hrms.vivacom.com.buildmyapk.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

  </android.support.constraint.ConstraintLayout>

基本上这是Android工作室提供的空骨架。 Gradle Build很好但是当我在我的手机上运行这个应用程序时,会出现以下错误。

FATAL EXCEPTION: main
        Process: hrms.vivacom.com.buildmyapk, PID: 678
        <b>java.lang.RuntimeException: Unable to start activity ComponentInfo{hrms.vivacom.com.buildmyapk/hrms.vivacom.com.buildmyapk.MainActivity}:
        java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1</b>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2378)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2440)
        at android.app.ActivityThread.access$800(ActivityThread.java:162)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5430)
        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:913)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
<b>Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
        at android.content.res.TypedArray.getDimensionPixelOffset(TypedArray.java:533)
        at android.support.v7.widget.TintTypedArray.getDimensionPixelOffset(TintTypedArray.java:189)</b>
        at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:149)
        at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:95)
        at android.support.v7.widget.Toolbar.getWrapper(Toolbar.java:2110)
        at android.support.v7.widget.ActionBarOverlayLayout.getDecorToolbar(ActionBarOverlayLayout.java:546)
        at android.support.v7.widget.ActionBarOverlayLayout.pullChildren(ActionBarOverlayLayout.java:538)
        at android.support.v7.widget.ActionBarOverlayLayout.setWindowCallback(ActionBarOverlayLayout.java:614)
        at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:410)
        at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
        at hrms.vivacom.com.buildmyapk.MainActivity.onCreate(MainActivity.java:11)
        at android.app.Activity.performCreate(Activity.java:6097)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)

0 个答案:

没有答案