我有一个使用ViewPager和ViewPagerIndicator的应用程序,由于某种原因,我不断收到以下错误。我似乎无法弄清楚错误填充的原因。任何帮助都会受到高度赞赏。基于堆栈跟踪,我认为它是viewpager启动的行上的main.xml的问题,但我之前没有做过任何事情。这可能来自图书馆方面吗?
E/ActivityThread(1220): Failed to inflate
E/ActivityThread(1220): android.view.InflateException: Binary XML file line #29: Error inflating class com.viewpagerindicator.TitlePageIndicator
E/ActivityThread(1220): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
E/ActivityThread(1220): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/ActivityThread(1220): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/ActivityThread(1220): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/ActivityThread(1220): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/ActivityThread(1220): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:323)
E/ActivityThread(1220): at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
E/ActivityThread(1220): at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
E/ActivityThread(1220): at com.jaisonbrooks.enlighten.MainActivityViewPager.onCreate(MainActivityViewPager.java:63)
E/ActivityThread(1220): at android.app.Activity.performCreate(Activity.java:5104)
E/ActivityThread(1220): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/ActivityThread(1220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
E/ActivityThread(1220): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
E/ActivityThread(1220): at android.app.ActivityThread.access$600(ActivityThread.java:153)
E/ActivityThread(1220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
E/ActivityThread(1220): at android.os.Handler.dispatchMessage(Handler.java:99)
E/ActivityThread(1220): at android.os.Looper.loop(Looper.java:137)
E/ActivityThread(1220): at android.app.ActivityThread.main(ActivityThread.java:5226)
E/ActivityThread(1220): at java.lang.reflect.Method.invokeNative(Native Method)
E/ActivityThread(1220): at java.lang.reflect.Method.invoke(Method.java:511)
/ActivityThread(1220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/ActivityThread(1220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/ActivityThread(1220): at dalvik.system.NativeStart.main(Native Method)
E/ActivityThread(1220): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.viewpagerindicator.TitlePageIndicator" on path: /data/app/com.jaisonbrooks.enlighten-1.apk
E/ActivityThread(1220): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
E/ActivityThread(1220): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/ActivityThread(1220): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/ActivityThread(1220): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
E/ActivityThread(1220): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
public class MainActivityViewPager extends SherlockActivity {
private ViewPager awesomePager;
private static int NUM_AWESOME_VIEWS = 3;
private Context context;
private AwesomePagerAdapter awesomeAdapter;
LayoutInflater inflater;
ProgressBar progressBar;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
com.actionbarsherlock.app.ActionBar actionBar = this
.getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(true);
setContentView(R.layout.main);
getSupportActionBar().show();
context = this;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
awesomeAdapter = new AwesomePagerAdapter();
awesomePager = (ViewPager) findViewById(R.id.pager);
awesomePager.setOffscreenPageLimit(3);
awesomePager.setAdapter(awesomeAdapter);
TitlePageIndicator awesomeIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
awesomePager.setAdapter(awesomeAdapter);
awesomeIndicator.setViewPager(awesomePager);
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.viewpagerindicator.TitlePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#18FF0000"
android:padding="10dip"
android:textColor="#AA000000"
app:footerColor="#FFAA2222"
app:footerIndicatorHeight="3dp"
app:footerIndicatorStyle="underline"
app:footerLineHeight="1dp"
app:selectedBold="true"
app:selectedColor="#FF000000" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
答案 0 :(得分:0)
使用片段
时应使用SherlockFragmentActivity答案 1 :(得分:0)
此问题是由Android Support Library rev.13
的最新更新引起的,我更新了我的图书馆项目和自己项目的支持包,从那时起问题就出现了。因此,在使用支持包12及其下时,问题得以解决。