So am trying to use runOnUiThread()
to update my LogUI (found in my apps MainActivity) which is a TextView. The issue is am trying to update the TextView using runOnUiThread()
from another class by getting the strings to be made on the View.
Here is details of my code to elaborate my issue:
private LoggingClass getLogs;
getLogs.AddtoLogUI(String.format("Established on port: %d", obj));
Then the LoggingClass code:
public class LoggingClass {
private MainActivity updateUI;
private String stringValue;
public void AddtoLogUI(final String format) {
this.stringValue = format;
updateUI.runOnUiThread(new Runnable(){
@Override
public void run() {
MainActivity.log_this(stringValue);
}
});
}
}
The method MainActivity.log_this()
code is like this:
public static void log_this(final String msg){
if(editable.toString().split("\n").length >=50) {
editable.delete(0, editable.toString().indexOf("\n"));
}
Runnable runnable = new Runnable(){
@Override
public void run() {
editable.append(msg);
editable.append("\n");
}
};
LogView.post(runnable);
}
PS: LogView is a TextView.
The NullpointerException is thrown when am trying to get the Strings using the getLogs.AddtoLogUI()
method.
Any suggestions?
Additional Info as regards the object:
`Object obj[] = new Object[1];
obj[0] = Integer.valueOf(Port);`