我正在开发一个包含模拟量表视图的Android应用程序,当我在eclipse中导入该库并且项目成功运行时,我发现它here。当我将该库包含到我的项目中时,它不接受它。在库文件旁边显示一个红色十字标记,我的应用程序崩溃显示: - 无法启动活动ComponentInfo {com.example.c1test / com.example.c1test .Test}:android.view.InflateException 我也尝试以JAR文件的形式添加库但是它没有用,请帮助我,我正在处理它,因为四个小时请帮助我。这是我的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<View
android:id="@+id/view2_drve_res_test"
android:layout_width="2dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/rltve_1_drve_res_test"
android:background="#000000" />
<View
android:id="@+id/view_drve_res_test"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/textView2_drve_res_test"
android:layout_toRightOf="@+id/rltve_1_drve_res_test"
android:background="#000000" />
<TextView
android:id="@+id/textView2_drve_res_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/view2_drve_res_test"
android:gravity="center"
android:paddingLeft="10dp"
android:text="@string/Coil_heading"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="@+id/lner_drve_res_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2_drve_res_test"
android:layout_alignParentRight="true"
android:layout_below="@+id/view_drve_res_test"
android:layout_marginTop="28dp" >
<TextView
android:id="@+id/txtview_drve_res_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Coil_1_value"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/edtxt_coil_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:id="@+id/rltve_1_drve_res_test"
android:layout_width="750dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<com.example.libraryforvoltmeter
android:id="@+id/gauge_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</RelativeLayout>
<LinearLayout
android:id="@+id/lner_drve_res_test_coil_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2_drve_res_test"
android:layout_alignParentRight="true"
android:layout_below="@+id/lner_drve_res_test"
android:layout_marginTop="28dp" >
<TextView
android:id="@+id/txtview_drve_res_test_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Coil_2_value"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/edttxt_coil_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<requestFocus />
</EditText>
</LinearLayout>
<RelativeLayout
android:id="@+id/rltve_2_drve_res_test"
android:layout_width="750dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</RelativeLayout>
<LinearLayout
android:id="@+id/lnear_drve_res_test_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/lner_drve_res_test_coil_2"
android:layout_marginTop="41dp"
android:layout_toRightOf="@+id/rltve_1_drve_res_test" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Voltage_value"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/edttxt_voltage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
这是我的Log cat:
01-02 06:38:11.530: W/dalvikvm(11015): threadid=1: thread exiting with uncaught exception (group=0x41694700)
01-02 06:38:11.550: D/dalvikvm(11015): GC_FOR_ALLOC freed 127K, 5% free 3484K/3664K, paused 15ms, total 17ms
01-02 06:38:11.560: E/AndroidRuntime(11015): FATAL EXCEPTION: main
01-02 06:38:11.560: E/AndroidRuntime(11015): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.medequip.c1testpanel/com.medequip.c1testpanel.DriveResponseTest}: android.view.InflateException: Binary XML file line #88: Error inflating class com.example.libraryforvoltmeter
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.os.Looper.loop(Looper.java:137)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-02 06:38:11.560: E/AndroidRuntime(11015): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 06:38:11.560: E/AndroidRuntime(11015): at java.lang.reflect.Method.invoke(Method.java:525)
01-02 06:38:11.560: E/AndroidRuntime(11015): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-02 06:38:11.560: E/AndroidRuntime(11015): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-02 06:38:11.560: E/AndroidRuntime(11015): at dalvik.system.NativeStart.main(Native Method)
01-02 06:38:11.560: E/AndroidRuntime(11015): Caused by: android.view.InflateException: Binary XML file line #88: Error inflating class com.example.libraryforvoltmeter
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-02 06:38:11.560: E/AndroidRuntime(11015): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.Activity.setContentView(Activity.java:1895)
01-02 06:38:11.560: E/AndroidRuntime(11015): at com.medequip.c1testpanel.DriveResponseTest.onCreate(DriveResponseTest.java:71)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.Activity.performCreate(Activity.java:5133)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-02 06:38:11.560: E/AndroidRuntime(11015): ... 11 more
01-02 06:38:11.560: E/AndroidRuntime(11015): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.libraryforvoltmeter" on path: DexPathList[[zip file "/data/app/com.medequip.c1testpanel-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.medequip.c1testpanel-1, /vendor/lib, /system/lib]]
01-02 06:38:11.560: E/AndroidRuntime(11015): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
01-02 06:38:11.560: E/AndroidRuntime(11015): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-02 06:38:11.560: E/AndroidRuntime(11015): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
01-02 06:38:11.560: E/AndroidRuntime(11015): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
01-02 06:38:11.560: E/AndroidRuntime(11015): ... 22 more
答案 0 :(得分:2)
以下行包含错误:
<com.example.libraryforvoltmeter
android:id="@+id/gauge_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1" />
可能是libraryforvoltmeter类不在以下包中:com.example 更改放置该库类文件的包