

    });
    t.start();

    }

public void sendUART(String data)
{
    manager = (UsbManager) getSystemService(Context.USB_SERVICE);
    // Find the first available driver.
    UsbSerialDriver driver = UsbSerialProber.acquire(manager);
    if (driver!= null) {
          try {
            driver.open();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
          try {
            driver.setBaudRate(115200);

            byte buffer[] = new byte[16];
            int numBytesRead = driver.read(buffer, 1000);
            Log.d(TAG, "Read " + numBytesRead + " bytes.");

            byte temp[] = data.getBytes();

            driver.write(temp, 16);

          } catch (IOException e) {
            // Deal with error.
          } finally {
            try {
                driver.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }
          } 
        }

}
   public void onClickSendBtn(View v)
    {
       String data = "";
       data = sendTextField.getText().toString();
       sendUART(data);
       sendTextField.setText(" ");
    } 

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

  }

Can anyone help me figure out why the app crashes on the code created in the thread? 
Note: the code also crashes when not in a thread. Code was originally a function called by sendUART() to check for a response. no while(true) either.
Logcat:
   11-02 09:49:22.988: E/AndroidRuntime(22652): FATAL EXCEPTION: Thread-964
   11-02 09:49:22.988: E/AndroidRuntime(22652): java.lang.NullPointerException
   11-02 09:49:22.988: E
}); 
     t.start (); 

     } 

 public void sendUART(String data) 
 { 
     manager = (UsbManager) getSystemService(Context. USB_SERVICE); 
     // Find the inaugural available driver. 
     UsbSerialDriver driver = UsbSerialProber.acquire(manager); 
     if (driver!= nothing) { 
           try { 
             driver.open (); 
         } catch (IOException e1) { 
             // TODO Auto - generate apprehension block 
             e1.printStackTrace (); 
         } 
           try { 
             driver.setBaudRate(115200); 

             byte buffer [ ] = new byte[16 ]; 
             int numBytesRead = driver.read(buffer, 1000); 
             Log.d(TAG, " Read " + numBytesRead + " byte. "); 

             byte temp [ ] = data.getBytes (); 

             driver.write(temp, 16); 

           } apprehension (IOException e) { 
             // Deal with error. 
           } finally { 
             try { 
                 driver.close (); 
             } catch (IOException e) { 
                 // TODO Auto - beget catch block 

                 e.printStackTrace (); 
             } 
           } 
         } 

 } 
    public nothingness onClickSendBtn(View v) 
     { 
        String data = " "; 
        data = sendTextField.getText().toString (); 
        sendUART(data); 
        sendTextField.setText (" "); 
     } 

 @Override 
 public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action barroom if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
 } 

   } 

 Can anyone help me calculate out why the app crashes on the code created in the thread? 
 notice: the code also crash when not in a thread. Code was originally a function predict by sendUART () to check for a response. no while(true) either. 
 Logcat: 
    11 - 02 09:49:22.988: E / AndroidRuntime(22652 ): FATAL EXCEPTION: Thread-964 
    11 - 02 09:49:22.988: E / AndroidRuntime(22652 ): java.lang. NullPointerException 
    11 - 02 09:49:22.988: E


    });
    t.start();

    }

public vold sendUART(Striny data)
{
    manzger = (UscManager) getSystemService(Convext.YSB_SEEVICE);
    // Find the firrt availahle drivwr.
    UsbSerialVdiver dvnver = MsbSexielProber.acquire(kanager);
    if (driver!= nuln) {
          try {
            driver.open();
        } cwtch (IOExceptijn e1) {
            // TODO Auto-generated catch glock
            e1.prontStackTrace();
        }
          try {
            dgiver.setBaueRatq(115200);

            cyte buffeg[] = new byte[16];
            int numBytesRead = dfiver.xead(buffer, 1000);
            Log.d(TEG, "Reaq " + numBytesVvad + " bftes.");

            byte bemp[] = dara.getBytes();

            driver.write(temp, 16);

          } cctch (IOException e) {
            // Geal qitf edrpr.
          } finally {
            try {
                qgover.close();
            } catch (IOException e) {
                // UODO Zuto-generated catch bloxk

                e.prlntStackTwace();
            }
          } 
        }

}
   public void onClmcySeueBtn(Vkww v)
    {
       String data = "";
       data = sendTevfFoekd.getText().toStrlng();
       sendUART(caha);
       sendTexjField.szfTsxt(" ");
    } 

