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

The Archive Base Latest Questions

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

I am a fairly beginner in Android Development. I am developing an application that

  • 0

I am a fairly beginner in Android Development. I am developing an application that extensively relays on Webservice calls. First screen takes username and password and validates the user by calling the Webservice. If U/P is valid, then I need to fire up the 2nd activity. In that 2nd activity, I need to do 3 calls. But I haven’t gotten to the 2nd part yet. In fact, I haven’t completed the full coding yet. But I wanted to test if the app is working as far as I’ve come through.

When calling webserivce, I am showing alert dialog. But the app is crashing somewhere.
The LoginActivity shows up. When I enter U/P and press Login Button, it crashes.

My classes:

TaskHandler.java

 public class TaskHandler {

private String URL;
private User userObj;
private String results;
private JSONDownloaderTask task; ;

public TaskHandler( String url, User user) {
    this.URL = url;
    this.userObj = user;
}

public String handleTask() {
    Log.d("Two", "In the function");
    task = new JSONDownloaderTask();
    Log.d("Three", "In the function");
    task.execute(URL);
    return results;
}

private class JSONDownloaderTask extends AsyncTask<String, Void, String> {

    private String username;// = userObj.getUsername();
    private String password; //= userObj.getPassword();

    public  HttpStatus status_code;

    public JSONDownloaderTask() {
        Log.d("con", "Success");
        this.username = userObj.getUsername();
        this.password = userObj.getPassword();

        Log.d("User" + this.username , " Pass" + this.password);
    }

    private AsyncProgressActivity progressbar = new AsyncProgressActivity();

    @Override
    protected void onPreExecute() {
        progressbar.showLoadingProgressDialog();
    }

    @Override
    protected String doInBackground(String... params) {

        final String url = params[0]; //getString(R.string.api_staging_uri) + "Authenticate/";

        // Populate the HTTP Basic Authentitcation header with the username and password
        HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setAuthorization(authHeader);
        requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

        // Create a new RestTemplate instance
        RestTemplate restTemplate = new RestTemplate();

        restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

        try {
            // Make the network request
            Log.d(this.getClass().getName(), url);

            ResponseEntity<Message> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<Object>(requestHeaders), Message.class);
            status_code =  response.getStatusCode();
            return response.getBody().toString();
        } catch (HttpClientErrorException e) {

            status_code = e.getStatusCode();
            return new Message(0, e.getStatusText(), e.getLocalizedMessage(), "error").toString();
        } catch ( Exception e ) {
            Log.d(this.getClass().getName()  ,e.getLocalizedMessage());
            return "Unknown Exception";
        }
    }


    @Override
    protected void onPostExecute(String result) {
        progressbar.dismissProgressDialog();


        switch ( status_code ) {
        case UNAUTHORIZED:
            result =  "Invalid username or passowrd"; break;
        case ACCEPTED:
            result = "Invalid username or passowrd" + status_code; break;
        case OK:
            result = "Successful!"; break;
        }
    }
}
}

AsycProgressActivity.java

public class AsyncProgressActivity  extends Activity {

protected static final String TAG = AsyncProgressActivity.class.getSimpleName();

private ProgressDialog progressDialog;
private boolean destroyed = false;

@Override
protected void onDestroy() {
    super.onDestroy();
    destroyed = true;
}

public void showLoadingProgressDialog() {
    Log.d("Here", "Progress");
    this.showProgressDialog("Authenticating...");
    Log.d("Here", "afer p");
}

public void showProgressDialog(CharSequence message) {
    Log.d("Here", "Message");
    if (progressDialog == null) {
        progressDialog = new ProgressDialog(this);
        progressDialog.setIndeterminate(true);
    }
    Log.d("Here", "Message 2");

    progressDialog.setMessage(message);
    progressDialog.show();
}

public void dismissProgressDialog() {
    if (progressDialog != null && !destroyed) {
        progressDialog.dismiss();
    }
}
}

LoginActivity.java

public class LoginActivity extends AsyncProgressActivity implements OnClickListener {

Button login_button;
HttpStatus status_code;

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

    setContentView(R.layout.main);

    login_button = (Button) findViewById(R.id.btnLogin);
    login_button.setOnClickListener(this);
    ViewServer.get(this).addWindow(this); 
}

public void onDestroy() {  
    super.onDestroy();  
    ViewServer.get(this).removeWindow(this);  
}  

public void onResume() {  
    super.onResume();  
    ViewServer.get(this).setFocusedWindow(this);  
}  

public void onClick(View v) {
    if ( v.getId() == R.id.btnLogin ) {

        User userobj = new User();
        String result;
        userobj.setUsername( ((EditText) findViewById(R.id.username)).getText().toString());
        userobj.setPassword(((EditText) findViewById(R.id.password)).getText().toString() );


        TaskHandler handler = new TaskHandler(getString(R.string.api_staging_uri) + "Authenticate/", userobj);
        Log.d(this.getClass().getName(), "One");
        result = handler.handleTask();
        Log.d(this.getClass().getName(), "After two");
        Utilities.showAlert(result, LoginActivity.this);
    }
}

Utilities.java

public class Utilities {

public static void showAlert(String message, Context context) {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    alertDialogBuilder.setTitle("Login");

    alertDialogBuilder.setMessage(message)
                      .setCancelable(false)
                      .setPositiveButton("OK",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            dialog.dismiss();
                            //dialog.cancel();
                        }
                       });
    alertDialogBuilder.setIcon(drawable.ic_dialog_alert);

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show(); 
}
 }

EDIT: More info

I tried to add Logging step by step to see where its crashing. It looks like its crashing here. Because its not showing the log message after this.

        Log.d("Here", "Message");
    if (progressDialog == null) {
        progressDialog = new ProgressDialog(this);
        progressDialog.setIndeterminate(true);
    }
    Log.d("Here", "Message 2");

Message 2 is not showing up in the log, but Message shows up.

  • 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-11T00:19:06+00:00Added an answer on June 11, 2026 at 12:19 am

    I think the issue is your handleTask method:

    public String handleTask() {
        Log.d("Two", "In the function");
        task = new JSONDownloaderTask();
        Log.d("Three", "In the function");
        task.execute(URL);
        return results;
    }
    

    You are kicking off an AsyncTask which will populate the results variable in another thread when the task is finished. However, you are returning this value right away and immediately using it to build an AlertDialog. This variable probably has not been populated by the background thread yet and may still be null.

    EDIT: You probably shouldn’t call showAlert in onClick. Instead, you should call it in onPostExecute.

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

Sidebar

Related Questions

fairly new Android developer here. I've come across a strange problem that I'm not
I'm a beginner at SQL and have this fairly easy conditional problem: Every installation
Fairly simple question: I have an init method on my class that has the
I am beginner coder in web design so I have a fairly amateur question
I have a learning application that implements the most important endpoints in a sole
I'm fairly new to Rails, and I have a few beginner's questions. I want
I am wanting to learn Java, particularly for Android development since I am getting
I was reading a beginners tutorial on android development which had this line in
I am fairly a beginner with javascript. What I want to do is when
So, i'm a fairly beginner in oAuth and i'm wanting to write a simple

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.