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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:24:50+00:00 2026-05-30T07:24:50+00:00

I have this class: package com.problemio; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList;

  • 0

I have this class:

package com.problemio;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
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.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends Activity 
{
    private TextView textView;

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        // Show form for login_email
        final EditText loginEmail = (EditText) findViewById(R.id.login_email);  
        String name = loginEmail.getText().toString();  

        // Show field for password  
        final EditText password = (EditText) findViewById(R.id.password);  
        String text = password.getText().toString();                  

        // Show button for submit
        Button submit = (Button)findViewById(R.id.submit);   




        // Show options for create-profile and forgot-password

        //readWebpage( R.layout.login) ;


        submit.setOnClickListener(new Button.OnClickListener() 
        {  
           public void onClick(View v) 
           {
              String email = loginEmail.getText().toString();
              String pass = password.getText().toString(); 
              sendFeedback(pass, email);
            }
        });        
    }


    public void sendFeedback(String pass , String email) 
    {  
        Log.d( "1" , pass );
        Log.d( "1" , email );

        String[] params = new String[] { "myurl", email, pass };

        DownloadWebPageTask task = new DownloadWebPageTask();
        task.execute(params);        

        Log.d( "2" , "After task.execute call" );

    }          



    private class DownloadWebPageTask extends AsyncTask<String, Void, String> 
    {
        @Override
        protected String doInBackground(String... theParams) 
        {
            Log.d( "Inner class: " , "Doing stuff in background" );

            String myUrl = theParams[0];
            String myEmail = theParams[1];
            String myPassword = theParams[2];

            Log.d( "Inner myURL: " , myUrl );
            Log.d( "myEmail: " , myEmail );
            Log.d( "myPass: " , myPassword );

            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();  
            postParameters.add(new BasicNameValuePair("username", myEmail ));  
            postParameters.add(new BasicNameValuePair("password", myPassword ));            

            String response = "";

            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(myUrl);

            try 
            {
                    HttpResponse execute = client.execute(httpGet);
                    InputStream content = execute.getEntity().getContent();

                    BufferedReader buffer = new BufferedReader(
                            new InputStreamReader(content));
                    String s = "";
                    while ((s = buffer.readLine()) != null) 
                    {
                        response += s;
                    }

                    Log.d( "After call, response: " , " " + response);
                } 
                catch (Exception e) 
                {
                    Log.d( "Exception: " , "Yup");
                    e.printStackTrace();
                }

            return response;
        }


        @Override
        protected void onPostExecute(String result) 
        {
            Log.d( "Post execute: " , "In the post-execute method" );
            textView.setText(result);
        }    
    }

        public void readWebpage(View view) 
        {
            Log.d( "Read webpage: " , "In the read webpage method" );
            DownloadWebPageTask task = new DownloadWebPageTask();
            task.execute(new String[] { "myurl" });
        }       
}

and when I call it, it does run, hit the remote server and pick up whatever that server outputs. So that is no problem.

The problem is that it creates this NullPointerException after the call is made and the response from the server is returned:

02-23 17:01:44.607: E/AndroidRuntime(2018): FATAL EXCEPTION: main
02-23 17:01:44.607: E/AndroidRuntime(2018): java.lang.NullPointerException
02-23 17:01:44.607: E/AndroidRuntime(2018):     at com.problemio.LoginActivity$DownloadWebPageTask.onPostExecute(LoginActivity.java:137)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at com.problemio.LoginActivity$DownloadWebPageTask.onPostExecute(LoginActivity.java:1)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at android.os.AsyncTask.finish(AsyncTask.java:602)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at android.os.AsyncTask.access$600(AsyncTask.java:156)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at android.os.Looper.loop(Looper.java:137)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at android.app.ActivityThread.main(ActivityThread.java:4424)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at java.lang.reflect.Method.invokeNative(Native Method)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at java.lang.reflect.Method.invoke(Method.java:511)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-23 17:01:44.607: E/AndroidRuntime(2018):     at dalvik.system.NativeStart.main(Native Method)

Also, what is the most proper thing to do after getting the return call? Should I just make an intent and go to a different Activity screen?

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-05-30T07:24:52+00:00Added an answer on May 30, 2026 at 7:24 am

    textView.setText(result); in onPostExecute method, the textview never init.

    if you want to notify another activity, you can set data in intent to call another activity, or send broadcast.

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

Sidebar

Related Questions

I have this code: package com.problemio; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList;
Okay so, I have this project structure: package A.B class SuperClass (this class is
I have a base class like this: package MyClass; use vars qw/$ME list of
I have this class called Table: class Table { public string Name { get
I have this class. public class Foo { public Guid Id { get; set;
i have this class called MemoryManager, it is supposed to implement a simple smart
I have this class: class View(object): def main_page(self, extra_placeholders = None): file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl'
I have this class: public static class CsvWriter { private static StreamWriter _writer =
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =

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.