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 what the problem is....
...the code acts literally crazy - it's absolutely illogical
this is my code:
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;
basically I create this ArrayList
But when I debug, it doesnt just go trough the code from top to bottom, it makes weird illogical jumps
the debugger arrives at the line:
ArrayList<String[]> formatedVerses = readAndSplitDatabaseFile(database, books);
then jumps to the if-statement (so far so good)
if (formatedVerses.size() < 1) {
but "formatedVerses.size() < 1" is false, so it should jump over the if-block
but instead the debugger not only jumps INTO the if-block, but it actually jumps into THE SECOND LINE of the block:
formatedVerses = readAndSplitDatabaseFile(database, books);
which makes no sense whatsoever.
I feel like somebody is playing jokes on me.
I just cant wrap my mind around this.....
I've also tried restructuring the code...
but it only gets weirder.
I've also tried other implementations. for example like this:
if (formatedVerses.size() < 1) {
return array1;
} else{
doSomethingElse();
return array2;
}
in that case, it jumps into the true-statement of the if-block
return array1;
and then, when I click on next-step, it actually JUMPS from that line to the
return array2 line inside of the else-block, while completely leaving out the doSomethingElse()-line
anybody got any ideas?
because I'm going crazy right now...
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.
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;
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.
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.
Related
here is some code that works when using play mode in the editor with unity remote, but it does not work when running on an actual android build. Just the function with a problem.
public IEnumerator Reload(){
if(isReloading == false){
Debug.Log ("Reloading");
if(isShooting == true){
CeaseFire();
}
isReloading = true;
fpsRigAnimation.CrossFade (reloadAnim);
guiText.text = "before animation length";
//problem here
yield return new WaitForSeconds (fpsRigAnimation[reloadAnim].length);
guiText.text = "after animation length";
fpsRigAnimation.CrossFade (poseAnim);
Debug.Log ("Reloaded");
isReloading = false;
}
}
The line where I yield for the animation length simply does not run on the android build. I get the "before animation length" in the gui, but not the "after animation length". But both show up when I play it in the editor through the unity remote app. Also the reload animation runs through fine, as well as the debug.log calls in the editor, but the reload animation does not go through at all in the android build.
Edit
I just tested the yield statement with a plain float value (2.23f), and it still does not work. So that means the yield statement is the problem too. But the animation clip length is still a problem because when I try making the guitext say the value, it shows nothing on the android, but it does in the editor. I do have other yield statements in the game that all work accordingly.
Edit: Solution
It turns out the text file that I was reading in all of the stats from needed to be in a special folder called "Resources" to be included in an actual build.
It turns out the text file that I was reading in all of the stats from needed to be in a special folder called "Resources" to be included in an actual build.
May revise your logic giving conditions shall work.
Like
if (animation[“name”].time > animation.["name"].length)
{
//do something
}
Give it a try and tell.
I am using robotium to test my app. Issue is with solo.searchText function. In my app I am using expandale listview to display category values. While testing using robotium I am cross checking whether all the categories are present. I am using the below code for that.
boolean ifCategoryLoadingFailed = false;
for(String cat: UnitTestHelperSuite.getInstance().categories){
if(solo.searchText(cat,1,true)){
//LogAdapter.verbose(TAG, "***********Found Category::"+ cat);
UnitTestingFramework.expdata.exportResult("****","Found Category::"+cat,"Success");
continue;
}
else{
ifCategoryLoadingFailed = true;
//LogAdapter.verbose(TAG, "***********Failed to Found Category::"+ cat);
UnitTestingFramework.expdata.exportResult("****","Found Category::"+cat,"Failed");
break;
}
}
It was working fine before. But now the list is not scrolling. So it is identifying only visible categories. But it is not entering the else condition.Testing is stopping here. How can I make it scrollable? please help me. I am stuck with this.
In my experience solo always scrolls down when searching for text. It does not scroll back up though. If your problem is caused by scrolling to the bottom while searching for one value, then the solution is to always call solo.scrollListToTop(listIndex) right before you call searchText() .
Specifically, I'm seeing this issue on an Android tablet, but I'm told it's with ALL mobile devices -- iPhones, Nexus tablets, etc.
But I have the common problem of change events not firing. Here's the function code that has the click events assigned:
function do_this(with_this_data)
{
var that = this;
this.with_this_data = with_this_data;
this.period = 900;
this.updateHours();
$('#date').change(function() {
that.updateHours();
});
$('#time_hour').change(function() {
that.updateMinutes();
});
// extra irrelevant data trimmed out
}
Now...one fix that should work is to move those .change() statements into a $(document).ready block -- but the problem is, if I do, then i get all sorts of undefined variable issues and stuff....all of the "update" functions are within said $(document).ready block and defined by names like "FutureStuff.prototype.updateMinutes."
What are my options???
Mifeet, again, I appreciate your feedback; I know you weren't able to fully get me up and running, but I'm still thankful.
But anyway, I solved the issue...it meant that basically I had to rewrite a new version of the JS code and stick it in an "if this chap is using a mobile browser" block. So yeah, one huge block of code for desktop users, another for mobile...but it works. :) And it was a pain in the hiney.
This is really an odd problem. The basic gist of it is what the title says. I have an adapter, which I am updating and calling notifyDatasetChanged() The problem however, is it does not work, unless the device has been rotated at least once. I can't for the life of me figure out why, what is being done differently after a rotation occurs?
The code in question is here:
The ASyncTask that handles it..
protected void onPostExecute(ArrayList<Records> result) {
if (ca == null)
{
ca = new CoverAdapter<Records>(c, R.layout.grid_cover_with_text_item, result);
}
if (gv.getAdapter() == null)
{
gv.setAdapter(ca);
}
else
{
new AdapterHelper().update((CoverAdapter) ca, result);
ca.notifyDataSetChanged;
}
}
With "ca" being my adapter, "gv" being my GridView and AdapterHelper().update being a method I found here to clear the adapter and add all the results of the arraylist to it, so it should be being updated properly.
Remember, this code works after the device has been rotated. Very confused right now, any insight would be appreciated. Thanks in advance.
Use the debugger and step through the code to check what is expected actually happens.
Glad you found the problem... Now you can ditch the AdapterHelperclass which is a waste.
I am converting someones Palm Pilot code into an Android application for them. This involves me using the NDK to read from one of their already built libraries. For this, I need to create several new functions.
void __stdcall FreeRelay(void){
RelayAPI_DataValid=0;
RelayAPI_SetBaud=0;
RelayAPI_get=0;
RelayAPI_put=0;
RelayAPI_flush=0;
RelayAPI_delay=0;
RelayAPI_initilized=0;
}
void Java_my_MainMenu_FreeRelayJava( JNIEnv * env, jobject this ) {
RelayAPI_DataValid = 0;
RelayAPI_SetBaud = 0;
RelayAPI_get = 0;
RelayAPI_put = 0;
RelayAPI_flush = 0;
RelayAPI_delay = 0;
RelayAPI_initilized = 0;
}
Now, my error is in the last line of the second method. I had originall had it spelled RelayAPI_initialized, I know that thats correct, but I'm not going through the trouble of changing all of this C code for the typo. I'll make my function fit with the old code. Anyway, I tried ndk-build and got this.
Now in between those separate ndk-build calls, I fixed the error. But it still is telling me in line 615 there is an error dealing with RelayAPI_initialized but its NOT THERE. I don't know whats going on, and I really know very little about C. I saved my files with the updated information then called ndk-build. WHAT AM I MISSING?
maybe you can grep to find if other var like RelayAPI_* are defined GLOBALLY in some c code or header file.
if not, define it, or don't set it.
it will resolve compilation error... but probably it wont work
do a clean of your build. so the party built stuff is deleted and you get a full rebuild.