0

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>
Kishan Dhamat
  • 3,746
  • 2
  • 26
  • 36
  • Have you written something in `onPause` of activity which might cause this? – MysticMagicϡ Sep 19 '14 at 05:13
  • 1
    Please post the last activity visible with its class name – Asheesh Sep 19 '14 at 05:13
  • 1
    `09-19 10:27:34.849: E/AndroidRuntime(28041): at com.squarespix.MobieAlert.PostsGridAdapter.getView(PostsGridAdapter.java:134)` post related classes, indicate line 134 – EpicPandaForce Sep 19 '14 at 05:17
  • @Dhruti We are absolutely doing nothing in onPause – Programming Pirate Sep 19 '14 at 05:21
  • 2
    There is problem in your XML file. Post your xml file. – Piyush Sep 19 '14 at 05:25
  • @Zhuinden I am Updating my question with a code snippet please have a look. – Programming Pirate Sep 19 '14 at 05:28
  • @PG_Android I have posted my xml for layout_single_post please have a look at it – Programming Pirate Sep 19 '14 at 05:36
  • Based on the error `Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1 09-19 10:45:34.039: E/AndroidRuntime(4263): at ` I would first make a copy of this XML file, then remove all dimensions and see if that fixes the issue. – EpicPandaForce Sep 19 '14 at 05:36
  • @Zhuinden Thank you I will try it and let you know. – Programming Pirate Sep 19 '14 at 05:38
  • @Zhuinden I did as you suggested and now its working, what might be the problem?? When I gave hard coded values I took reference from the dimens file only, all the values are specified. So is it better to go with different layouts for different devices instead of values for each type of device? – Programming Pirate Sep 19 '14 at 05:49
  • No need to remove them all, just check the ones in the element on row #7 (`Binary XML file line #7`) - likely `@dimen/single_post_date_size` – laalto Sep 19 '14 at 05:50
  • 1
    I think the problem is that there is no "default" dimension file without a resource identifier on the folder, and so there can be cases in which it cannot find the dimensions on reload. – EpicPandaForce Sep 19 '14 at 05:54
  • @Zhuinden Which device should we consider as default, as there are variety of android devices and each one have different values, while providing the default dimension file. Is it mdpi device?. – Programming Pirate Sep 19 '14 at 06:07
  • 1
    Just have a values folder without an identifier for the case of not finding any dimensions, but having one for mdpi is not a bad idea. – EpicPandaForce Sep 19 '14 at 06:08
  • @Zhuinden I also want to know, if there is any way to make the devices pick different layouts if it has hardware navigation keys. I have posted my code snippet in my post (I am using back key and home key to identify the device with hardware nav bar and providing a different layout for it). Is it a correct way? Is there any other reliable or standard way? – Programming Pirate Sep 19 '14 at 06:23
  • http://stackoverflow.com/questions/16092431/check-for-navigation-bar ? oh wait, that's somewhat what you are using, nevermind. I guess not. – EpicPandaForce Sep 19 '14 at 06:27
  • @Zhuinden Yeah we are using the same approach, but is there a better way to do? Is it necessary to use two different layouts one for devices with navigation bar and other for devices with hardware nav bar? – Programming Pirate Sep 19 '14 at 06:33

1 Answers1

0

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