我试图摆脱一个麻烦的例外。

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.galleryphoto_fragment, null);
...

This line leads to Binary XML file line #13: Error inflating class pl.XXX.app.utils.ImageViewZoom


这个XML文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ProgressBar
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="gone" />

    <pl.XXX.app.utils.ImageViewZoom <!-- line #13 -->
        android:id="@+id/mainPhoto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="matrix" />

</FrameLayout>


我已经为您标记了第13行。

我尝试了什么?好吧,最初我以为是ImageViewZoom错误未正确注册,但是当从另一段代码中调用时它可以正常工作。有人可以在这里向我指出正确的方向吗?

更新
这是堆栈:

android.view.InflateException: Binary XML file line #13: Error
 inflating class pl.XXX.app.utils.ImageViewZoom
         at android.view.LayoutInflater.createView(LayoutInflater.java:620)
         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
         at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
         at pl.XXX.app.fragments.GalleryPhotoFragment.onCreateView(GalleryPhotoFragment.java:41)
         at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
         at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
         at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
         at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
         at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
         at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
         at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:442)
         at pl.XXX.app.GalleryActivity.setPhotosAdapter(GalleryActivity.java:351)
         at pl.XXX.app.GalleryActivity.access$1400(GalleryActivity.java:67)
         at pl.XXX.app.GalleryActivity$GetPhotos.onPostExecute(GalleryActivity.java:543)
         at pl.XXX.app.GalleryActivity$GetPhotos.onPostExecute(GalleryActivity.java:518)
         at android.os.AsyncTask.finish(AsyncTask.java:631)
         at android.os.AsyncTask.access$600(AsyncTask.java:177)
         at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
         at android.os.Handler.dispatchMessage(Handler.java:99)
         at android.os.Looper.loop(Looper.java:137)
         at android.app.ActivityThread.main(ActivityThread.java:5103)
         at java.lang.reflect.Method.invokeNative(Native Method)
         at java.lang.reflect.Method.invoke(Method.java:525)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
         at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.reflect.InvocationTargetException
         at java.lang.reflect.Constructor.constructNative(Native Method)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
         at android.view.LayoutInflater.createView(LayoutInflater.java:594)
         ... 31 more
         Caused by: java.lang.NoClassDefFoundError: it.sephiroth.android.library.easing.Cubic
         at it.sephiroth.android.library.imagezoom.ImageViewTouchBase.<init>(ImageViewTouchBase.java:72)
         at it.sephiroth.android.library.imagezoom.ImageViewTouch.<init>(ImageViewTouch.java:42)
         at pl.XXX.app.utils.ImageViewZoom.<init>(ImageViewZoom.java:21)
         at pl.XXX.app.utils.ImageViewZoom.<init>(ImageViewZoom.java:17)
         ... 34 more

最佳答案

Caused by: java.lang.NoClassDefFoundError: it.sephiroth.android.library.easing.Cubic
  at it.sephiroth.android.library.imagezoom.ImageViewTouchBase.<init>(ImageViewTouchBase.java:72)
  at it.sephiroth.android.library.imagezoom.ImageViewTouch.<init>(ImageViewTouch.java:42)
  at pl.XXX.app.utils.ImageViewZoom.<init>(ImageViewZoom.java:21)
  at pl.XXX.app.utils.ImageViewZoom.<init>(ImageViewZoom.java:17)


您的ImageViewZoom构造函数最终会调用ImageViewTouchBase构造函数,而该it.sephiroth.android.library.easing.Cubic找不到。确保代码包含在您的项目中。

07-27 21:50