twlkyao
twlkyao

Reputation: 14628

Android ‘InvocationTargetException‘ and 'UnsupportedOperationException'

I have encountered a problem on OPPO X905 and OPPO X907, both are of Android 4.0.3(API Level 15), I haven't used any higher level API, and I have searched on Google and SO, all are different from my problem, below are my xml file and crash log, thanks in advance.

xml file:(the margin of divider was originally 7.5dp, could this be the problem?)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_full"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#eff0f7"
    android:baselineAligned="false"
    android:orientation="vertical" >
    <RelativeLayout
        android:id="@+id/item_first_half"
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:orientation="vertical" >
        <View
            android:id="@+id/first_path"
            android:layout_width="4dp"
            android:layout_height="4dp"
            android:layout_marginLeft="40dp"
            android:layout_marginStart="40dp"
            android:background="@drawable/selector_car_action_path" />
        <ImageView
            android:id="@+id/im_car_direction_icon"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_gravity="top"
            android:layout_marginLeft="28dp"
            android:layout_marginStart="28dp"
            android:layout_marginTop="4dp"
            android:background="@drawable/selector_car_action_background"
            android:padding="2dp"
            android:src="@drawable/selector_navi_icon_63" />
        <View
            android:id="@+id/second_path"
            android:layout_width="4dp"
            android:layout_height="4dp"
            android:layout_below="@id/im_car_direction_icon"
            android:layout_marginLeft="40dp"
            android:layout_marginStart="40dp"
            android:background="@drawable/selector_car_action_path" />
        <TextView
            android:id="@+id/tv_direction"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginEnd="15dp"
            android:layout_marginLeft="68dp"
            android:layout_marginRight="15dp"
            android:layout_marginStart="68dp"
            android:singleLine="true"
            android:text=""
            android:textColor="@drawable/selector_car_route_turn_text"
            android:textSize="16sp" />
    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/item_second_half"
        android:layout_width="match_parent"
        android:layout_height="32dp" >
        <View
            android:id="@+id/third_path"
            android:layout_width="4dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="40dp"
            android:layout_marginStart="40dp"
            android:background="@drawable/selector_car_action_path" />
        <TextView
            android:id="@+id/tv_road_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="68dp"
            android:layout_marginStart="68dp"
            android:layout_marginTop="4dp"
            android:singleLine="true"
            android:text=""
            android:textColor="@drawable/selector_car_route_desc"
            android:textSize="16sp" />
        <TextView
            android:id="@+id/divider_for_road_and_distance"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginEnd="7dp"
            android:layout_marginLeft="7dp"
            android:layout_marginRight="7dp"
            android:layout_marginStart="7dp"
            android:layout_marginTop="4dp"
            android:layout_toEndOf="@id/tv_road_name"
            android:layout_toRightOf="@id/tv_road_name"
            android:singleLine="true"
            android:text="|"
            android:textColor="@drawable/selector_car_route_desc"
            android:textSize="16sp" />
        <TextView
            android:id="@+id/tv_ride_distance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="4dp"
            android:layout_toEndOf="@id/divider_for_road_and_distance"
            android:layout_toRightOf="@id/divider_for_road_and_distance"
            android:singleLine="true"
            android:text=""
            android:textColor="@drawable/selector_car_route_desc"
            android:textSize="16sp" />
        <View
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:layout_alignParentBottom="true"
            android:layout_marginEnd="15dp"
            android:layout_marginLeft="68dp"
            android:layout_marginRight="15dp"
            android:layout_marginStart="68dp"
            android:background="#dee1f0" />
    </RelativeLayout>
</LinearLayout>

The drawable/selector_car_route_desc file is

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true" android:color="@color/color_999999"/>
    <item android:state_selected="false" android:color="@color/color_333333"/>

</selector>

crash log:

