我早些时候发布了这个问题,但几乎没有人看到它,很长一段时间后我没有收到任何答案。
每次单击按钮启动新活动时,我都会收到此错误:
java.lang.NoClassDefFoundError: android.support.v4.util.SparseArrayCompat
Eclipse用户已经回答了这个问题,但我使用的是 IntelliJ。尝试在我的 Android 应用程序中实现一些库后,我得到了这个。这是我的 LogCat:
08-03 22:47:58.471: ERROR/AndroidRuntime(19876): FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #9: Error inflating class com.origamilabs.library.views.StaggeredGridView
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.example.PixelBin.ThePixelBinActivities.Top_Fragment.onCreateView(Top_Fragment.java:37)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:139)
at android.support.v4.view.ViewPager.populate(ViewPager.java:804)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1016)
at android.view.View.measure(View.java:12725)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12725)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:12725)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
at android.view.View.measure(View.java:12725)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1075)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2453)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
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:586)
... 34 more
Caused by: java.lang.NoClassDefFoundError: android.support.v4.util.SparseArrayCompat
at com.origamilabs.library.views.StaggeredGridView.<init>(StaggeredGridView.java:296)
at com.origamilabs.library.views.StaggeredGridView.<init>(StaggeredGridView.java:304)
... 37 more
有谁知道如何为像我这样的 IntelliJ 用户摆脱这个错误?从 Eclipse 解决方案看来,它更像是与 IDE 相关的问题,而不是与代码相关的问题。