I have a problem with setText( TextView ).
view = EgridView.getChildAt( iterator );
parameter = (TextView) view.findViewById( R.id.gridItemParameter );
if( modbus.readAvailable() > 0 ){
if( !((data = modbus.readData()).equals("")) ){
Log.i("-------------TEST-----------", data); // <-------- wrok
//Toast.makeText(getApplicationContext(), data , Toast.LENGTH_LONG).show(); <----- work
// parameter.setText( "test" ); <----------- work
parameter.setText( data ); // <--------- crash
}
}
Why **parameter.setText( data ); **crashes my app?
More code:
public int readAvailable(){
try{
return inStream.available();
} catch( Exception e ){
return 0;
}
}
public String readData(){
try{
if( isConnected == true && socket.isConnected() && inStream != null ){
int i;
int oneByte;
byte byteArray[] = new byte[ 100 ];
int available = inStream.available();
String data = "";
if( available > 0 ){
inStream.read( byteArray );
for( i = 0; i < available; i++ ){
oneByte = byteArray[ i ] & 0xff;
data = data.concat( Integer.toString( oneByte ) + " " );
}
return data; // <-----
} else {
return "";
}
} else {
errorText = "no communication";
return "";
}
} catch( Exception e ){
errorText = e.getMessage();
return "";
}
}
If in readData() I write return "test"; then work
If in readData() I write return byteArray.toString(); then work
If in readData() I write for( i = 0; i < 10; i++ ){ then work
If in readData() I write for( i = 0; i < 11; i++ ){ then crashes
int available = 13 in this situation.
My problem is illogical for me. Please advice.
Thanks for all answers