Android ActionBar NullPointerException - android

I want to enable the Android ActionBar, however it doesn't work for me.
Here is my MainActivity:
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
ActionBar actionBar = getActionBar();
actionBar.show();
//more code............
and here is the logcat:
03-04 16:31:09.423: E/AndroidRuntime(1441): FATAL EXCEPTION: main
03-04 16:31:09.423: E/AndroidRuntime(1441): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.salebook/com.example.salebook.MainActivity}: java.lang.NullPointerException
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.os.Looper.loop(Looper.java:137)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 16:31:09.423: E/AndroidRuntime(1441): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 16:31:09.423: E/AndroidRuntime(1441): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 16:31:09.423: E/AndroidRuntime(1441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 16:31:09.423: E/AndroidRuntime(1441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 16:31:09.423: E/AndroidRuntime(1441): at dalvik.system.NativeStart.main(Native Method)
03-04 16:31:09.423: E/AndroidRuntime(1441): Caused by: java.lang.NullPointerException
03-04 16:31:09.423: E/AndroidRuntime(1441): at com.example.salebook.MainActivity.onCreate(MainActivity.java:130)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.Activity.performCreate(Activity.java:5104)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 16:31:09.423: E/AndroidRuntime(1441): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 16:31:09.423: E/AndroidRuntime(1441): ... 11 more
Where line 130 is anctionBar.show() and I have in res/menu/menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/itemid_0"
android:title="Action Item 0"
android:icon="#drawable/ic_launcher"
android:orderInCategory="0"
android:showAsAction="ifRoom|withText" />
<item android:id="#+id/itemid_1"
android:title="Action Item 1"
android:orderInCategory="0" />
<item android:id="#+id/itemid_2"
android:title="Action Item 2"
android:orderInCategory="0" />
<item android:id="#+id/itemid_3"
android:title="Action Item 3"
android:orderInCategory="0" />
</menu>
I didn't find the problem. Hope someone help me.
Thanks.
Also,in the appThem style:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowActionBar">true</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

You Actionbar returns null because you don't have actionbar but you are requesting using getActionbar()
Make sure that you've window feature to show your actionbar, That is required for the actionbar to show. Check the below links for more details.
...check this question getActionBar returns null And also check this link for the more information on your problem http://blog.perpetumdesign.com/2011/08/strange-case-of-dr-action-and-mr-bar.html

You Remove
android:theme="#style/AppTheme"
in "application" from AndroidManifest.xml

Do you actually see an actionbar if you remove the line actionBar.show()?
If not, it could be related to your theme, e.g. Theme.Light.NoActionBar.

go to the AndroidManifest.xml and replace
android:theme="#style/AppTheme"
by
android:theme="#android:style/Theme.Holo.Light.DarkActionBar"

Related

Why I can't start a new activity?

Whenever I tried to click the button it stops working.
Here are the logs:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blogspot.hlowrold.mybooks/com.blogspot.hlowrold.mybooks.Main2Activity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:356)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:325)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.blogspot.hlowrold.mybooks.Main2Activity.onCreate(Main2Activity.java:13)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
What is the problem here? Please help me.
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
example
styles.xml:
<style name="ThemeCompatLight" parent="Theme.AppCompat.Light.NoActionBar">
</style>
AndroidManifest.xml
<activity
android:name=".your.activity.name"
android:theme="#style/ThemeCompatLight" />
make your style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
you need add appcompat lib to build.gradle
compile 'com.android.support:appcompat-v7:25.3.1'
and add theme in styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>
and in manifest file, peresent activity this way
<activity
android:name="YOUR_ACTIVITY"
android:theme="#style/AppTheme" />

android how change background action bar

