gpt4 book ai didi

Android ‘InvocationTargetException‘ and ' UnsupportedOperationException'

转载 作者:太空宇宙 更新时间:2023-11-03 12:16:41 25 4
gpt4 key购买 nike

我在OPPO X905和OPPO X907上遇到过问题,都是Android 4.0.3(API Level 15),我没有用过更高级别的API,我在Google和SO上搜索过,都是不一样的根据我的问题,下面是我的 xml 文件和崩溃日志,在此先感谢。

xml文件:(divider的边距本来是7.5dp,会不会是这个问题?)

<?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>

drawable/selector_car_route_desc文件是

<?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>

崩溃日志:

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)

CarRouteShowItem.java:78的代码是这样的:

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

CarRouteShowItem 不是View 的子元素,它的代码如下:

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
}

图形布局可以在 Eclipse 中从 API 级别 8 预览到 API 级别 23,但是当我在 API 级别 15 的 Android Studio 中预览它时,它给出错误消息:无法解析资源@style/Widget.TextView,其他API级别都可以,但我没有使用TextView的样式。

最佳答案

你只需要多一双眼睛 :-)

enter image description here

 android:layout_height="1px"

希望你现在能看到。第二个 child 中的最后一个 RelativeLayout ID item_second_half类型 <View改成

android:layout_height="1dp"

让我尽快恢复视力

关于Android ‘InvocationTargetException‘ and ' UnsupportedOperationException',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32714637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com