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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:54:02+00:00 2026-05-16T08:54:02+00:00

I am new to Android development since my EVO purchase a few months ago.

  • 0

I am new to Android development since my EVO purchase a few months ago.

Anyway, I am developing my first Android app using Eclipse and Android SDK emulator.

I am trying to do a simple HTTP POST. My real code has my login information hard coded in so I replaced it with test information and I changed the url as well to simply POST to google.com.

I am getting a NullPointerException when trying to view the HTTP POST request response.

I have added the internet permissions to my manifest xml file as well.

Here is my code.

editted

Thanks in advance

::updated::

I have initialized the txtResult TextView object and I am getting new NullPointerException.


package com.dougi.TexAgsPremiumWidget;

import java.io.IOException;
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.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TexAgsPremiumWidget extends Activity {

    LinearLayout layout = new LinearLayout(this);;
    TextView txtResult = new TextView(this);
    ProgressDialog pDialog;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        login();

        layout.addView(txtResult);
        setContentView(layout);

        pDialog = ProgressDialog.show(this, "Loading", "please wait...", true);
    }

    public void login()
    {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.google.com");

        try
        {
            List nameValuePairs = new ArrayList(2);
            nameValuePairs.add(new BasicNameValuePair("username", "test"));
            nameValuePairs.add(new BasicNameValuePair("password", "test"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            txtResult.setText(HttpHelper.request(response));
        } 

        catch (ClientProtocolException e)
        {
            Log.i("httpClientProtocolException", e.toString());
        }

        catch (IOException e)
        {
            Log.i("httpClientIOException", e.toString());
        }
    }
}

here is my new logcat error log


08-22 20:57:40.153: ERROR/AndroidRuntime(960): ERROR: thread attach failed
08-22 20:57:40.883: ERROR/AndroidRuntime(966): Uncaught handler: thread main exiting due to uncaught exception
08-22 20:57:40.923: ERROR/AndroidRuntime(966): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dougi.TexAgsPremiumWidget/com.dougi.TexAgsPremiumWidget.TexAgsPremiumWidget}: java.lang.NullPointerException
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.os.Looper.loop(Looper.java:123)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.app.ActivityThread.main(ActivityThread.java:4363)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at java.lang.reflect.Method.invokeNative(Native Method)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at java.lang.reflect.Method.invoke(Method.java:521)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at dalvik.system.NativeStart.main(Native Method)
08-22 20:57:40.923: ERROR/AndroidRuntime(966): Caused by: java.lang.NullPointerException
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.view.View.(View.java:1777)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.view.ViewGroup.(ViewGroup.java:279)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.widget.LinearLayout.(LinearLayout.java:88)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at com.dougi.TexAgsPremiumWidget.TexAgsPremiumWidget.(TexAgsPremiumWidget.java:25)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at java.lang.Class.newInstanceImpl(Native Method)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at java.lang.Class.newInstance(Class.java:1479)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
08-22 20:57:40.923: ERROR/AndroidRuntime(966):     ... 11 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-16T08:54:03+00:00Added an answer on May 16, 2026 at 8:54 am

    There could be too many reasons for that, and if you don’t tell us which line is the number 60 we are not going to be able to help you. Anyway… so far I see a clear NullpointerException case: you first call login() and after that you initialize txtResult

    login();
    layout =  new LinearLayout(this);
    txtResult = new TextView(this);
    

    That of course will cause a NullPointerException because inside login() you are doing:

    txtResult.setText(HttpHelper.request(response));
    

    In that case, txtResult have not been initialized, thus it’s null.

    Edit:

    Sigh… doing TextView txtResult = new TextView(this); outside any method will cause another NullPointerException. That’s because the use of this. You better read little bit more about what it means, but let me give you a simple explanation: this is a keyword used to reference an instance of the object current object. Every initialization you do that is not inside a method will be called before the constructor is invoked (that’s called lazy initialization), thus in that case the object has not been instantiated and this will be null.

    What you have to do, and I thought you were going to get the idea is:

    layout =  new LinearLayout(this);
    txtResult = new TextView(this);
    login();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey, im new to android development and trying to make my first application. What
I'm new to Eclipse/Android development so I'm hoping this is something basic that I'm
I'm new to Android application development and I'm currently experimenting with various UI ideas.
I'm new to Android development and I'm currently going through some tutorials. When I
I am new for android development. I am trying read and write contacts to
I was reading over at the Android development website about using reflections. But I'm
I'm quite new to Android development. When is it a good idea to create
I am new to Android development and have been following the tutorials available on
I am new to android development and am currently working my way through the
I'm pretty new to Android development, but I have some experience with Java and

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.