Skip to content Skip to sidebar Skip to footer

Very Different Result When Testing Android App On Two Computers

I'm working on an Android app, and I'm developing on my Macbook laptop when I'm away from home and my Windows computer at home. I have the same JDK version (1.8.0_131) on both mach

Solution 1:

I'm guessing you have different code on your Mac and PC. You mention calling getDeclaredFields(), but the code you posted calls getFields(). If the code you posted is from your PC, then that is why you're seeing inherited public fields.

You're not seeing private fields because you're trying to access them without making them accessible. This throws an exception, which you log and ignore. Check your logs and you should see exceptions for each non-public field. Try adding just the names of your fields to your string or call setAccessible(true) of each field before calling get.

UPDATE:

I don't know where the change and serialVersionUID fields are coming from. I suspect there's an IDE or compiler setting to automatically include them. Since they are static fields you can filter them out. You would probably want to do this anyway.

for (Field f : getClass().getDeclaredFields()) {
    if (Modifier.isStatic(f.getModifiers()) continue;
    if (!f.isAccessible()) {
        f.setAccessible(true);
    }
    Object value = f.get(this);
    temp += ", " + f.getName() + ": " + String.valueOf(value);
}

Solution 2:

I'd add this as a comment but don't have enough reputation..so just some bits of advice: 1. Try not to use reflection, 99% of the time it is only a workaround for bad design... Think about refactoring. 2. Avoid using abstract classes at all, use interfaces instead.

Post a Comment for "Very Different Result When Testing Android App On Two Computers"