java - How do I access variables within a Handler? Setting them public did not work -


i not know how use variables handler in different method. tried set variables(readbuf, readmessage, , msg) public, did not work. how access these variables in separate method? want variables listed including .arg1 , .obj in handler.

the code commented out processing data was.

    public handler handler;     public byte[] readbuf;      public string readmessage;     public object msg;      handler = new handler();      private final handler mhandler = new handler() {         @override         public void handlemessage(message msg) {             switch (msg.what) {             case message_state_change:                 if(d) log.i(tag, "message_state_change: " + msg.arg1);                 switch (msg.arg1) {             case message_read:                        //for(int = 0; a< 8000; a++)                        //{                        try                         {                         byte[] readbuf = (byte[]) msg.obj;                         string readmessage = new string(readbuf,0,msg.arg1);                         mconversationarrayadapter.add("voltage: "+ readmessage);                         //double[] convert = new double[1];                         //for(int z=0; z <1;z++)                         //{                         //convert[z]= double.parsedouble(readmessage);                         //}                         //for(int j=0; j<1;j++)                         //{                         //stored[a][j]= convert[j];                         //}                         //}                         catch(numberformatexception e)                         {                          system.err.println("numberformatexception: "+e.getmessage());                         }                         //}                 break;             }         }     };      public void process()     {         new thread(new task()).start();     }      class task implements runnable     {         @override         public void run()          {                 try{                     thread.sleep(1000);                 }                 catch(interruptedexception e)                 {                     e.printstacktrace();                 }                 handler.post(new runnable()                 {                     @override                     public void run(){                         for(int = 0; a< 8000; a++)                         {                         byte[] readbuf = (byte[]) msg.obj;//error .obj                         try                         {                         string readmessage = new string(readbuf,0,msg.arg1);// error .arg1                         mconversationarrayadapter.add("voltage: "+ readmessage);                         double[] convert = new double[1];                         for(int z=0; z <1;z++)                         {                         convert[z]= double.parsedouble(readmessage);                         }                         for(int j=0; j<1;j++)                         {                         stored[a][j]= convert[j];                         }                         }                         catch(numberformatexception e)                         {                          system.err.println("numberformatexception: "+e.getmessage());                         }                         }                       }                 });         }      } } 

the way used object variables in other methods setting new public static variables equal object variables. way use them in other methods.


Comments

Popular posts from this blog

Change the color of an oval at click in Java AWT -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -