访问FrameLayout时获取RunTime异常

时间:2011-11-17 05:15:52

标签: java android exception runtime android-framelayout

所以我正在编写一个应用程序,出于某种原因,当我尝试获取FrameLayout的高度时,我得到一个运行时异常。我在整个设计中使用了相当多的重量,所以我想仔细检查它们是我需要它们的高度。

这是我的主要活动:

package com.app.conekta;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;

public class Conekta extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    }

    @Override
    public void onStart() {

        super.onStart();

        FrameLayout fl1 = (FrameLayout) findViewById(R.id.headerFrameLayout);
        //Button b=(Button) findViewById(R.id.searchButton);
        Toast.makeText(Conekta.this, fl1.getHeight(), Toast.LENGTH_SHORT).show();

    }
}

这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <FrameLayout
        android:id="@+id/headerFrameLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.05"
        android:background="#597eAA" >

        <ImageView
            android:id="@+id/logoImage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#7ba1d1"
            android:src="@drawable/logo_conekta" />
    </FrameLayout>

    <LinearLayout
        android:id="@+id/bodyLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.7"
        android:background="#f3f3f3"
        android:orientation="horizontal" >

        <FrameLayout
            android:id="@+id/leftBlankFrameLayout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="0.15"
            android:background="#f3f3f3" >
        </FrameLayout>

        <LinearLayout
            android:id="@+id/centerVerticalLayout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="0.7"
            android:orientation="vertical" >

            <FrameLayout
                android:id="@+id/topCenterFrameLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.35" >
            </FrameLayout>

            <TextView
                android:id="@+id/venueLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.025"
                android:text="What are you looking for?"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000000" />

            <EditText
                android:id="@+id/venueTextField"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.025" >

                <requestFocus />
            </EditText>

            <FrameLayout
                android:id="@+id/middleCenterFrameLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.05" >
            </FrameLayout>

            <TextView
                android:id="@+id/locationLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.025"
                android:text="Where?"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000000" />

            <AutoCompleteTextView
                android:id="@+id/locationTextField"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.025"
                android:text="" />

            <LinearLayout
                android:id="@+id/buttonLinearLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.05"
                android:background="#f3f3f3"
                android:orientation="horizontal" >

                <FrameLayout
                    android:id="@+id/leftButtonLinearLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="0.1" >
                </FrameLayout>

                <Button
                    android:id="@+id/searchButton"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="0.8"
                    android:background="#6fa8dc"
                    android:text="Search" />

                <FrameLayout
                    android:id="@+id/rightButtonLinearLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="0.1" >
                </FrameLayout>
            </LinearLayout>

            <FrameLayout
                android:id="@+id/bottomCenterFrameLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.35" >
            </FrameLayout>
        </LinearLayout>

        <FrameLayout
            android:id="@+id/rightBlankFrameLayout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="0.15"
            android:background="#f3f3f3" >
        </FrameLayout>
    </LinearLayout>

    <FrameLayout
        android:id="@+id/footerFrameLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.15"
        android:background="#7ba1d1" >
    </FrameLayout>

</LinearLayout>

知道为什么会这样吗?

11-16 23:57:41.408: W/ResourceType(409): No package identifier when getting name for resource number 0x00000000
11-16 23:57:41.427: D/AndroidRuntime(409): Shutting down VM
11-16 23:57:41.427: W/dalvikvm(409): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
11-16 23:57:41.427: E/AndroidRuntime(409): Uncaught handler: thread main exiting due to uncaught exception
11-16 23:57:41.447: E/AndroidRuntime(409): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.conekta/com.app.conekta.Conekta}: android.content.res.Resources$NotFoundException: String resource ID #0x0
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.os.Looper.loop(Looper.java:123)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.ActivityThread.main(ActivityThread.java:4363)
11-16 23:57:41.447: E/AndroidRuntime(409):  at java.lang.reflect.Method.invokeNative(Native Method)
11-16 23:57:41.447: E/AndroidRuntime(409):  at java.lang.reflect.Method.invoke(Method.java:521)
11-16 23:57:41.447: E/AndroidRuntime(409):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-16 23:57:41.447: E/AndroidRuntime(409):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-16 23:57:41.447: E/AndroidRuntime(409):  at dalvik.system.NativeStart.main(Native Method)
11-16 23:57:41.447: E/AndroidRuntime(409): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.content.res.Resources.getText(Resources.java:200)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.widget.Toast.makeText(Toast.java:258)
11-16 23:57:41.447: E/AndroidRuntime(409):  at com.app.conekta.Conekta.onStart(Conekta.java:27)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.Activity.performStart(Activity.java:3723)
11-16 23:57:41.447: E/AndroidRuntime(409):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
11-16 23:57:41.447: E/AndroidRuntime(409):  ... 11 more
11-16 23:57:41.467: I/dalvikvm(409): threadid=7: reacting to signal 3
11-16 23:57:41.467: E/dalvikvm(409): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

1 个答案:

答案 0 :(得分:1)

尝试更改

Toast.makeText(Conekta.this, fl1.getHeight(), Toast.LENGTH_SHORT).show();

Toast.makeText(Conekta.this, String.valueOf(fl1.getHeight()), Toast.LENGTH_SHORT).show();