I am developing an Android (API level 7) app in Eclipse 3.7.2. I have the most curious problem:
There is a class called LoginData to hold login information:
public class LoginData {
private final String login;
private final String password;
public LoginData(final String login, final String password) {
this.login = login; // breakpoint 2 here
this.password = password;
}
public String getLogin() {
return login;
}
public String getPassword() {
return password;
}
}
Then there is a method to retrieve it (in another class):
public static LoginData getLoginData(final Context context) {
final SharedPreferences prefs = getPrefs(context);
final String login = prefs.getString(LOGIN, null);
final String pass = prefs.getString(PASS, null);
if (Utils.isEmpty(login) || Utils.isEmpty(pass)) { // breakpoint 1 here
return null;
}
return new LoginData(login, pass);
}
Method isEmpty() looks like this:
public static boolean isEmpty(final String s) {
return s == null || "".equals(s);
}
And a method calling getLoginData() inside an AsyncTask:
@Override
protected WSResult doInBackground(final Params... params) {
final LoginData loginData = Prefs.getLoginData(context);
...
context is an activity in which the async task is located.
Now when I run this code, loginData is null. Tracing the problem, I put a breakpoint 1 in the specified location. I see that both login and pass is not empty, and I see the program flow go to the last line, return new LoginData(...);. From there it returns… a null.
Tracing the problem further I add breakpoint 2, only to find that the constructor LoginData(...) does not get invoked.
So my first question is: am I missing something really obvious here? If not, there is some weird problem with the code that gets compiled and run.
Some remarks:
LoginDatais used in another location in the program, and works – breakpoint 2 catches on.- I tried renaming
LoginDatato something else, in case it’s cached somewhere or there is a weird name clash. - I tried running this on a Android 2.1 emulator from Eclipse, as well as on a Galaxy Tab.
- I tried cleaning & building the project again.
- I tried closing & opening the project again.
- I tried deleting the project from workspace and importing it again.
I would like to avoid the necessity to create a new Eclipse workspace (that is my final chance, it helped me in a similar case when dealing with Java EE).
What to do?
try replacing this check with