布局错误:java.lang.UnsupportedOperationException:无法转换为维度

时间:2016-01-04 16:16:12

标签: android fatal-error crash

单击ListActivity中的项目并打开MyBrowser Activity时,应用程序会被不幸地停止。我在LogCat中检查过它显示致命错误。无法找到解决方案。 其他活动在模拟器中运行良好,但在点击浏览器后,它显示致命异常。

LogCat

    ` --------- beginning of crash
    01-04 21:26:13.013    2487-2487/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.example.dell.firstapp, PID: 2487
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dell.firstapp/com.example.dell.firstapp.MyBrowser}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
                at android.app.ActivityThread.access$800(ActivityThread.java:151)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:135)
                at android.app.ActivityThread.main(ActivityThread.java:5257)
                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:903)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
         Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
                at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:572)
                at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6660)
                at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1864)
                at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1776)
                at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:62)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:808)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
                at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
                at android.app.Activity.setContentView(Activity.java:2145)
                at com.example.dell.firstapp.MyBrowser.onCreate(MyBrowser.java:22)
                at android.app.Activity.performCreate(Activity.java:5990)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
                at android.app.ActivityThread.access$800(ActivityThread.java:151)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:135)
                at android.app.ActivityThread.main(ActivityThread.java:5257)
                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:903)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <LinearLayout
        android:weightSum="100"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <EditText

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/etURL"
            android:layout_weight="20" />
        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Go"
            android:id="@+id/bGo"
            android:layout_weight="80"
            android:layout_marginRight="@+id/editText"/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:weightSum="8"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bBack"
            android:text="Go back page"
            android:layout_weight="2"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bFwd"
            android:text="Go forward"
            android:layout_weight="2"
            />
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bRefresh"
            android:text="Refresh page"
            android:layout_weight="2"/>
        <Button android:text="clear History"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bHistory"
            android:layout_weight="2"/>
    </LinearLayout>
    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/wvBrowser"></WebView>

</LinearLayout>

Android清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dell.firstapp" >
    <uses-sdk android:minSdkVersion="8"/>
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".Splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Starting"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.dell.firstapp.STARTING" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.dell.firstapp.MENU" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Email"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.dell.firstapp.EMAIL" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Camera" android:label="@string/app_name">
        </activity>
        <activity
            android:name=".MyBrowser" android:label="@string/app_name">
        </activity>
    </application>
</manifest>

活动类

    public class MyBrowser extends Activity implements View.OnClickListener{

            EditText url;
            WebView ourBrow;
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.simplebrowser);

                WebView ourBrow=(WebView) findViewById(R.id.wvBrowser);
                ourBrow.getSettings().setJavaScriptEnabled(true);
                ourBrow.getSettings().setLoadWithOverviewMode(true);
                ourBrow.getSettings().setUseWideViewPort(true);

                ourBrow.setWebViewClient(new ourViewClient());
                try {
                    ourBrow.loadUrl("http://www.google.com");
                }catch (Exception e){
                    e.printStackTrace();
                }

                Button go=(Button) findViewById(R.id.bGo);
                Button back=(Button) findViewById(R.id.bBack);
                Button forward=(Button) findViewById(R.id.bFwd);
                Button refresh=(Button) findViewById(R.id.bRefresh);
                Button clearHistory=(Button) findViewById(R.id.bHistory);
                url=(EditText) findViewById(R.id.etURL);
                go.setOnClickListener(this);
                back.setOnClickListener(this);
                forward.setOnClickListener(this);
                refresh.setOnClickListener(this);
                clearHistory.setOnClickListener(this);
            }

            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.bGo:
                        String theWebsite=url.getText().toString();
                        ourBrow.loadUrl(theWebsite);
                        //Hiding the keyboard after using an EditText
                        InputMethodManager imm=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(url.getWindowToken(),0);
                        break;
                    case R.id.bBack:
                        if(ourBrow.canGoBack())
                            ourBrow.goBack();
                        break;
                    case R.id.bFwd:
                        if(ourBrow.canGoForward())
                            ourBrow.goForward();
                        break;
                    case R.id.bRefresh:
                        ourBrow.reload();
                        break;
                    case R.id.bHistory:
                        ourBrow.clearHistory();
                        break;
                }
            }
        }

编辑:新例外

01-04 23:37:11.766    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:11.864    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:12.000    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:16.058    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:16.122    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:16.202    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:16.373    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:16.471    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:16.585    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:19.396    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:19.496    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:19.574    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:19.736    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:19.802    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:19.916    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:20.366    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:20.468    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:20.549    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:20.735    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:20.798    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:20.879    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:21.065    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:21.183    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:21.261    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:21.456    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:21.572    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:21.685    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:21.872    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:21.985    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:22.065    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:22.232    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:22.337    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:22.422    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:23.628    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:23.737    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:23.817    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:24.002    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
01-04 23:37:24.053    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
01-04 23:37:24.136    2227-2243/? E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
01-04 23:37:24.337    2227-2243/? E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)

1 个答案:

答案 0 :(得分:0)

您的错误是

UnsupportedOperationException: Can't convert to dimension

这是由以下行(针对您的Go按钮)引起的,因为Android无法将@+id/editText转换为维度:

android:layout_marginRight="@+id/editText"

android:layout_marginRight期望维度由数字或维度资源提供,请参阅下面的示例

// number
android:layout_marginRight="16dp"

// dimension resource
android:layout_marginRight="@dimen/margin_size"