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

  • Home
  • SEARCH
  • 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 8299259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:05:18+00:00 2026-06-08T16:05:18+00:00

I’m new to using HTTP, more over in Android. I am attempting/have to to

  • 0

I’m new to using HTTP, more over in Android. I am attempting/have to to authenticate a login sending the required information over HTTP Post using a JSON object.

When I run the app, I login using the login screen which asks for an install to be added into the access url, a username, and a password. I enter those in, hit the confirm button, and then the app crashes and a message comes up saying: “Unfortunately, TesterField has stopped.”

I cannot decipher what is being identified in the LOGCAT.

Will someone please tell me the reason behind this (run-time) error?

CODE:

package name.company.androidlogin;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginScreen extends Activity {

    private Button loginButton;
    private TextView resultText;
    private EditText usernameText;
    private EditText passwordText;
    private EditText installText;
    private String accessURL = "http://url";
    public final String CONSUMER_KEY = "KEY";
    public final String CONSUMER_SECRET = "SECRET";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_screen);

        loginButton = (Button) findViewById(R.id.btn_login);
        resultText = (TextView) findViewById(R.id.lbl_result);
        usernameText = (EditText) findViewById(R.id.txt_username);
        passwordText = (EditText) findViewById(R.id.txt_password);
        installText = (EditText) findViewById(R.id.txt_install);
        loginButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.login_screen, menu);
        return true;
    }
    public void sendJson()
    {
        JSONObject jOb;
        try {
            jOb = toJSON();
            HttpPost httpPost = new HttpPost(accessURL);
            StringEntity entity = new StringEntity(jOb.toString(), HTTP.UTF_8);
            entity.setContentType("application/json");
            httpPost.setEntity(entity);
            HttpClient client = new DefaultHttpClient();
            HttpResponse response = client.execute(httpPost);
            resultText.setText(response.getStatusLine().getStatusCode()+" "+response.getStatusLine().getReasonPhrase());
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public JSONObject toJSON() throws JSONException {
        JSONObject credentials = new JSONObject();
        try {
            credentials.put("ConsumerSecret", CONSUMER_SECRET);
            credentials.put("ConsumerKey", CONSUMER_KEY);
            credentials.put("Password", passwordText.getText());
            credentials.put("Username", usernameText.getText());
        } finally {
            resultText.setText(credentials.toString(2));
        }
        return credentials;
    }
}

LOG CAT:

07-16 13:55:50.834: I/ActivityManager(93): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=name.company.testerfield/.URLBuilder bnds=[120,402][240,552]} from pid 192
07-16 13:55:50.834: W/WindowManager(93): Failure taking screenshot for (180x300) to layer 21005
07-16 13:55:50.954: D/dalvikvm(1122): Not late-enabling CheckJNI (already on)
07-16 13:55:50.997: I/ActivityManager(93): Start proc name.company.testerfield for activity name.company.testerfield/.URLBuilder: pid=1122 uid=10040 gids={3003}
07-16 13:55:51.134: I/WindowManager(93): createSurface Window{415d4950 Starting name.company.testerfield paused=false}: DRAW NOW PENDING
07-16 13:55:51.474: W/NetworkManagementSocketTagger(93): setKernelCountSet(10040, 1) failed with errno -2
07-16 13:55:52.474: I/WindowManager(93): createSurface Window{41620b70 name.company.testerfield/name.company.testerfield.URLBuilder paused=false}: DRAW NOW PENDING
07-16 13:55:52.604: D/gralloc_goldfish(1122): Emulator without GPU emulation detected.
07-16 13:55:52.704: I/ActivityManager(93): Displayed name.company.testerfield/.URLBuilder: +1s788ms
07-16 13:55:52.974: W/NetworkManagementSocketTagger(93): setKernelCountSet(10005, 0) failed with errno -2
07-16 13:55:55.054: I/WindowManager(93): createSurface Window{415cdbe0 InputMethod paused=false}: DRAW NOW PENDING
07-16 13:55:56.084: D/dalvikvm(147): GC_CONCURRENT freed 306K, 35% free 10784K/16455K, paused 6ms+8ms
07-16 13:56:09.504: D/dalvikvm(93): GC_CONCURRENT freed 483K, 10% free 12354K/13639K, paused 6ms+33ms
07-16 13:56:13.364: D/dalvikvm(376): GC_CONCURRENT freed 499K, 6% free 11433K/12039K, paused 6ms+27ms
07-16 13:56:17.134: D/AndroidRuntime(1122): Shutting down VM
07-16 13:56:17.134: W/dalvikvm(1122): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
07-16 13:56:17.164: E/AndroidRuntime(1122): FATAL EXCEPTION: main
07-16 13:56:17.164: E/AndroidRuntime(1122): java.lang.NullPointerException
07-16 13:56:17.164: E/AndroidRuntime(1122):     at java.net.URI.parseURI(URI.java:353)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at java.net.URI.<init>(URI.java:204)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at java.net.URI.create(URI.java:725)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at org.apache.http.client.methods.HttpPost.<init>(HttpPost.java:79)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at name.company.testerfield.URLBuilder.postLoginData(URLBuilder.java:57)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at name.company.testerfield.URLBuilder.onClick(URLBuilder.java:50)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at android.view.View.performClick(View.java:3480)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at android.view.View$PerformClick.run(View.java:13983)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at android.os.Handler.handleCallback(Handler.java:605)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at android.os.Looper.loop(Looper.java:137)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at android.app.ActivityThread.main(ActivityThread.java:4340)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at java.lang.reflect.Method.invokeNative(Native Method)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at java.lang.reflect.Method.invoke(Method.java:511)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-16 13:56:17.164: E/AndroidRuntime(1122):     at dalvik.system.NativeStart.main(Native Method)
07-16 13:56:17.204: W/ActivityManager(93):   Force finishing activity name.company.testerfield/.URLBuilder
07-16 13:56:17.204: W/WindowManager(93): Failure taking screenshot for (180x300) to layer 21010
07-16 13:56:17.344: I/WindowManager(93): createSurface Window{41642a88  paused=false}: DRAW NOW PENDING
07-16 13:56:17.724: W/ActivityManager(93): Activity pause timeout for ActivityRecord{4133b488 name.company.testerfield/.URLBuilder}
07-16 13:56:17.743: W/NetworkManagementSocketTagger(93): setKernelCountSet(10005, 1) failed with errno -2
07-16 13:56:17.814: I/WindowManager(93): createSurface Window{41622c28 com.android.launcher/com.android.launcher2.Launcher paused=false}: DRAW NOW PENDING
07-16 13:56:18.694: W/NetworkManagementSocketTagger(93): setKernelCountSet(10040, 0) failed with errno -2
07-16 13:56:28.634: W/ActivityManager(93): Activity destroy timeout for ActivityRecord{4133b488 name.company.testerfield/.URLBuilder}

EDIT:
I should mention some other requirements:
– set the content type as “application/json; charset=utf-8″
– will be receiving a cookie as part of the response

THANKS

  • 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-08T16:05:19+00:00Added an answer on June 8, 2026 at 4:05 pm

    The error was from attempting to connect to the internet on the main thread. I used AsyncTask to carry out connecting to the internet in the background on a different thread.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a view passing on information from a database: def serve_article(request, id): served_article
I have thousands of HTML files to process using Groovy/Java and I need to
I have a jquery bug and I've been looking for hours now, I can't
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 just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

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.