Hi i would change my actionbar background color. I've found a lot of tutorial but when i launch my app it crashes giving me error message.
This is what i've done.
AndroidManifest.xml:
<activity
android:name=".UserActivity"
android:label="#string/app_name"
android:parentActivityName="com.example.securepassword.MainActivity"
android:theme="#style/MyTheme" >
<intent-filter>
<action android:name="user" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AddItemActivity"
android:label="#string/app_name"
android:parentActivityName="com.example.securepassword.UserActivity"
android:theme="#style/MyTheme" >
<intent-filter>
<action android:name="add_item" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
UserActivity and AddItemActivity are the activities where actionbar appears.
I have created my personal style in /res/values-v11/styles.xml
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#0086D4</item>
</style>
when i start UserActivity my app crashes giving me this error:
01-10 12:53:08.337: E/AndroidRuntime(15095): FATAL EXCEPTION: main
01-10 12:53:08.337: E/AndroidRuntime(15095): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.securepassword/com.example.securepassword.UserActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.os.Looper.loop(Looper.java:137)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-10 12:53:08.337: E/AndroidRuntime(15095): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 12:53:08.337: E/AndroidRuntime(15095): at java.lang.reflect.Method.invoke(Method.java:525)
01-10 12:53:08.337: E/AndroidRuntime(15095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-10 12:53:08.337: E/AndroidRuntime(15095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-10 12:53:08.337: E/AndroidRuntime(15095): at dalvik.system.NativeStart.main(Native Method)
01-10 12:53:08.337: E/AndroidRuntime(15095): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
01-10 12:53:08.337: E/AndroidRuntime(15095): at com.example.securepassword.UserActivity.onCreate(UserActivity.java:17)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.Activity.performCreate(Activity.java:5133)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-10 12:53:08.337: E/AndroidRuntime(15095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-10 12:53:08.337: E/AndroidRuntime(15095): ... 11 more
The problem appears when in androidmanifest i use MyTheme like style for both activities..what's wrong?
You have answer in exception message
You need to use a Theme.AppCompat theme (or descendant) with this activity.
Use Theme.AppCompat.
Additionally you can use toolbar to customize you action bar
You can add it in layout xml such as standard view and set it in your activity by setSupportActionBar(toolbarObject) method as is shown below
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="5dp"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<!-- your layout -->
</LinearLayout>
YourActivty.class
public class YourActivty extends ActionBarActivity {
Toolbar mToolbar;
public void onCreate(Bundle savedInstanceState) {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
// configure toolbar stuff
setSupportActionBar(mToolbar);
}
}
But when you want to use toolbar. You have to use Theme.AppCompat.NoActionBar theme
you can try using code in your Activity like this:
ActionBar ab = getActionBar();
ab.setHomeButtonEnabled(true);
ColorDrawable colorDrawable = new ColorDrawable(
Color.parseColor("#0086D4"));
ab.setBackgroundDrawable(colorDrawable);
To change the color of text on ActionBar use this:
ab.setTitle(Html.fromHtml("<font color='#YOUR_COLORCODE'>ActionBarTitle </font>"));
OR
int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
if (actionBarTitleId > 0) {
TextView title = (TextView) findViewById(actionBarTitleId);
if (title != null) {
title.setTextColor(YOUR COLOR );
}
}
Change the inheritance of your main activity to Activity (import android.app.Activity) , i think it solves the problem with using custom theme

PreferenceFragment compile but my program doesn't work . What is the matter ? Exception code is here

03-04 11:09:41.524: E/AndroidRuntime(943): FATAL EXCEPTION: main
03-04 11:09:41.524: E/AndroidRuntime(943): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.otobusumnerede/com.otobusumnerede.AyarlarActivity}: java.lang.NullPointerException
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.os.Looper.loop(Looper.java:137)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 11:09:41.524: E/AndroidRuntime(943): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 11:09:41.524: E/AndroidRuntime(943): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 11:09:41.524: E/AndroidRuntime(943): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 11:09:41.524: E/AndroidRuntime(943): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 11:09:41.524: E/AndroidRuntime(943): at dalvik.system.NativeStart.main(Native Method)
03-04 11:09:41.524: E/AndroidRuntime(943): Caused by: java.lang.NullPointerException
03-04 11:09:41.524: E/AndroidRuntime(943): at com.otobusumnerede.AyarlarActivity.onCreate(AyarlarActivity.java:24)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.Activity.performCreate(Activity.java:5104)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 11:09:41.524: E/AndroidRuntime(943): ... 11 more
03-04 11:24:14.452: E/Trace(1311): error opening trace file: No such file or directory (2)
03-04 11:24:44.843: E/AndroidRuntime(1311): FATAL EXCEPTION: main
03-04 11:24:44.843: E/AndroidRuntime(1311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.otobusumnerede/com.otobusumnerede.AyarlarActivity}: java.lang.NullPointerException
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.os.Looper.loop(Looper.java:137)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 11:24:44.843: E/AndroidRuntime(1311): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 11:24:44.843: E/AndroidRuntime(1311): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 11:24:44.843: E/AndroidRuntime(1311): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 11:24:44.843: E/AndroidRuntime(1311): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 11:24:44.843: E/AndroidRuntime(1311): at dalvik.system.NativeStart.main(Native Method)
03-04 11:24:44.843: E/AndroidRuntime(1311): Caused by: java.lang.NullPointerException
03-04 11:24:44.843: E/AndroidRuntime(1311): at com.otobusumnerede.AyarlarActivity.onCreate(AyarlarActivity.java:25)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.Activity.performCreate(Activity.java:5104)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 11:24:44.843: E/AndroidRuntime(1311): ... 11 more
If you can copy text from your activity and paste it, or atleast paste line no.25 of your code, its easier to help you.
Going by as it is so early in your activity, check onCreate() first
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayoutxml);
imageView = (ImageView) findViewById(R.id.yourimageviewid); //just an example
make sure to call setContentView() before any findViewById
check if you have declared, initialized your variables properly
if so, look for a value that could be null

Illegal State Exception: Custom Dialog

I have created a custom dialog layout. When invoked, the dialog pops up fine. But when I try to set the content inside the dialog using the two lines commented below, it throws an illegal state exception.
private void showCustomDialog(String content){
final Dialog d = new Dialog(this);
d.setContentView(R.layout.spread_info_popup);
d.show();
// TextView contentTv = (TextView) findViewById(R.id.my_dialog_content);
// contentTv.setText(content);
}
What is wrong here ?
Do i need to inflate the layout spread_info_popup before referring to TextView within it with an id of my_dialog_content ?
the Stacktrace:
03-04 15:03:54.690: E/AndroidRuntime(4194): FATAL EXCEPTION: main
03-04 15:03:54.690: E/AndroidRuntime(4194): java.lang.IllegalStateException: Could not execute method of the activity
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.view.View$1.onClick(View.java:3591)
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.view.View.performClick(View.java:4084)
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.view.View$PerformClick.run(View.java:16966)
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.os.Handler.handleCallback(Handler.java:615)
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.os.Handler.dispatchMessage(Handler.java:92)
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.os.Looper.loop(Looper.java:137)
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-04 15:03:54.690: E/AndroidRuntime(4194): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 15:03:54.690: E/AndroidRuntime(4194): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 15:03:54.690: E/AndroidRuntime(4194): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-04 15:03:54.690: E/AndroidRuntime(4194): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-04 15:03:54.690: E/AndroidRuntime(4194): at dalvik.system.NativeStart.main(Native Method)
03-04 15:03:54.690: E/AndroidRuntime(4194): Caused by: java.lang.reflect.InvocationTargetException
03-04 15:03:54.690: E/AndroidRuntime(4194): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 15:03:54.690: E/AndroidRuntime(4194): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 15:03:54.690: E/AndroidRuntime(4194): at android.view.View$1.onClick(View.java:3586)
03-04 15:03:54.690: E/AndroidRuntime(4194): ... 11 more
03-04 15:03:54.690: E/AndroidRuntime(4194): Caused by: java.lang.NullPointerException
03-04 15:03:54.690: E/AndroidRuntime(4194): at com.me.reader.ui.activity.CompleteList.showSpreadInfoPopup(CompleteList.java:122)
03-04 15:03:54.690: E/AndroidRuntime(4194): at com.me.reader.ui.activity.CompleteList.setSpreadDescriptionfromXML(CompleteList.java:104)
03-04 15:03:54.690: E/AndroidRuntime(4194): at com.me.reader.ui.activity.CompleteList.onAboutIconClicked(CompleteList.java:81)
03-04 15:03:54.690: E/AndroidRuntime(4194): ... 14 more
you should look for the view inside the Dialog:
TextView contentTv = (TextView) dialog.findViewById(R.id.my_dialog_content);
contentTv.setText(content);
here the documentation.

Spinner on an ActionBar issue on a Dialog Activity

Hi I have an activity that shows a dialog form an standard layout.
android:theme="#android:style/Theme.Holo.Light.Dialog"/>
I was trying to add a simple spinner to the actionbar but I am having issues and error in the line getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST).
When I change my theme to a common activity it works perfect.
This are the errors showed by the logcat:
3114-3114/org.PeteProto E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.PeteProto/org.PeteProto.Detail}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.PeteProto.Detail.onCreate(Detail.java:30)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more

Categories

Resources