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 6604699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:11:30+00:00 2026-05-25T19:11:30+00:00

I have build 2 projects my main one and a twitter posting one. I

  • 0

I have build 2 projects my main one and a twitter posting one. I have imported the twitter one into the main and am now trying to hook it up. Below is the import code. The problem is I know I am missing something possibly to do with the context? I have just summarised what is contained in my main project below so you understand better (Hopefully).

import com.tweet.t.TweetToTwitterActivity;

            TweetToTwitterActivity twitter = new TweetToTwitterActivity();
            twitter.buttonLogin(v);

Here is the TweetToTwitterActivity

public class TweetToTwitterActivity extends Activity {

    private SharedPreferences mPrefs;
    /** Twitter4j object */
    private Twitter mTwitter;
    private RequestToken mReqToken;

    public void buttonLogin(View v) {
        mPrefs = getSharedPreferences("twitterPrefs", MODE_PRIVATE);
        // Load the twitter4j helper
        mTwitter = new TwitterFactory().getInstance();

        // Tell twitter4j that we want to use it with our app
        mTwitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
        if (mPrefs.contains(PREF_ACCESS_TOKEN)) {
            Log.i(TAG, "Repeat User");
            loginAuthorisedUser();
        } else {
            Log.i(TAG, "New User");
            loginNewUser();
        }
    }

The Logcat produces this error

09-23 11:27:40.034: ERROR/AndroidRuntime(229): java.lang.NullPointerException
09-23 11:27:40.034: ERROR/AndroidRuntime(229):     at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
09-23 11:27:40.034: ERROR/AndroidRuntime(229):     at com.tweet.t.TweetToTwitterActivity.buttonLogin(TweetToTwitterActivity.java:74)

and point to this line.

    mPrefs = getSharedPreferences("twitterPrefs", MODE_PRIVATE);
  • 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-05-25T19:11:31+00:00Added an answer on May 25, 2026 at 7:11 pm

    getSharedPreferences() is a method of the Context class. You are just creating an instance of TweetToTwitterActivity which extends Activity but this activity is not presently started.
    One way to solve this will be to pass a Context object also to buttonLogin:

    Change public void buttonLogin(View v)

    to public void buttonLogin(View v, Context context)

    and mPrefs = getSharedPreferences("twitterPrefs", MODE_PRIVATE);

    to mPrefs = context.getSharedPreferences("twitterPrefs", MODE_PRIVATE);

    and twitter.buttonLogin(v);

    to twitter.buttonLogin(v, this);

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

Sidebar

Related Questions

I have a CruiseControl build server running a large number of projects. On one
i have 2 android projects in eclipse, one is the main application, the other
I have a build file in my Eclipse projects. One of the things this
We have several independent builds (each independent build is a multi-project build). The main
We have just setup our hudson server to build .NET projects which seems to
I have a build server running CruiseControl.NET. It works well for the 7 projects
I have a bunch of ant projects that build plug-ins that all conform to
Does anyone have a good way to build MSI (vdproj) projects using MsBuild or
I have projects that need to be build with a specific version of the
I have a solution with several projects, where the startup project has a post-build

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.