java - Android Thread progressBar issue -



java - Android Thread progressBar issue -

the issue of running thread isn't much issue. i'll give quick outline of want , problem having.

i currently:

implementing runnable interface creating new thread , phone call start method creating run method start method call.

the purpose of new thread animate progress bar while main thread processing image (pixel level). create progress bar follows in oncreate method (loadbar declared globally)

loadbar = (progressbar) findviewbyid(r.id.loadbar);

then in run method

loadbar.animate();

however when run method called throws null pointer exception. when creating new thread runnable interface guess doesn't phone call oncreate method causing null pointer there way around or missing simple?

edit: code requested cutting downwards little problem lies

public class mainactivity extends activity implements runnable {

//declare progressbar private progressbar loadbar; //declare thread private thread createanimation; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); addlisteneronbutton(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_main, menu); homecoming true; } public void addlisteneronbutton() { //assigning loadbar loadbar = (progressbar) findviewbyid(r.id.loadbar); } public void editimage(int pos) { //show progress bar loadbar.setvisibility(view.visible); //start new thread animation createanimation = new thread(new mainactivity()); createanimation.start(); //*** edit image code here (cut out long , not relevant) **// //stop create animation createanimation.interrupt(); loadbar.setvisibility(view.invisible); } //@override public void run() { //create animation loadbar.animate(); } }

java android multithreading

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -