Reputation: 188
we have two activities one is where we make the connection via bluetooth and managing the blutooth other one is the update the UI where we want to update the GUI containing the TextViews. We successfully send and recieve the message within two activities and vice versa.
private OnMessageReceivedListener dataReceivedListener = new OnMessageReceivedListener() {
public void OnMessageReceived(String device, String message) {
//t.setText(message);
Log.d("Message" , message);
msg = message;
UpdateGUI();
}
};
THE above function recieves the message and we did that successfully.
private void UpdateGUI() {
//i++;
//tv.setText(String.valueOf(i));
myHandler.post(myRunnable);
}
final Runnable myRunnable = new Runnable() {
public void run() {
btBoard.UpdateYoursBoard(mystring);
}
};
The above function of connection class calls the method of our GUI class and send a recieved message to it.
In our GUI class we want this
public void UpdateYoursBoard(String positions)
{
Log.d("Positions" , positions);
tv.setText(positions);
}; we successfully recieved the message in log.d but when we want to change our textview text it gives following errors.
java.lang.NullPointerException
at net.clc.bt.Board.UpdateYoursBoard(Board.java:3460)
NOTE : we are working with bluetooth and we have 3 mobile connected simultaneously and UpdateYourBoard will change the TextViews of 3 mobiles GUI's.
kindly help me to fix the problem. Thanks in advance
Upvotes: 2
Views: 190
Reputation: 20563
The reference to your TextView 'tv' is null. Initialize it somewhere using findViewById()
or some other appropriate method.
Check your scopes etc so that the reference is maintained properly at the point where you call the setText()
method.
Upvotes: 0
Reputation: 38168
First your Board class is far too big. 3 500 lines in a java file is very bad idea. Design more, decouple and split things. You are missing the divide and conqueer principle of IT.
In your case, tv is null. How and when do you get a reference to it ? If you used findViewById in your onCreate method (after super.onCreate has been called), it should work.
Upvotes: 2