Error inflating class android.support.v4.view.ViewPager(膨胀类 android.support.v4.view.ViewPager 时出错)
问题描述
我一直在尝试为在 <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15"/>
上运行的应用程序创建一个寻呼机我写了我的根据这篇博文编写代码.
I've been trying to create a Pager for my application that runs on <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15" />
I wrote my code according to this blog post.
寻呼机活动的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/instructionsViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
适配器代码:
public class MyPagerAdapter extends PagerAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return 2;
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return (arg0 == ((View) arg1));
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) container.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 1:
resId = R.layout.instructions_page1;
break;
case 2:
resId = R.layout.instructions_page2;
break;
}
View view = inflater.inflate(resId, null);
((ViewPager) container).addView(view, 0);
return view;
}
}
活动代码
public class Instructions extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.instructions);
MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager pager = (ViewPager) findViewById(R.id.instructionsViewPager);
pager.setAdapter(adapter);
pager.setCurrentItem(0);
}
}
由于某种原因,当我运行此应用程序时,我收到以下错误列表:
for some reason, when I run this app, I get this following error list:
05-28 09:38:54.535: E/AndroidRuntime(18658): FATAL EXCEPTION: main
05-28 09:38:54.535: E/AndroidRuntime(18658): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thepoosh/com.thepoosh.Instructions}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v4.view.ViewPager
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.os.Looper.loop(Looper.java:123)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-28 09:38:54.535: E/AndroidRuntime(18658): at java.lang.reflect.Method.invokeNative(Native Method)
05-28 09:38:54.535: E/AndroidRuntime(18658): at java.lang.reflect.Method.invoke(Method.java:507)
05-28 09:38:54.535: E/AndroidRuntime(18658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
05-28 09:38:54.535: E/AndroidRuntime(18658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
05-28 09:38:54.535: E/AndroidRuntime(18658): at dalvik.system.NativeStart.main(Native Method)
05-28 09:38:54.535: E/AndroidRuntime(18658): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v4.view.ViewPager
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-28 09:38:54.535: E/AndroidRuntime(18658): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.Activity.setContentView(Activity.java:1663)
05-28 09:38:54.535: E/AndroidRuntime(18658): at com.thepoosh.Instructions.onCreate(Instructions.java:11)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-28 09:38:54.535: E/AndroidRuntime(18658): ... 11 more
05-28 09:38:54.535: E/AndroidRuntime(18658): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loader dalvik.system.PathClassLoader[/data/app/com.thepoosh-1.apk]
05-28 09:38:54.535: E/AndroidRuntime(18658): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-28 09:38:54.535: E/AndroidRuntime(18658): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-28 09:38:54.535: E/AndroidRuntime(18658): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
05-28 09:38:54.535: E/AndroidRuntime(18658): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-28 09:38:54.535: E/AndroidRuntime(18658): ... 20 more
所以,我知道它失败了,因为我正在使用 android.support.v4.view.ViewPager
,我尝试使用它并更改为纯 ViewPager
和导入 android.support.v13
但没有帮助...
so, I know it's failing because I'm using the android.support.v4.view.ViewPager
, I tried playing with that and changing to plain ViewPager
and importing android.support.v13
but it didn't help...
关于如何解决此问题的任何想法?
any thoughts on how to fix this?
推荐答案
确保将库放在项目中的公共文件夹中,例如 libs.
Make sure that you place your libraries in a common folder such as libs in your project.
右键单击 jar,然后选择 Build Path 并单击 Add to Build Path.
Right click on the jar, then select Build Path and click on Add to Build Path.
这会将您的库添加到您的项目中.如果一切正确,您可以在名为Referenced Libraries"的项目中生成的文件夹"中看到它
That will add your library to your project. If everything is correct, you can see it in a generated "folder" in the project called "Referenced Libraries"
这篇关于膨胀类 android.support.v4.view.ViewPager 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:膨胀类 android.support.v4.view.ViewPager 时出错
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01