I am developing an application using the ABS library. In two fragments, you must use the custom view in the action bar. My code works fine in ICS and JB. But I'm testing the gingerbread and crashed.
My code is as follows:
public class SearchContactActivity extends SherlockFragmentActivity { private EditText searchField; private ImageButton searchButton; @Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.search_contacts); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); View view = actionBar.getCustomView();
My XML theme:
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="Theme.Styled.Search" parent="Theme.Sherlock.Light"> <item name="actionBarStyle">@style/Widget.Styled.ActionBar.Search</item> <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar.Search</item> </style> <style name="Widget.Styled.ActionBar.Search" parent="Widget.Sherlock.Light.ActionBar"> <item name="background">@drawable/bg_actionbar</item> <item name="android:background">@drawable/bg_actionbar</item> <item name="backgroundSplit">@drawable/bg_actionbar</item> <item name="android:backgroundSplit">@drawable/bg_actionbar</item> <item name="android:titleTextStyle">@style/NoTitleText</item> <item name="android:subtitleTextStyle">@style/NoTitleText</item> <item name="android:displayOptions">showHome|useLogo|showCustom</item> <item name="android:customNavigationLayout">@layout/custom_action</item> </style> </resources>
and my custom_view:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/editText_search" style="@style/Widget.Styled.EditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_toLeftOf="@+id/button_search" android:ems="10" android:hint="@string/hint_search" android:inputType="textNoSuggestions" android:layout_marginRight="5dp" /> <ImageButton android:id="@+id/button_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/editText_search" android:layout_alignTop="@+id/editText_search" android:layout_alignParentRight="true" android:layout_marginRight="5dp" android:background="@drawable/button_go_login_xml" android:paddingLeft="15dp" android:paddingRight="15dp" android:src="@drawable/lupa" /> </RelativeLayout>
My logarithm
10-18 18:03:34.259: E/AndroidRuntime(10576): FATAL EXCEPTION: main 10-18 18:03:34.259: E/AndroidRuntime(10576): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.co2fine.client/com.co2fine.client.SearchContactActivity}: java.lang.NullPointerException 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.os.Handler.dispatchMessage(Handler.java:99) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.os.Looper.loop(Looper.java:123) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.app.ActivityThread.main(ActivityThread.java:3729) 10-18 18:03:34.259: E/AndroidRuntime(10576): at java.lang.reflect.Method.invokeNative(Native Method) 10-18 18:03:34.259: E/AndroidRuntime(10576): at java.lang.reflect.Method.invoke(Method.java:507) 10-18 18:03:34.259: E/AndroidRuntime(10576): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874) 10-18 18:03:34.259: E/AndroidRuntime(10576): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632) 10-18 18:03:34.259: E/AndroidRuntime(10576): at dalvik.system.NativeStart.main(Native Method) 10-18 18:03:34.259: E/AndroidRuntime(10576): Caused by: java.lang.NullPointerException 10-18 18:03:34.259: E/AndroidRuntime(10576): at com.co2fine.client.SearchContactActivity.onCreate(SearchContactActivity.java:53) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 10-18 18:03:34.259: E/AndroidRuntime(10576): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 10-18 18:03:34.259: E/AndroidRuntime(10576): ... 11 more
source share