Android Compatibility Library error
Has anyone try the demo app for the new compatibility library on Android yet. Here
I am trying v4 build on API 11 and I keep on getting this error when I try the Support4Demo and click on Tabs and Pager in the Fragment Demo
e07-16 21:32:06.890: ERROR/AndroidRuntime(15315): java.lang.NoClassDefFoundError: com.example.android.supportv4.app.LoaderCustomSupport$AppListFragment 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at com.example.android.supportv4.app.FragmentTabs.onCreate(FragmentTabs.java:55) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.app.Instrumentation.callActivit开发者_如何学GoyOnCreate(Instrumentation.java:1072) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.app.ActivityThread.access$1500(ActivityThread.java:132) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.os.Handler.dispatchMessage(Handler.java:99) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.os.Looper.loop(Looper.java:143) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at android.app.ActivityThread.main(ActivityThread.java:4263) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at java.lang.reflect.Method.invokeNative(Native Method) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at java.lang.reflect.Method.invoke(Method.java:507) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-16 21:32:06.890: ERROR/AndroidRuntime(15315): at dalvik.system.NativeStart.main(Native Method)
Can anyone help me out in this?
The reason the class can't be found is that one of the Interfaces that the AppListFragment implements (OnQuerytextListener) is defined in SearchView which is only found in Honeycomb (API 11+).
public static class AppListFragment extends ListFragment implements OnQueryTextListener, LoaderManager.LoaderCallbacks<List<AppEntry>>
{
I've searched through the compatibility jar but can't find anything to do with SearchView so I assume this will only work on Honeycomb and up (and compiling at a target lower than Honeycomb does prevent this working.
There are also a couple of other failures for the same reason for example Loader -> Throttle then press menu - missing method.
From the Compatibility Package page
Warning: Be certain that you not confuse the standard android packages with those in android.support library. Some code completion tools might get this wrong, especially if you're building against recent versions of the platform. To be safe, keep your build target set to the same version as you have defined for your android:minSdkVersion and double check the import statements for classes that also exist in the support library, such as SimpleCursorAdapter
Following their own advice means the entire project can't compile - half the example classes seem to be reliant on something higher than API 4.
My answer? Some of the examples are bad and are relying on code not present. With any luck Google will update them to work soon.
Oh yeah, you can temporarily make it work by removing the OnQueryTextListener and the methods from the AppListFragment, but it'll fail later with a different problem.
I have solved this problem by commenting out the proper lines in FragmentTab.onCreate and FragmentTabPager.onCreate.
//mTabManager.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
// LoaderCustomSupport.AppListFragment.class, null);
精彩评论