问题
When I create a new Android Sample Project from eclipse with api level 14, add the compatibility library and try to run it on my gingerbread device. It gave the following error :
Error Inflating Class SwitchPreference
I just commented the SwitchPreference
from the preferences xml file and was able to run the api demos app. But the Fragment(and few others) demos were not available.
Is this expected? should I have a device running api-14 to be able to see the Fragment demos? Am I missing anything in the process of creating the project?
Any help is appreciated.
回答1:
The compatibility library provides the Fragment API, but it doesn't somehow upgrade your API level 10 device to API 11 or 14. The sample projects for API 14 probably use other APIs besides fragments that the compatibility library does not provide. Additionally, the namespaces are different. You'll have to do some work to port that sample back if you want to run it on Gingerbread. I would look in the samples in the compatibility library instead.
回答2:
API 13 devices can't run API 14 programs. Drop the required API level of your application (if you can). If you're not using any API 14 things, it should work for you.
来源:https://stackoverflow.com/questions/8189554/how-to-run-the-api-level-14-demos-on-gingerbread-and-lower-devices