Skip to content Skip to sidebar Skip to footer

Android: Code Acts Crazy

I have an extremely strange Problem, while trying to develop for android on eclipse my program always returned non-sense statements, so I tried debugging it. And Now I understand w

Solution 1:

Usually when I see behavior like this, it is because I am not running the code I think I am running. I have not done Android development, so I can't speak specifically to that, but do you have "build automatically" under the project menu checked? I have found that to reduce the number of times I see this behavior tremendously.

Have you tried cleaning the code and doing a complete rebuild? Are you running this out of Eclipse or on a remote device? If on a remote device, have you published the code to the device?

As I said, I haven't done any Android development, so some of these questions may seem obvious from an Andriod developing standpoint.

Hope those ideas help.

Solution 2:

To me, it actually sounds like your braces are misaligned in some way. It appears to be ignoring the braces around the if statement, treating it like this.

if (formatedVerses.size() < 1) // check if readAndSplitDatabaseFile worked
    createDatabase(database, false); // if not. the database wasnt initialized
formatedVerses = readAndSplitDatabaseFile(database, books); // try again 

Doesn't really explain your second example though.

EDIT: Or maybe your second block is also parsing oddly.. doesn't explain why the code continues after a return statement though.

if (formatedVerses.size() < 1) 
    return array1;
else
    doSomethingElse();
return array2;

Solution 3:

just to elaborate on what aperkins said, which is all correct, the Eclipse debugger uses line number information from when your code was compiled into a .class file, and uses your source .java file to display what line of code is being run. So say you write this :

if (readAndSplitDatabaseFile(database, books).size() < 1) { 
    createDatabase(database, false); // if not. the database wasnt initialized
    formatedVerses = readAndSplitDatabaseFile(database, books); // try again 
}

return formatedVerses;

and you build and run, and then you add a line of code and a blank line:

ArrayList<String[]> formatedVerses = readAndSplitDatabaseFile(database, books);

if (formatedVerses.size() < 1) { // check if readAndSplitDatabaseFile worked
    createDatabase(database, false); // if not. the database wasnt initialized
    formatedVerses = readAndSplitDatabaseFile(database, books); // try again 
}

return formatedVerses;

now when you are debugging, you are stepping through the first example, but looking at the second. The solution as aperkins mentioned is just to build and run again, or to undo your changes until they match up with what you had when you last compiled.

Solution 4:

Okay, I figured it out.

Strangely it was something completely different.

I made some mistakes on the complete other side of my program. It had nothing to do with this code-segment (the problems weren't even in the same class.)

once that was fixed, it started to act normal again.

I don't understand it and at this point, I don't want to understand it.

Thanks for the help, everybody.

Post a Comment for "Android: Code Acts Crazy"