0

我有这个应用程序使用 ViewPager 和 ViewPagerIndicator,由于某种原因,我不断收到以下错误。我似乎无法弄清楚为什么会出现错误。任何帮助将不胜感激。根据堆栈跟踪,我认为我的 main.xml 在 vi​​ewpager 启动的那一行存在问题,但我之前没有做过任何事情。这可能来自图书馆方面吗?

 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

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

4

2 回答 2

0

使用 Fragment 时应使用 SherlockFragmentActivity

于 2013-05-18T21:34:56.020 回答
0

这个问题是由最新的更新引起的Android Support Library rev.13,我更新了我的库项目和自己的项目的支持包,从那时起问题就发生了。因此,当使用支持包 12 及以下版本时,该问题已得到解决。

于 2013-05-28T21:10:06.740 回答