I am aware there are many forms on StackOverflow about this very topic but none of the fixed worked for me.
When I run the code:
muteText.setText("Testing")
I get an error.
MainActivity.java
//Class Variables
Button startTime;
Button endTime;
TextView muteTime;
TextView unmuteTime;
int hour;
int minute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Define Variables
startTime = (Button)findViewById(R.id.startButton);
endTime = (Button)findViewById(R.id.endTime);
muteTime = (TextView)findViewById(R.id.muteText);
Log.i("SchedMute", "muteTime: " + muteTime.getText().toString());
unmuteTime = (TextView)findViewById(R.id.unmuteTime);
//Button Listeners
startTime.setOnClickListener(this);
endTime.setOnClickListener(this);
//--\\
hour = 0;
minute = 0;
}
public void onClick(View v){
int id = v.getId();
if(id == R.id.startButton){ //Selecting time 2 Mute phone
showTimePickerDialog(v);
}
}
public void setStartTime(){
muteTime.setText("Testing Testing 123");
}
(Error occurs in last Method (setStartTime))
I am calling the method in another class by doing so:
MainActivity activity = new MainActivity();
activity.setStartTime();
I spend a good 30 minutes trying to figure this one out. Error:
07-29 12:29:44.034 19958-19958/myApp.com.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: myApp.com.app, PID: 19958
java.lang.NullPointerException
at myApp.com.app.MainActivity$TimePickerFragment.onTimeSet(MainActivity.java:96)
at android.app.TimePickerDialog.tryNotifyTimeSet(TimePickerDialog.java:223)
at android.app.TimePickerDialog.onClick(TimePickerDialog.java:173)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:170)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5678)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)