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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:52:28+00:00 2026-05-24T03:52:28+00:00

I need some help on android.., apparently, I’m trying to make a progress dialog

  • 0

I need some help on android.., apparently, I’m trying to make a progress dialog for learning purposes, basically this progress dialog doesn’t do anything but shows the progress bar… I have a button in my main activity, upon clicking on that button, its onClickListener will run showDialog(1) method, which will call the main’s onCreateDialog method, however I’ve placed the button’s View.onClickListener as a separate class which is ButtonOnClickListener, all the necessary variables in the main activity are referenced in it, when I ran the activity in the avd emulator..when I click the button, it does not execute the progress dialog, but throws me an error “Sorry! the application has stopped unexpectedly. Please try again.” which forces me to quit… problem is with the ButtonOnClickListener class..which I still couldn’t debug for hours..

It only works if the the onClickListener is an anonymous class… some help?

This is the main activity class..

package edu.net.learn.android;

import android.app.Activity;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.Dialog;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Message;

public class DialogImproved extends Activity{
CharSequence[] items = {"Google", "Apple", "Microsoft"};
boolean[] itemsChecked = new boolean[items.length];

private ProgressDialog _progressDialog;
private int _progress = 0;
private Handler _progressHandler;

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

    Button btn = (Button)this.findViewById(R.id.btn_dialog);

    _progressHandler = new Handler(){
        public void handleMessage(Message msg){
            super.handleMessage(msg);
            if(_progress >= 100){
                _progressDialog.dismiss();
            }//end if
            else {
                _progress++;
                _progressDialog.incrementProgressBy(1);
                _progressHandler.sendEmptyMessageDelayed(0, 100);
            }
        }
    };


    btn.setOnClickListener(new ButtonOnClickListener(this,_progress,_progressDialog,
            _progressHandler));


}//end onCreate

protected Dialog onCreateDialog(int id){
    switch(id){
    case 1:
        _progressDialog = new ProgressDialog(this);
        _progressDialog.setIcon(R.drawable.icon);
        _progressDialog.setTitle("Downloading files..");
        _progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

        _progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Hide", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getBaseContext(), "Hide clicked", Toast.LENGTH_SHORT).show();

            }
        });

        _progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener(){

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_SHORT).show();

            }
        });
        return _progressDialog;

    }

    return null;
}

ButtonOnClickListener Class…

package edu.net.learn.android;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;
import android.view.View;


public class ButtonOnClickListener implements View.OnClickListener {

private Activity main;
private ProgressDialog _progressDialog;
private int _progress = 0;
private Handler _progressHandler;

ButtonOnClickListener(Activity main,int _progress, 
        ProgressDialog _progressDialog, Handler _progressHandler){
    this.main = main;
    this._progress = _progress;
    this._progressDialog = _progressDialog;
    this._progressHandler = _progressHandler;
}

public void onClick(View v){
    _progress = 0;
    _progressDialog.setProgress(0);
    _progressHandler.sendEmptyMessage(0);
    main.showDialog(1);


    _progressHandler = new Handler(){
        public void handleMessage(Message msg){
            super.handleMessage(msg);
            if(_progress >= 100){
                _progressDialog.dismiss();
            }//end if
            else {
                _progress++;
                _progressDialog.incrementProgressBy(1);
                _progressHandler.sendEmptyMessageDelayed(0, 100);
            }
        }
    };

}




}

LogCat reported a null pointer exception at ButtonOnClickListener class at line 27…

  • 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-24T03:52:29+00:00Added an answer on May 24, 2026 at 3:52 am

    Invokation of onCreateDialog will only assign values to the fields in DialogImproved. It will not assign values to the fields in ButtonOnClickListener

    I don’t know why you have dialog references in the DialogImproved, and I don’t know what you want to do, but it actually looks like you instead want to use AsyncTask. The task should aggregate the dialog, the DialogImproved doesn’t need to know about the progress dialog.

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

Sidebar

Related Questions

I need some help here. Basically, I have an Activity. This uses the startActivityForResult()
I need some help calculating Pi. I am trying to write a python program
I need some help with jQuery script again :-) Just trying to play with
I need some help dealing with three Threads in Android One thread is the
I need some help to store a Object in an SQLite database using Android.I
I'm creating an Android app utilising OpenGL ES, and need some help with the
Hii everybody , I am noob at android and need some help... I am
I'm kind of new to this whole thing so I need some help. I
I am a very green android developer and need some help with a strange
i am new to java and android. I need some help with my main.xml

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.