我在我的应用中使用ActionBarSherlock库。我遵循了这个Tutorial但它无法正常工作,应用程序因OnCreateOptionsMenu()而一旦启动就崩溃了。我可以得到什么是错误。请帮忙
03-11 14:29:16.037: W/MenuInflater(10097): Cannot instantiate class: com.actionbarsherlock.widget.SearchView
03-11 14:29:16.037: W/MenuInflater(10097): java.lang.reflect.InvocationTargetException
03-11 14:29:16.037: W/MenuInflater(10097): at java.lang.reflect.Constructor.constructNative(Native Method)
03-11 14:29:16.037: W/MenuInflater(10097): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.view.MenuInflater$MenuState.newInstance(MenuInflater.java:488)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.view.MenuInflater$MenuState.setItem(MenuInflater.java:447)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.view.MenuInflater$MenuState.addItem(MenuInflater.java:468)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.view.MenuInflater.parseMenu(MenuInflater.java:190)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.view.MenuInflater.inflate(MenuInflater.java:112)
03-11 14:29:16.037: W/MenuInflater(10097): at com.earth.map.location.MainActivity.onCreateOptionsMenu(MainActivity.java:71)
03-11 14:29:16.037: W/MenuInflater(10097): at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:44)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:560)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:64)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:164)
03-11 14:29:16.037: W/MenuInflater(10097): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:397)
03-11 14:29:16.037: W/MenuInflater(10097): at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:759)
03-11 14:29:16.037: W/MenuInflater(10097): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2992)
03-11 14:29:16.037: W/MenuInflater(10097): at android.os.Handler.handleCallback(Handler.java:615)
03-11 14:29:16.037: W/MenuInflater(10097): at android.os.Handler.dispatchMessage(Handler.java:92)
03-11 14:29:16.037: W/MenuInflater(10097): at android.os.Looper.loop(Looper.java:137)
03-11 14:29:16.037: W/MenuInflater(10097): at android.app.ActivityThread.main(ActivityThread.java:5059)
03-11 14:29:16.037: W/MenuInflater(10097): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 14:29:16.037: W/MenuInflater(10097): at java.lang.reflect.Method.invoke(Method.java:511)
03-11 14:29:16.037: W/MenuInflater(10097): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
03-11 14:29:16.037: W/MenuInflater(10097): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
03-11 14:29:16.037: W/MenuInflater(10097): at dalvik.system.NativeStart.main(Native Method)
03-11 14:29:16.037: W/MenuInflater(10097): Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class <unknown>
03-11 14:29:16.037: W/MenuInflater(10097): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-11 14:29:16.037: W/MenuInflater(10097): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-11 14:29:16.037: W/MenuInflater(10097): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-11 14:29:16.037: W/MenuInflater(10097): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-11 14:29:16.037: W/MenuInflater(10097): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-11 14:29:16.037: W/MenuInflater(10097): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-11 14:29:16.037: W/MenuInflater(10097): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.widget.SearchView.<init>(SearchView.java:264)
03-11 14:29:16.037: W/MenuInflater(10097): at com.actionbarsherlock.widget.SearchView.<init>(SearchView.java:252)
03-11 14:29:16.037: W/MenuInflater(10097): ... 24 more
03-11 14:29:16.037: W/MenuInflater(10097): Caused by: java.lang.reflect.InvocationTargetException
03-11 14:29:16.037: W/MenuInflater(10097): at java.lang.reflect.Constructor.constructNative(Native Method)
03-11 14:29:16.037: W/MenuInflater(10097): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-11 14:29:16.037: W/MenuInflater(10097): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-11 14:29:16.037: W/MenuInflater(10097): ... 32 more
03-11 14:29:16.037: W/MenuInflater(10097): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f010030 a=-1}
03-11 14:29:16.037: W/MenuInflater(10097): at android.content.res.Resources.loadColorStateList(Resources.java:2053)
03-11 14:29:16.037: W/MenuInflater(10097): at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
03-11 14:29:16.037: W/MenuInflater(10097): at android.widget.TextView.<init>(TextView.java:803)
03-11 14:29:16.037: W/MenuInflater(10097): at android.widget.TextView.<init>(TextView.java:477)
03-11 14:29:16.037: W/MenuInflater(10097): ... 35 more
03-11 14:29:16.045: D/AndroidRuntime(10097): Shutting down VM
03-11 14:29:16.045: W/dalvikvm(10097): threadid=1: thread exiting with uncaught exception (group=0x418ab2a0)
03-11 14:29:16.045: E/AndroidRuntime(10097): FATAL EXCEPTION: main
03-11 14:29:16.045: E/AndroidRuntime(10097): java.lang.NullPointerException
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.earth.map.location.MainActivity.onCreateOptionsMenu(MainActivity.java:76)
03-11 14:29:16.045: E/AndroidRuntime(10097): at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:44)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:560)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:64)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:164)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:397)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:759)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2992)
03-11 14:29:16.045: E/AndroidRuntime(10097): at android.os.Handler.handleCallback(Handler.java:615)
03-11 14:29:16.045: E/AndroidRuntime(10097): at android.os.Handler.dispatchMessage(Handler.java:92)
03-11 14:29:16.045: E/AndroidRuntime(10097): at android.os.Looper.loop(Looper.java:137)
03-11 14:29:16.045: E/AndroidRuntime(10097): at android.app.ActivityThread.main(ActivityThread.java:5059)
03-11 14:29:16.045: E/AndroidRuntime(10097): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 14:29:16.045: E/AndroidRuntime(10097): at java.lang.reflect.Method.invoke(Method.java:511)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
03-11 14:29:16.045: E/AndroidRuntime(10097): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
03-11 14:29:16.045: E/AndroidRuntime(10097): at dalvik.system.NativeStart.main(Native Method)
MainActivity.java
public class MainActivity extends SherlockFragmentActivity implements LoaderCallbacks<Cursor> {
....
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main, menu);
// Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
答案 0 :(得分:1)
我在使用ActionBarSherlock
时注意到的一件事是,要正确使用它并且没有任何错误,您应该使用此库中的一个主题作为所有文件夹中的父级(values, values-v11, values-v14
)。因此,我想在您的values-v14/styles
或values-v14/themes
中,取决于您为应用程序使用的主要自定义主题的位置,而不是使用Theme.Holo
作为您的父级,请将其更改为使用一个来自ActionBarSherlock
的主题:
那应该解决你的问题。
答案 1 :(得分:0)
为什么你使用动作栏sherlock?您可以直接使用actionbaractivity。
http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html