Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8094907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:56:39+00:00 2026-06-05T20:56:39+00:00

I have a app with 2 tabbed activities, and I’m trying to get SharedPreferences

  • 0

I have a app with 2 tabbed activities, and I’m trying to get SharedPreferences on the second tab by using this code:
SharedPreferences prefs = this.getSharedPreferences("com.some.app", Context.MODE_PRIVATE);
But it makes the app force close, I use the same code on the first activity and it gets the SharedPreferences just fine! Any ideas what causing this?

Logcat:

06-19 17:10:37.690: W/dalvikvm(6589): threadid=1: thread exiting with uncaught exception (group=0x40a031f8)
06-19 17:10:37.706: E/AndroidRuntime(6589): FATAL EXCEPTION: main
06-19 17:10:37.706: E/AndroidRuntime(6589): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.something.some/com.something.somehow}: java.lang.NullPointerException
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:1797)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.widget.TabHost.setCurrentTab(TabHost.java:346)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:150)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:540)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.view.View.performClick(View.java:3511)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.view.View$PerformClick.run(View.java:14105)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.os.Handler.handleCallback(Handler.java:605)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.os.Looper.loop(Looper.java:137)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.ActivityThread.main(ActivityThread.java:4424)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at java.lang.reflect.Method.invokeNative(Native Method)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at java.lang.reflect.Method.invoke(Method.java:511)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at dalvik.system.NativeStart.main(Native Method)
06-19 17:10:37.706: E/AndroidRuntime(6589): Caused by: java.lang.NullPointerException
06-19 17:10:37.706: E/AndroidRuntime(6589):     at com.someone.someapp.Statify.onCreate(Statify.java:59)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.Activity.performCreate(Activity.java:4465)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-19 17:10:37.706: E/AndroidRuntime(6589):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-19 17:10:37.706: E/AndroidRuntime(6589):     ... 18 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:56:41+00:00Added an answer on June 5, 2026 at 8:56 pm

    Tab Host houses seperate activites(if im not mistaken) so when you call “this” it is returning the context of the tab activity, why it null i am not sure(i am assuming this is null because idk what is on line 59).

    My recommendation would be to use one shared preferences instance from your main activity instead of initiating a shared preference variable for each sub activity(Even though they would point to the same prefs)

    Or better yet use a ViewPager instead of the outdated Tab Host.

    If you want to stick with what you are doing try this.getBaseContext().getSharedPreferences()

    More contextual information would allow for a better answer as your smippit is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an tabbed App using UITabBarController . There are 2 tabs, linked to
I have an app with 2 tabbed view, I wish to execute some code
I'm making a tabbed view application and using CloudMade's API. I have a working
This is my first tabbed application for Android. I walked through the HelloTabWidget app
I am creating an app that is using a tabbed view. I currently am
Hi I'm setting up an android app and I'm using a tabbed interface. I'd
I have an app using a UITabBarController, and I have another view that needs
So, I have an iOS tabbed app (live and free in the store [
My app has 3 categories of buttons, I want to have a tabbed panel
In my Android app, I have a tabbed Activity . In one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.