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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:41:27+00:00 2026-05-21T23:41:27+00:00

I’m trying to use AsyncTask to connect to a web service. When I launch

  • 0

I’m trying to use AsyncTask to connect to a web service. When I launch the app it closes unexpectedly. What am I doing wrong? Here’s my code:

public class Main extends Activity {
    private static final String CONSUMER_KEY = "dsfjfsdksfdjl322342";
    private static final String CONSUMER_SECRET = "fwefer234242424";
    private TextView mText;
    ProgressDialog progress = null;
    TextView mTextView = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mTextView = (TextView)findViewById(R.id.textView);
        //new ConnectThinkNearTask().execute();
        new ConnectToThinkSomeAPITask().execute("http://api-someapi.api.com/1.0/offers/40.7144,-74.0060.json");
    }

    private class ConnectToSomeAPITask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String...urls) {
            String response = "";
            for(String url: urls) {
                OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY,
                        CONSUMER_SECRET);
                consumer.setTokenWithSecret("", "");

                try {
                    URL url1 = new URL(url);
                    HttpURLConnection request = (HttpURLConnection) url1.openConnection();


                    // sign the request
                    consumer.sign(request);

                    // send the request
                    request.connect();

                    if(request.getResponseCode()==200) {
                        response = "Sorry, failed to connect to x";
                        //                  mText.setText("Sorry, failed to connect to x");
                        //              } else if(request.getResponseCode()==401) {
                        response = "Congrats, you're connected to x!";
                        //mText.setText("Congrats, you're connected to x!");
                    } else
                        response = "Whatever you're asking for, it ain't a valid HTTP request...";
                    //                  mText.setText("Whatever you're asking for, it ain't a valid HTTP request...");
                } catch (Exception e) {
                    e.printStackTrace();

                } 
            } return response;

        }

        @Override
        protected void onPostExecute(String result) {
            mTextView.setText(result);
        }
    }       

}

And here’s the log:

 05-09 21:34:00.219: ERROR/AndroidRuntime(29878): FATAL EXCEPTION: AsyncTask #1
05-09 21:34:00.219: ERROR/AndroidRuntime(29878): java.lang.RuntimeException: An error occured while executing doInBackground()
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.lang.Thread.run(Thread.java:1096)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878): Caused by: java.lang.NoClassDefFoundError: oauth.signpost.basic.DefaultOAuthConsumer
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at org.androidstack.thinknear.Main$ConnectToThinkNearTask.doInBackground(Main.java:45)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at org.androidstack.thinknear.Main$ConnectToThinkNearTask.doInBackground(Main.java:1)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-09 21:34:00.219: ERROR/AndroidRuntime(29878):     ... 4 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-05-21T23:41:28+00:00Added an answer on May 21, 2026 at 11:41 pm

    Ok, well the logcat was helpful. This happens to me a lot, when I just add libraries to the build path by configuring the build path by selecting user libraries. For some reason, I need to always created a folder called libs in my project, then add the jars and click to add to build path. It’s working now!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.