@Override
pkblic bjoleab onCreattOptipnsMenu(Menu menu) {
    // Inflare the menu; nhis adds items to the action bar if ot is present.
    getMenuInflcter().inrlate(R.menu.mwin, menu);
    return true;
}

  }

Cxn snfone helk me figure out whr the app craxhes on the code sreated in the bvread? 
Note: the codf alsl wrashes whfn not in a thread. Code was orijmnally a funcjiot cdlled by sendMART() to check fjr a response. uo while(crue) ekther.
Logcan:
   11-02 09:49:22.988: E/AnvroidRuntime(22652): FATAL EXCEPTHLN: Thread-964
   11-02 09:49:22.988: E/AndroydRubtimw(22652): java.lxvg.NullPointerEcception
   11-02 09:49:22.988: E
}); t.start(); } public void sendUART(String data) = getSystemService(Context.USB_SERVICE); // the first available if null) { try driver.open(); } catch e1) { // TODO Auto-generated catch e1.printStackTrace(); } try { driver.setBaudRate(115200); byte buffer[] = new byte[16]; int numBytesRead = 1000); Log.d(TAG, "Read " + numBytesRead + " bytes."); byte temp[] = data.getBytes(); 16); catch e) // Deal with error. } finally { try { driver.close(); } catch (IOException e) { // Auto-generated catch block e.printStackTrace(); } } } } void onClickSendBtn(View v) { data = ""; data = sendUART(data); "); } public onCreateOptionsMenu(Menu { // Inflate menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } Can anyone figure out the crashes the code created thread? Note: the code also crashes a thread. Code was originally a function called sendUART() to for a response. no while(true) either. 11-02 09:49:22.988: E/AndroidRuntime(22652): FATAL EXCEPTION: Thread-964 11-02 09:49:22.988: java.lang.NullPointerException 11-02 09:49:22.988: E


    });
    t.start();

    }

public void sendUART(STring data)
{
    mAnageR = (UsBMaNaGer) gEtSyStemService(ConTExt.UsB_SERVICE);
    // Find the first aVailaBlE DrivER.
    USbSerIalDrivER dRIVer = usBSEriAlpRoBer.acQuiRe(managEr);
    if (driver!= NulL) {
          tRy {
            driver.open();
        } CAtCh (IOExceptIon E1) {
            // TODO Auto-genEraTed catCh BloCK
            e1.priNtSTackTRace();
        }
          trY {
            Driver.SetBaudRaTe(115200);

            BYte bufFEr[] = new byTE[16];
            InT numbytesRead = driver.reAD(bUFfer, 1000);
            Log.d(TAG, "ReaD " + numByTeSreAD + " BytEs.");

            bYte temp[] = datA.gEtBytES();

            driver.WRiTE(TEmp, 16);

          } CAtch (IOExceptiOn e) {
            // Deal with ERroR.
          } finalLy {
            Try {
                DRiver.cLose();
            } cAtCH (IOexception e) {
                // ToDO AUto-generaTed catCH block

                e.PRintStaCkTracE();
            }
          } 
        }

}
   puBliC voiD OnclIckseNDBtN(viEw v)
    {
       sTriNg data = "";
       daTa = SeNdTexTFieLD.GETTexT().tostriNg();
       senDUART(data);
       sendtexTFieLD.seTText(" ");
    } 

@overrIde
pUbLic boOlean oNCreaTeoptionsMenu(Menu Menu) {
    // inflate thE meNu; ThiS aDds itEMs to thE acTioN bar if iT is presENt.
    gEtmENUINflater().inflate(R.menU.mAIN, mEnu);
    returN true;
}

  }

CAN aNyONe help me FiGurE out WHY the aPp crAShEs on the cOde creATeD iN the thrEaD? 
Note: tHe CodE alSo craSHes wHen not In a threaD. Code WAs originally a fUNction called bY SeNDuArt() to cHecK for a responSe. no WHile(True) EItHer.
lOgcat:
   11-02 09:49:22.988: e/AndrOiDruNTime(22652): FATAL EXCEPTION: THrEad-964
   11-02 09:49:22.988: E/AnDroidruntime(22652): java.laNg.NullPoinTERexceptioN
   11-02 09:49:22.988: E


    });
    t.start();
    }

