I have a problem with my code. It keeps on crashing when i have a blank editText field. This bit of code is in the settings of my app and works the data fine but when ther
if (task1.toString().length() < 0) {
task1.toString();
t1.setText(task1);
}
else {
t1.setText(edit);
}
The above makes no sense at all.
Firstly task1
IS a string so there's no need to call toString()
to convert it to one.
Secondly, your conditional statement (if
) is checking to see if task1
has a length less than zero....think about it.
Thirdly, if it does have an impossible length less than zero you then call toString()
on it again (with no variable to receive the impossible less than zero result) and you then try to set the text of your t1
EditText
.
The chances are that your file reading is failing (probably because you only save the strings later in the onClick(...)
method). Because your task
strings will be null
if the file reading fails then you need to test for null
before trying to use them.
In other words you're doing this in your code...
String task1 = null;
To fix the bit of code I enclosed at the beginning, use...
if (task1 != null) {
t1.setText(task1);
}
else {
t1.setText(edit);
}
...but most importantly, make sure your files have the strings in them that you need to read.