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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:59:05+00:00 2026-06-11T01:59:05+00:00

i have some problem, i want to make my application OAuth with twitter account

  • 0

i have some problem, i want to make my application OAuth with twitter account

This is my Main.xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <ImageButton
        android:id="@+id/btnTwitterConnect"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:background="@drawable/standard_twitter"
        android:contentDescription="@string/twitter_btn_description"
        android:gravity="center" />

</RelativeLayout>

And this is my Main.java File

package com.test.twitteroauth;

import oauth.signpost.OAuth;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;



public class MainActivity extends Activity {

    private static final String CONSUMER_KEY = "CONSUMER KEY GOES HERE";
    private static final String CONSUMER_SECRET = "CONSUMER SECRET GOES HERE";

    private static String ACCESS_KEY = null;
    private static String ACCESS_SECRET = null;


    private static final String REQUEST_URL = "http://twitter.com/oauth/request_token";
    private static final String ACCESS_TOKEN_URL = "http://twitter.com/oauth/access_token";
    private static final String AUTH_URL = "http://twitter.com/oauth/authorize";
    private static final String CALLBACK_URL = "OauthTwitter://twitt";
    private static final String PREFERENCE_FILE = "twitter_oauth.prefs";

    private static CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
    private static CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(REQUEST_URL, ACCESS_TOKEN_URL, AUTH_URL);


    @Override
    public void onCreate(Bundle savedInstanceState) {

        ImageButton btnTwitterConnect = (ImageButton) findViewById(R.id.btnTwitterConnect);
        btnTwitterConnect.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                try {
                     String authURL = provider.retrieveRequestToken(consumer, CALLBACK_URL);
                     Log.d("OAuthTwitter", authURL);
                     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL)));
                    } catch (OAuthMessageSignerException e) {
                        e.printStackTrace();
                    } catch (OAuthNotAuthorizedException e) {
                        e.printStackTrace();
                    } catch (OAuthExpectationFailedException e) {
                        e.printStackTrace();
                    } catch (OAuthCommunicationException e) {
                        e.printStackTrace();
                    }
            }
        });         
    }

        @Override
        public void onResume() {
            super.onResume();
        Uri uri = this.getIntent().getData();

        if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
            Log.d("OAuthTwitter", uri.toString());
        String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
            Log.d("OAuthTwitter", verifier);
        try {
        provider.retrieveAccessToken(consumer, verifier);
        ACCESS_KEY = consumer.getToken();
        ACCESS_SECRET = consumer.getTokenSecret();

        Log.d("OAuthTwitter", ACCESS_KEY);
        Log.d("OAuthTwitter", ACCESS_SECRET);

        } catch (OAuthMessageSignerException e) {
            e.printStackTrace();
        } catch (OAuthNotAuthorizedException e) {
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            e.printStackTrace();
        }
       }
      }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


}

I just followed the tutorial here: http://blog.copyninja.info/2010/09/android-oauth-authentication-with.html

But the android application is always Crashed

LogCat Details:

09-08 19:11:13.754: D/AndroidRuntime(566): Shutting down VM
09-08 19:11:13.754: W/dalvikvm(566): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-08 19:11:13.785: E/AndroidRuntime(566): FATAL EXCEPTION: main
09-08 19:11:13.785: E/AndroidRuntime(566): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.twitteroauth/com.test.twitteroauth.MainActivity}: java.lang.NullPointerException
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.os.Looper.loop(Looper.java:123)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-08 19:11:13.785: E/AndroidRuntime(566):  at java.lang.reflect.Method.invokeNative(Native Method)
09-08 19:11:13.785: E/AndroidRuntime(566):  at java.lang.reflect.Method.invoke(Method.java:521)
09-08 19:11:13.785: E/AndroidRuntime(566):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-08 19:11:13.785: E/AndroidRuntime(566):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-08 19:11:13.785: E/AndroidRuntime(566):  at dalvik.system.NativeStart.main(Native Method)
09-08 19:11:13.785: E/AndroidRuntime(566): Caused by: java.lang.NullPointerException
09-08 19:11:13.785: E/AndroidRuntime(566):  at com.test.twitteroauth.MainActivity.onCreate(MainActivity.java:44)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-08 19:11:13.785: E/AndroidRuntime(566):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-08 19:11:13.785: E/AndroidRuntime(566):  ... 11 more

I know it’s caused by java.Lang.NullPointerException but where is the errors?

Thank you

(Android 2.2, Eclipse 3.7, Java JDK 1.7)

  • 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-11T01:59:06+00:00Added an answer on June 11, 2026 at 1:59 am

    In addition to the setContentView(...), you should call super.onCreate(savedInstanceState); above it, otherwise you’ll end up with a SuperNotCalledException

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(...);
    
       // ...
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
I am new to .net and have this problem: I want to make installer
I have some problem. Dialog.dismiss() does not work. I want to input ip, username,
I want to persist my entity with ManyToMany relation. But i have some problem
I have some kind of problem with jQuery selectors. Let's say i want to
my problem is: I have an image and want to mark some areas over
I have some problem with this mongoid. It's my first time to use mongoDB,
Suppose I have some application A with a database. Now I want to add
In My application XML layout, I have one Relativelayout, In which there are two
I want to make a native Android application for a website. The first problem

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.