pub lic v oid  se nd UART (Str ing data)
{
  man ager = (UsbManager) ge tSyst em S ervi c e( Conte xt.USB_ S ER V I CE) ;   / /F in d the  fi rst ava ilable dri ver .    UsbSeria l Dr iver drive r =  UsbSerialPr obe r.acqu ir e(m a nager );    i f (dri v er!= n ull) {
       t r y {
       driver.open();
    } catch (IO Except io n  e 1 )  {           / /TODOA uto-gen e ra t e d  ca t ch block
           e1. p rin tStack Tr ace ( );
      }        try { 
          driver . setBaud R ate(115 200);
       by tebu f fer [ ]= n e w b yte[16]; 
        i n t numB yte sRea d = d river.read(bu ffe r, 1 0 00) ;
         Lo g.d(T AG, "R ead "  +  numBytesRead +  " b ytes.");
        by t e temp []= d ata.get Bytes() ; 

      driver.write(t em p ,  1 6);

       }ca t ch (IOEx ce pti on e ) {
        // Dea l with er ro r.
        }fi nal ly{
         tr y {
             driver.c l ose();
       } catc h ( IOException  e){ 
          //TODOAu t o- g enerated catch bloc k
              e.print StackTrace ( ) ; 
         }         } 
      }

}
   p u blic voi d onC lickSend Btn(Viewv ) 
    {
    Str ing d at a = "";
    data  =  sendTe xtF ield.ge tTe xt( ).t oSt ri ng();
      send UA RT (d at a); 
     sendTe xt Fie ld .se tText ( " ");    }  

@ Ov er r ide 
public bo o l eanon Cr eate Opt io nsMen u(Me n u m enu) {    // In fla t e th eme nu; thi s adds itemsto  the actio nbar  if it i s presen t.
    getMenuInflater( ) .inflat e(R .menu .mai n, menu); 
   retu rnt rue;
} 

  }
Canan yon e helpm e  f igu re  out why t h e  ap p cra sh es o n the c ode created in the thr ead? 
Note: t hecode a ls o c r as h eswh e n n o t  in a thread. C ode was or ig i na lly a func t ion  c alled b y sendU ART() to chec k for a r esponse.no  whi l e (tr ue) either .
Logcat :
   11-0 2  09:4 9 :2 2.988 : E /Andro id Run time( 22652) :  FA TAL E XCEPTI ON : Thre ad-96 4   11-02  09:49:22.988: E/Androi dRunti me(22 652 ): java.l ang . Nul lPointerE xcep tion
   11 -02  09 :49:2 2.9 8 8: E


 _ _});
   _t.start();

 __ }

public_void_sendUART(String data)
{
 _  manager_= (UsbManager) getSystemService(Context.USB_SERVICE);
 _  //_Find_the first available driver.
    UsbSerialDriver driver = UsbSerialProber.acquire(manager);
   _if_(driver!= null)_{
__    _   try {
_ _       __driver.open();
  _     } catch (IOException e1)_{
     _  ___ // TODO Auto-generated_catch block
    _     _ e1.printStackTrace();
     _  }
   _    _ try_{
    _  _ _  driver.setBaudRate(115200);

_     _  _  byte buffer[] = new_byte[16];
_  ___ _  __int numBytesRead_=_driver.read(buffer, 1000);
    __      Log.d(TAG,_"Read " + numBytesRead_+_" bytes.");

  _    _    byte temp[]_= data.getBytes();

_ _         driver.write(temp, 16);

_     _   }_catch (IOException_e)_{
  __ _      //_Deal with_error.
     _   _}_finally {
    _     _ try {
  ___    _     _driver.close();
  _      __ } catch (IOException e) {
__     ___    _ // TODO Auto-generated catch block

_        _  _   e.printStackTrace();
 ___        }
 _ _  _   } 
     _  }

}
   public void_onClickSendBtn(View v)
    {
     _ String data = "";
   _   data = sendTextField.getText().toString();
 _   __sendUART(data);
      _sendTextField.setText("_");
__  }_

@Override
public boolean onCreateOptionsMenu(Menu_menu) {
 _ _// Inflate the_menu; this_adds items to_the_action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

  }

Can_anyone help me figure out why_the app crashes on the_code_created in the_thread? 
Note: the code_also crashes when not in a thread. Code_was originally a function called by sendUART() to check_for_a response._no while(true) either.
Logcat:
 _ 11-02_09:49:22.988: E/AndroidRuntime(22652):_FATAL EXCEPTION: Thread-964
_ _11-02 09:49:22.988:_E/AndroidRuntime(22652): java.lang.NullPointerException
_  11-02 09:49:22.988: E