错误:java.lang.UnsupportedOperationException:无法转换为维度:type = 0x3

时间:2015-08-15 13:57:00

标签: java android eclipse

我正在制作一个简单的Android应用程序。 但如果我想运行我的应用程序,我会收到错误:

08-15 09:39:33.050: E/AndroidRuntime(871): FATAL EXCEPTION: main
08-15 09:39:33.050: E/AndroidRuntime(871): Process: com.a3gaatleren, PID: 871
08-15 09:39:33.050: E/AndroidRuntime(871): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.a3gaatleren/com.a3gaatleren.MainActivity}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x3
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.os.Handler.dispatchMessage(Handler.java:102)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.os.Looper.loop(Looper.java:136)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.ActivityThread.main(ActivityThread.java:5001)
08-15 09:39:33.050: E/AndroidRuntime(871):  at java.lang.reflect.Method.invokeNative(Native Method)
08-15 09:39:33.050: E/AndroidRuntime(871):  at java.lang.reflect.Method.invoke(Method.java:515)
08-15 09:39:33.050: E/AndroidRuntime(871):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-15 09:39:33.050: E/AndroidRuntime(871):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-15 09:39:33.050: E/AndroidRuntime(871):  at dalvik.system.NativeStart.main(Native Method)
08-15 09:39:33.050: E/AndroidRuntime(871): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x3
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:464)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6129)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:615)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:559)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:56)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.view.LayoutInflater.inflate(LayoutInflater.java:480)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
08-15 09:39:33.050: E/AndroidRuntime(871):  at com.a3gaatleren.MainActivity.onCreate(MainActivity.java:17)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.Activity.performCreate(Activity.java:5231)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-15 09:39:33.050: E/AndroidRuntime(871):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
08-15 09:39:33.050: E/AndroidRuntime(871):  ... 11 more
08-15 09:39:38.860: I/Process(871): Sending signal. PID: 871 SIG: 9

Mainactivity:

package com.a3gaatleren;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class MainActivity extends ActionBarActivity {

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

    final Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        startActivity(new Intent(MainActivity.this, Samenvattingen.class));

        }
    }
    );

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            Intent menuIntent = new Intent(this, Instellingen.class);
            startActivity(menuIntent);

            return true;
        }
        return super.onOptionsItemSelected(item);


    }


}

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="@string/marginbutton"
    android:layout_marginRight="@string/marginbutton"
    tools:context="com.a3gaatleren.MainActivity" >

    <Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="82dp"
    android:text="@string/Samenvatting" />

    <Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button1"
    android:text="@string/Woordenlijst" />

    <Button
    android:id="@+id/button3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button2"
    android:text="@string/Agenda" />

    <Button
    android:id="@+id/button4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button3"
    android:text="@string/Instellingen" />

</RelativeLayout>

有人可以告诉我如何解决这个问题吗?

PS:英语不是我的第一语言,所以我现在的英语不正确

1 个答案:

答案 0 :(得分:0)

就我而言,它也与dimenString不匹配。

但是我的错误是我将background的值放在elevation中来保存 ctrl + c 的值,然后忘记了。

可以帮助某人