gpt4 book ai didi

java - 致命异常 : main/android. view.InflateException

转载 作者:行者123 更新时间:2023-11-29 22:12:03 25 4
gpt4 key购买 nike

我正在尝试为我的应用程序创建一个 ViewPager。我是 android 开发的新手,所以我首先尝试一个示例来查看它是如何工作的 this地点。当我尝试在模拟器中运行它时,它会强制关闭。我不知道为什么会出现错误,我检查了很多次代码,没有任何区别。

因为代码与上面链接中的代码相同,所以我只提供 logcat。

01-30 04:07:40.059: E/AndroidRuntime(3013): FATAL EXCEPTION: main
01-30 04:07:40.059: E/AndroidRuntime(3013): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testviewpager/com.testviewpager.TestViewPagerActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class com.viewpagerindicator.TitlePagePageIndicator
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.os.Looper.loop(Looper.java:123)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-30 04:07:40.059: E/AndroidRuntime(3013): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 04:07:40.059: E/AndroidRuntime(3013): at java.lang.reflect.Method.invoke(Method.java:507)
01-30 04:07:40.059: E/AndroidRuntime(3013): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-30 04:07:40.059: E/AndroidRuntime(3013): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-30 04:07:40.059: E/AndroidRuntime(3013): at dalvik.system.NativeStart.main(Native Method)
01-30 04:07:40.059: E/AndroidRuntime(3013): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.viewpagerindicator.TitlePagePageIndicator
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-30 04:07:40.059: E/AndroidRuntime(3013): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.Activity.setContentView(Activity.java:1657)
01-30 04:07:40.059: E/AndroidRuntime(3013): at com.testviewpager.TestViewPagerActivity.onCreate(TestViewPagerActivity.java:14)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-30 04:07:40.059: E/AndroidRuntime(3013): ... 11 more
01-30 04:07:40.059: E/AndroidRuntime(3013): Caused by: java.lang.ClassNotFoundException: com.viewpagerindicator.TitlePagePageIndicator in loader dalvik.system.PathClassLoader[/data/app/com.testviewpager-1.apk]
01-30 04:07:40.059: E/AndroidRuntime(3013): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-30 04:07:40.059: E/AndroidRuntime(3013): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-30 04:07:40.059: E/AndroidRuntime(3013): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
01-30 04:07:40.059: E/AndroidRuntime(3013): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
01-30 04:07:40.059: E/AndroidRuntime(3013): ... 20 more

com.viewpagerindicator 是一个库项目(在其 com.jakewharton.android.viewpagerindicator 的链接上,我知道,我只是将其更改为原始版本),我没有进行任何更改,仅从作者站点导入。因此,如果有人知道我做错了什么,请提供帮助。如果这还不够,我可以提供更多信息。

最佳答案

我有同样的问题,但我发现如果您关注 this link ,解决方案非常简单像我一样,你必须从你的主布局中删除这部分 [jakewharton.android] 引用链接主布局这是什么导致 inflateException 并使其就像你的 viewPagerIndicator 库包名称一样

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.viewpagerindicator.TitlePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

关于java - 致命异常 : main/android. view.InflateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9386116/

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