android.view.InflateException: Binary XML file line #106: Error inflating class <unknown>
android.view.LayoutInflater.createView(LayoutInflater.java:606)
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
android.view.LayoutInflater.inflate(LayoutInflater.java:489)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.tencent.map.ama.route.ui.view.e.<init>(CarRouteShowItem.java:78)
com.tencent.map.ama.route.ui.view.f.a(CarRouteShowView.java:100)
com.tencent.map.ama.route.ui.view.d.a(CarRouteDetailView.java:37)
com.tencent.map.ama.route.ui.MapStateCarRoute.e(MapStateCarRoute.java:418)
com.tencent.map.ama.route.ui.MapStateCarRoute$1.run(MapStateCarRoute.java:255)
android.os.Handler.handleCallback(Handler.java:605)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4476)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
dalvik.system.NativeStart.main(Native Method)
cause by:
java.lang.reflect.InvocationTargetException: null
java.lang.reflect.Constructor.constructNative(Native Method)
java.lang.reflect.Constructor.newInstance(Constructor.java:417)
android.view.LayoutInflater.createView(LayoutInflater.java:586)
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
android.view.LayoutInflater.inflate(LayoutInflater.java:489)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.tencent.map.ama.route.ui.view.e.<init>(CarRouteShowItem.java:78)
com.tencent.map.ama.route.ui.view.f.a(CarRouteShowView.java:100)
com.tencent.map.ama.route.ui.view.d.a(CarRouteDetailView.java:37)
com.tencent.map.ama.route.ui.MapStateCarRoute.e(MapStateCarRoute.java:418)
com.tencent.map.ama.route.ui.MapStateCarRoute$1.run(MapStateCarRoute.java:255)
android.os.Handler.handleCallback(Handler.java:605)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4476)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
dalvik.system.NativeStart.main(Native Method)
cause by:
java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
android.view.View.<init>(View.java:2849)
android.widget.TextView.<init>(TextView.java:499)
android.widget.TextView.<init>(TextView.java:492)
java.lang.reflect.Constructor.constructNative(Native Method)
java.lang.reflect.Constructor.newInstance(Constructor.java:417)
android.view.LayoutInflater.createView(LayoutInflater.java:586)
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
android.view.LayoutInflater.inflate(LayoutInflater.java:489)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.tencent.map.ama.route.ui.view.e.<init>(CarRouteShowItem.java:78)
com.tencent.map.ama.route.ui.view.f.a(CarRouteShowView.java:100)
com.tencent.map.ama.route.ui.view.d.a(CarRouteDetailView.java:37)
com.tencent.map.ama.route.ui.MapStateCarRoute.e(MapStateCarRoute.java:418)
com.tencent.map.ama.route.ui.MapStateCarRoute$1.run(MapStateCarRoute.java:255)
android.os.Handler.handleCallback(Handler.java:605)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4476)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
dalvik.system.NativeStart.main(Native Method)

the code of CarRouteShowItem.java:78 is like this:

View mView = LayoutInflater.from(mContext).inflate(R.layout.car_route_detail_item, null);

The CarRouteShowItem is not child of View, its code is as follows:

public class CarRouteShowItem {

    private Context mContext;

    private View mView;

    public CarRouteShowItem(Context context) {
        mContext = context;

        // mView is used by caller 
        mView = LayoutInflater.from(mContext).inflate(R.layout.car_route_detail_item, null);

        // some view finds 
    }

        // some other methods related with specific logic
}

The graphic layout could preview in the Eclipse from API level 8 to API level 23, but when I preview it in Android Studio on API level 15, it gives the error message:Couldn't resolve resource @style/Widget.TextView, other API levels are OK, but I haven't use the style for TextView.

Upvotes: 3

Views: 1896

Answers (2)

Elltz
Elltz

Reputation: 10869

All you need is an extra eye :-)

enter image description here

 android:layout_height="1px"

hope you can see now. The last child in your second RelativeLayout with id item_second_half of type <View change it to

android:layout_height="1dp"

let me have my eye back as soon as possible

Upvotes: 4

gmetax
gmetax

Reputation: 3973

I think the problem is somewhere in @style/ referenced in AppTheme. Try to remove all of them (reset to default) and add one-by-one until the crash occurs. This way you can find the style that has wrong attributes.

if you see down on your log error you will see that the InvocationTargetException occurs by java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12

UPDATE

I noticed something bad in your xml file, you are using text color as "drawable", you have to use colors xml file (example)

UPDATE AGAIN

after more search i found this file if you see the 499 and 492 line (that appears on logerror) you will see that maybe it couldn't find style for textview

Upvotes: 3

Related Questions