Tuesday 15 February 2011

android - AsyncTask Class Showing Null Pointer Exception in onProgressUpdate Method -


I'm starting on Android, I'm trying to control a progress bar with an AsyncTask in such an app Which extends Android's Inbuilt messenger class. I'm getting an exception, but I do not understand the mistake in my code.

  The public class extends the MyMessenger service {personal progressive dialog download progressive; Fixed final end v1 = 1, v2 = 2; Barbar progress; Class Expands MyHandler Handler {@Override Public void handleMessage {Switch (msg.what) {Case v1: Toast. GetApplicationContext, "Message = 1 Messenger Handler", Toast. LNNHH_LOG). ); break; Case v2: New Sync () carry about (); break; }}} Messenger messenger = new messenger (new mahandler ()); @Ivarried Public IBinder on Bint (Intent Intent) {// Tudro Auto-Generated Math Stub // Tour. Make text (getApplicationContext (), "binding ...", toast. LNNHHLLG). Show (); Return messenger Butbinder (); } Public Class Sync Async Task & lt; Zero, integer, zero> {Int progress = 0; @ Override Protected Zero Progress Update (Integer ... Value) {// TODO Auto Generate Method Stub // Super. Progress update (value); DownloadProgressDialog.setProgress (value [0]); } @ Override protected voice downline background (zero ... parameter) {// Tudo auto-generated method while stub (Progress & lt; 100) {Progress ++; PublishProgress (progress); SystemClock.sleep (1000); } Return tap; } @ Override Protected Zero on PreExecute () {// TODO Automatically generated method stub super.onPreExecute (); DownloadProgressDialogLog = New Progressive (getApplicationContext ()); DownloadgraduateDialogs.settings ("downloading file ..."); DownloadProgressDialog.setMax (100); DownloadProgressDialog.setProgressStyle (ProgressDialog.STYLE_HORIZONTAL); DownloadProgressDialog.setCancelable (incorrect); DownloadProgressDialog.show (); }}   

}

Since you can not find ViewById in The services that start in your service and make a bar as a public static variable. Repeatedly because you have not started it with FindViewById

  public static progression = (progress bar) code in the enigencode  
  // async function @ Progress update (integer) override protected void. .. value) {if (MyActivityName.bar = null) MyActivityName.bar.setProgress (value [0]); Super.onProgressUpdate (value); }   

Hope this works.

No comments:

Post a Comment