简体   繁体   中英

Android Home Button Click crashes the app

I am developing an application in which I came across a weird problem. The app works fine but when the user clicks on home button of the device the app crashes giving the following error.

LogCat **

09-19 10:45:33.989: W/ResourceType(4263): Failure getting entry for 0x7f0a0017 (t=9 e=23) in package 0 (error -75)
09-19 10:45:33.989: D/AndroidRuntime(4263): Shutting down VM
09-19 10:45:33.989: W/dalvikvm(4263): threadid=1: thread exiting with uncaught exception (group=0x41615d88)
09-19 10:45:34.039: E/AndroidRuntime(4263): FATAL EXCEPTION: main
09-19 10:45:34.039: E/AndroidRuntime(4263): Process: com.squarespix.MobieAlert, PID: 4263
09-19 10:45:34.039: E/AndroidRuntime(4263): android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at com.squarespix.MobieAlert.PostsGridAdapter.getView(PostsGridAdapter.java:134)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.AbsListView.obtainView(AbsListView.java:2263)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.GridView.onMeasure(GridView.java:1048)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.View.measure(View.java:16628)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.View.measure(View.java:16628)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.View.measure(View.java:16628)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.View.measure(View.java:16628)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2295)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.View.measure(View.java:16628)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1920)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1117)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1299)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5703)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.Choreographer.doFrame(Choreographer.java:544)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.os.Handler.handleCallback(Handler.java:743)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.os.Looper.loop(Looper.java:136)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.app.ActivityThread.main(ActivityThread.java:5212)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at java.lang.reflect.Method.invokeNative(Native Method)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at java.lang.reflect.Method.invoke(Method.java:515)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at dalvik.system.NativeStart.main(Native Method)
09-19 10:45:34.039: E/AndroidRuntime(4263): Caused by: java.lang.reflect.InvocationTargetException
09-19 10:45:34.039: E/AndroidRuntime(4263):     at java.lang.reflect.Constructor.constructNative(Native Method)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
09-19 10:45:34.039: E/AndroidRuntime(4263):     ... 43 more
09-19 10:45:34.039: E/AndroidRuntime(4263): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:464)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.TextView.<init>(TextView.java:979)
09-19 10:45:34.039: E/AndroidRuntime(4263):     at android.widget.TextView.<init>(TextView.java:625)
09-19 10:45:34.039: E/AndroidRuntime(4263):     ... 46 more


**


if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        boolean hasBackKey = KeyCharacterMap
                .deviceHasKey(KeyEvent.KEYCODE_BACK);
        boolean hasHomeKey = KeyCharacterMap
                .deviceHasKey(KeyEvent.KEYCODE_HOME);
        // try{
        if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
            v = inflater.inflate(R.layout.layout_single_post,parent,
                    false);
        } else if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
            if (hasBackKey && hasHomeKey) {
                v = inflater.inflate(
                        R.layout.layout_single_post_hwkeys, parent,false);
            } else {
                v = inflater.inflate(R.layout.layout_single_post,parent,false);//Line 134
            }
        }
    }
    else
    {
        v=convertView;
    }

We are using this piece of code to check if the device has a on-screen or a hardware navigation bar and setting layout accordingly. Is this the correct approach? Is it causing the problem?

My xml for layout_single_post is here

<?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="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:textColor="#000000"
    android:textSize="@dimen/single_post_date_size" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/postImage"
        android:layout_width="@dimen/single_post_postimage_width"
        android:layout_height="@dimen/single_post_postimage_height"
        android:layout_marginLeft="@dimen/single_post_postimage_margin_left"
        android:contentDescription="@string/single_post_post_image"
        android:scaleType="fitXY"
        android:src="@drawable/nophoto" />

    <LinearLayout
        android:id="@+id/imagesLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/single_post_images_layout_margin_left"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/healthImage"
            android:layout_width="@dimen/single_post_health_image_width"
            android:layout_height="@dimen/single_post_health_image_height"
            android:layout_marginBottom="@dimen/single_post_health_margin_btm"
            android:contentDescription="@string/single_post_health_status_image"
            android:scaleType="fitXY"
            android:src="@drawable/health_status" />

        <ImageView
            android:id="@+id/googelMapImage"
            android:layout_width="@dimen/single_post_map_image_width"
            android:layout_height="@dimen/single_post_map_image_height"
            android:layout_marginTop="@dimen/single_post_map_margin_top"
            android:contentDescription="@string/single_post_google_map_image"
            android:scaleType="fitXY"
            android:src="@drawable/google_map_icon" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/userLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/profileImage"
            android:layout_width="@dimen/single_post_profile_image_width"
            android:layout_height="@dimen/single_post_profile_image_height"
            android:layout_marginLeft="@dimen/single_post_profile_image_margin_left"
            android:contentDescription="@string/single_post_profile_image"
            android:src="@drawable/profileimage" />

        <TextView
            android:id="@+id/tv_name"
            android:layout_width="@dimen/single_post_username_width"
            android:layout_height="@dimen/single_post_username_height"
            android:gravity="center_horizontal"
            android:textColor="#000000"
            android:textSize="@dimen/single_post_username_textsize" />
    </LinearLayout>
</LinearLayout>

<TextView
    android:id="@+id/tv_desc"
    android:layout_width="@dimen/single_post_description_width"
    android:layout_height="@dimen/single_post_description_height"
    android:layout_marginBottom="@dimen/single_post_description_margin_bottom"
    android:layout_marginLeft="@dimen/single_post_description_margin_left"
    android:layout_marginTop="@dimen/single_post_description_margin_top"
    android:textColor="#000000"
    android:textSize="@dimen/single_post_description_text_size" />

</LinearLayout>

The problem got solved. Thanks @Zhuinden that was the reason, no default dimensions were placed in the values folder without resource identifier. The same thing is given in the following link. This might help someone else also. Provide Default dimens

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM