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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:40:23+00:00 2026-06-03T09:40:23+00:00

i have 3 classes and the class called WebServiceCleint class is extending Asynctask and

  • 0

i have 3 classes and the class called WebServiceCleint class is extending Asynctask and in doInBackgrnd() i m passing url and i m getting data from webservice. but i m calling this from another class’s method called VerifyTeacherId. Now how can i show progress dialog??? where should i write the pg.show and pg.dismiss.???

public  class WebServiceClient extends AsyncTask<String, Void, String>
{

 private static final String base_path = "http://www.gdaschools.in/";
 protected static final String SLASH = "/";


 private ProgressDialog dialog;
 private Activity activity;

 public WebServiceClient(Activity activity) {
        this.activity = activity;
        this.dialog = new ProgressDialog(activity);
    }

    @Override
     protected void onPreExecute() {
            this.dialog.setMessage("Progress start");
            this.dialog.show();
        }



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

    StringBuffer sb = new StringBuffer();
    sb.append(base_path);
    sb.append(params[0]);
    HttpRetriever retrieveResponse = new HttpRetriever();
    retrieveResponse.retrieve(sb.toString());
    return retrieveResponse.getResponseXml();
}



 @Override
protected void onPostExecute(String result) {
     if (this.dialog.isShowing()) {
           this.dialog.dismiss();
     }
}
}

And the method where i m calling is it in another class named SelectOptionActivity. The method is

public void verifyTeacherId(View view)
{
    teacherIdString = TeacherId.getText().toString().trim();

    clientThread = new WebServiceClient(SelectOptionActivity.this);
    clientThread.execute("teacher/" + teacherIdString);     

    try 
    {
        String xml = clientThread.get();

        DocumentBuilderFactory factory1 = DocumentBuilderFactory.newInstance();
        factory1.setNamespaceAware(true);
        try
        {
            DocumentBuilder builder = factory1.newDocumentBuilder();
            Document doc =builder.parse(new InputSource(new StringReader(xml))); 
            Element root = doc.getDocumentElement();
            if (doc != null) 
            {
                    NodeList nl = doc.getElementsByTagName("empId");
                    if (nl.getLength() > 0)
                    {
                        Node node = nl.item(0);
                        responseTeacherId = node.getTextContent();
                    }
                    NodeList n2=doc.getElementsByTagName("empName");
                    if (n2.getLength() > 0)
                    {
                        Node node = n2.item(0);
                        responseTeacherName = node.getTextContent();

                    }
            }

             Toast.makeText(getBaseContext(),""+responseTeacherId,10).show();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

Now getting error like

05-08 12:10:10.834: D/AndroidRuntime(524): Shutting down VM
05-08 12:10:10.834: W/dalvikvm(524): threadid=1: thread exiting with uncaught exception (group=0x40014760)
05-08 12:10:10.872: E/AndroidRuntime(524): FATAL EXCEPTION: main
05-08 12:10:10.872: E/AndroidRuntime(524): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.GDAProj/com.GDAProj.SelectOptionActivity}: java.lang.NullPointerException
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1739)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.ActivityThread.access$500(ActivityThread.java:122)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.os.Looper.loop(Looper.java:132)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.ActivityThread.main(ActivityThread.java:4123)
05-08 12:10:10.872: E/AndroidRuntime(524):  at java.lang.reflect.Method.invokeNative(Native Method)
05-08 12:10:10.872: E/AndroidRuntime(524):  at java.lang.reflect.Method.invoke(Method.java:491)
05-08 12:10:10.872: E/AndroidRuntime(524):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-08 12:10:10.872: E/AndroidRuntime(524):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-08 12:10:10.872: E/AndroidRuntime(524):  at dalvik.system.NativeStart.main(Native Method)
05-08 12:10:10.872: E/AndroidRuntime(524): Caused by: java.lang.NullPointerException
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:132)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:65)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:120)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.AlertDialog.<init>(AlertDialog.java:80)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
05-08 12:10:10.872: E/AndroidRuntime(524):  at com.GDAProj.WebServiceClient.<init>(WebServiceClient.java:20)
05-08 12:10:10.872: E/AndroidRuntime(524):  at com.GDAProj.SelectOptionActivity.<init>(SelectOptionActivity.java:70)
05-08 12:10:10.872: E/AndroidRuntime(524):  at java.lang.Class.newInstanceImpl(Native Method)
05-08 12:10:10.872: E/AndroidRuntime(524):  at java.lang.Class.newInstance(Class.java:1301)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
05-08 12:10:10.872: E/AndroidRuntime(524):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1730)
05-08 12:10:10.872: E/AndroidRuntime(524):  ... 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-06-03T09:40:25+00:00Added an answer on June 3, 2026 at 9:40 am

    Pass context of your current activity to AsyncTask class and using that context show progress dialog in onPreExecute() and dismiss it onPostExecute()

    public  class WebServiceClient extends AsyncTask<String, Void, String>
    {
     private static final String base_path = "http://www.gdaschools.in";
     protected static final String SLASH = "/";
     private ProgressDialog dialog;
     private Activity activity;
    
    public WebServiceClient(Activity activity) {
        this.activity = activity;
        this.dialog = new ProgressDialog(activity);
    }
    
    @Override
     protected void onPreExecute() {
            this.dialog.setMessage("Progress start");
            this.dialog.show();
        }
    
    @Override
        protected void onPostExecute(final Boolean success) {
            if (this.dialog.isShowing()) {
               this.dialog.dismiss();
            }
    
    .
    .
    .
    

    Code is only for your understanding..

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

Sidebar

Related Questions

I have a bas class called Media with two classes that inherit from it,
Concerning data binding I have these classes: public class Foo : List<Bar> { public
I have a class called Shop that contains data members ( NSString , NSInteger
I have an Abstract class called Function which has 2 inheriting classes (actually 6,
I have two test classes called TT_Common and TT_Container which extends CPPUNIT_NS::TestFixture: class TT_Common
I have a two classes, a controller called AppController and a class called URLDelegate
So I have two classes. One is a class called Main. The Main class
I have a LINQ to SQL class called Data with a column of type
For simplicity let's say I have two classes: a class called Car and a
Say I have two classes, in two different headers, called: class TestA { public:

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.