It seems that the Android SDK doesn't compile my android app correctly. After building an app, I sometimes get seemingly random exceptions. The error goes away if I comment out the offending code, rebuild, uncomment the code, then rebuild again.
For instance, this code gave me a NullPointerException:
playButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivityForResult(settings, PLAY_GAME);
}
});
There is nothing wrong this code! Yet adb logcat tells me it's the cause of an exception.
Commenting out this code, rebuilding, uncommenting and rebuilding, makes the error go away.
What is going on?
This is making developing for android particularly frustrating.
Update: As I pointed out before, these are seemingly random errors that go away once I uncomment/recompile/comment/recompile. So I can't reproduce the stacktrace. It was a NullPointerException if I remember correctly.
However, if it is indeed buggy programming, why is the app running fine now w/o ANY errors at all?
Whenever I make a significant change to the app (add a new resource, a new class, function, etc), old code that was working fine breaks. Why?
Update: Seriously guys, lay off on the hate. I feel like a stumbled on a Atheists vs Christian debate. Sorry to have insunated that android was at fault. Started a new question with the latest errors:
App Ran Fine, Now Breaking for Seemingly Unknown Reasons
Commenting out this code, rebuilding, uncommenting and rebuilding, makes the error go away.
This might seem to you like a bug in Android, but I suspect that the real problem is a threading / synchronization related bug in your code. For instance, playButton may be being used before it is initialized.
But we cannot really help you unless you show us the stack trace and identify the line(s) of code where the exception was thrown.
However, if it is indeed buggy programming, why is the app running fine now w/o ANY errors at all?
See above: it is most likely because you have a threading / synchronization issue. You need to be aware that different parts of an application with a GUI will run in different threads ... even if you didn't explicitly create those threads. There are rules you have to follow. If you don't follow those rules, bad things happen ... like exceptions that sometimes happen and sometimes don't happen, depending on which way the wind is blowing.
Could be that your PLAY_GAME activity is returning without a result, e.g., if you press the back button & it just stops without calling setResult().
No, as noted in several other places, sometimes the source and the bin get out of sync. I've noticed numerous times, specially when making changes to XML. The solution, for commandline users, is to remove the bin directory, and re-compile. Problem goes away.
Related
I work on large enterprise java monolith code. I am new to the team and recently worked on a task, where my tech lead gave a quick guidance - "When you click this button on UI .... eventually this line of code will be executed. This is where you should start exploring"
Now that I have a specific point/line in code, i can put breakpoint and explore the whole flow after that using step-over/step-in. But if i need to know what happened BEFORE that line of code, how do i do it in eclipse?
Between Clicking that button on UI, and that line of code that my tech lead pointed me to, i need to know what all classes/methods were called. Is there a way to explore it in eclipse?
I apologize for a very basic question. Barely learning java and barely getting familiar with eclipse (just learned debugger and breakpoints yesterday).
I originally posted this question on GameDev stackexchange however I'll also ask the question here to try and get more outreach, especially since I wasn't sure my problem was specific to game development since it's a problem with a Java native call.
For the past months I've been working on creating my own game engine for personal use in LWJGL using pieces here and there, especially from developer ThinMatrix's rightfully credited code, to learn as much as I can while building it. Only recently there has been strange behavior happening when I launch the engine from IntelliJ for testing:
After about 6-10 individual times I click run, all subsequent runs suddenly take about 60 seconds for the window to appear.
Whenever I restart my PC this hanging resets and I have another 6-10 runs before it hangs everytime again.
I located the issue to glfwInit, more specifically at the call to the native method:
#NativeType("int")
public static boolean glfwInit() {
long __functionAddress = Functions.Init;
return invokeI(__functionAddress) != 0; // Right here
}
I also noticed that this issue only started when I attempted to implement text support in my engine using the STBTrueType library. It was perfectly fine before that. I tried removing the TrueType code but it didn't fix it.
Here's a list of things I've tried:
Clearing my temp folder in case a buggy or corrupted file was present.
Recompiling and rebuilding the entire LWJGL jars twice.
Building glfw.dll from the GLFW sources and replacing the glfw.dll in the native jars with the former.
Reinstalling Java and actually upgrading JDK versions (from 13.0.2 to 14.0.2)
Switching IDEs even if I suspected it wouldn't work.
Updating my NVIDIA drivers, and reinstalling them.
I'm quite confused as to what it could be, and I'd be more than happy to share code, thread dumps, or debug info if you deem it necessary. Here is the Github repository with the latest, "faulty" code (fault in quotes because I'm not too sure the code is the problem.)
Thank you very much for any guidance.
P.S: Please tell me if this is better asked in StackOverflow instead of here.
So I fixed the issue, it turns out it wasn't even related to anything to do with programming, or STBTrueType, or the library itself. The problem was as pointed out in this StackOverflow post, where this hanging behavior was due to a faulty driver or, in my case, my keyboard USB being plugged in the "wrong" USB port. I moved my computer at the same time I started working on text in my engine, hence why I wrongly linked the issue with the TrueType library. If you're having the same issue, look at the aforementioned post or if that doesn't work, look for a peripheral that might cause interference.
This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 6 years ago.
This has happened on a few different occasions, and I've always just kind of ignored it - but now I'm getting close to being finished with some of my projects, so it can no longer be ignored..
The Issue is as follows: While working on a project in Android Studio, on multiple occasions, seemingly at random, references to "R" will become Red, as if it were an error (or not found)..
For example, in my Main Activity, this reference to R is red, indicating an Error.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Everything with Android Studio is updated via the standard update channel.. The project isn't complicated whatsoever, and I haven't messed with anything that could be delicate, or somehow affect R.. so I'm left extremely confused..
Can anybody offer any kind of explanation regarding this issue?
I would greatly appreciate any advice I can get :) Thanks!
UPDATE: ALTHOUGH THE "DUPLICATE" I WAS LINKED TO BELOW (WHICH I READ FOR ABOUT AN HOUR) DID IN FACT CONTAIN SOME GOOD INFORMATION, IT WAS HOWEVER, A CONVERSATION THAT SEEMED TO CIRCULATE AROUND ECLIPSE (RATHER THAN ANDROID STUDIO, WHICH COULD DRASTICALLY CHANGE THINGS IN SOME CASES). THAT SAID, I DID FINALLY SUCCESSFULLY FIX THE CAUSE OF THE ISSUE! THIS PARTICULAR CASE WASN'T DIRECTLY REFERENCED IN THE LINK I WAS GIVEN, ALTHOUGH I DID GATHER ENOUGH FROM IT TO KNOW GENERALLY WHERE TO SNOOP AROUND FOR THE ERROR. SURE ENOUGH, IT WAS ACTUALLY A MANIFEST FILE REFERENCE TO THE APP ICON (LOL) SOMEHOW IT WAS MESSING THINGS UP, AND SO IN THE
<APPLICATION> SECTION OF THE MANIFEST FILE, I SIMPLY HAD TO ADD:
tools:replace="android:icon"
AFTER THAT, I WENT TO THE MENU AND DID A REBUILD, AND FINALLY IT BUILT THE PROJECT SUCCESSFULLY WITHOUT ANY ERRORS! HOPEFULLY THIS HELPS SOMEBODY ELSE OUT THERE WITH THE SAME ISSUE!
..FOR THOSE OF YOU WHO WANT THE SHORT VERSION OF WHAT I READ IN THE LINK: IN GENERAL, THE "R" NOT FOUND ISSUE SEEMS TO BE CAUSED MOSTLY BY ERRORS OR MISTAKES WITHIN ONE OF YOUR XML RESOURCE FILES WHICH CAUSES R TO NOT BUILD PROPERLY. THANKS FOR THE LINK.
The R file is a generated file, so you need to build the program in order to get the references to it. Make sure you check this answer to see how to rebuild it :
Android studio is based on Intellij Idea. In Intellij Idea you have to do the following from the GUI menu.
Build -> Rebuild Project
I recently came across a bug with an unresolved issue in SDK 2.2 and, as its fixed in 2.5, decided to explore a switch.
Now I am new to GWT and I have no idea of the effects of doing such a switch, but figured it couldn't hurt to mess around locally. I went ahead and successfully updated to 2.5 locally to test and can run with no errors. However many of the text boxes have changed appearance and my navigation bar disappeared, etc...
Is this type of behavior normal after an update? If so I cant imagine why anyone would be in a hurry to do so, as spending enormous amounts of time to modify all pages is pretty unrealistic. Is there maybe some type of quick fix or an error i may have made to cause this?
If you want to put a lot of resources into a GWT project it is always a good idea to check regularly how the project is going on. On the release-note page you can check what's new and what has been deprecated. This way you can make an informed and rational decision whenever you want to update. This is very important since going from an old version (say 1.0) to a new one (i.e 2.5.1) might give some headaches to the programmers. Spendind half-an-hour checking what's going on every month will make your life easier.
GWT has an issue tracker where you can see the open issues and what has been resolved. Many issues have never been fixed, but I read the GWT team intend to solve the 100 most important issues for the next release. GWT is now open-source and you can contribute to its development whenever you know of to fix one of those issues.
Last but not least: many people say a lot of things, which are not always correct (including on Stack Overflow). Always dubble check before making important decisions.
Giving this advice is all I can do for you so far...
Yet, if you give me some info about that bug you expected to be fixed and the exact name of that "navigation bar" widget you might find out information on the sites above to check their status. But I can't search that for you if I don't know what the bug was and the name of the widget that is broken. Also, when you say "many of the textboxes" I understand it's not every textbox that's broken but some variant your are using in some particular places. More information would also be needed...
I am using Eclipse IDE.
Sometimes, after I make some alterations to the code and try to run, I get "'Process Model Delta' has encountered a problem" error. If I try to run again, sometimes it runs (without giving any error again) or again gives the error and I have to restart Eclipse.
I am not pasting any piece of code here, because the code was perfectly fine in many situations when this error occurred.
Can anybody let me know the reason why this error occurs or what is the meaning of this error?
Thanks in advance!
I assume you're actually debug. It that's the case, the cause is in one of your breakpoints. See if it runs fine with breakpoints disabled. If that helps, try Debug view menu Java > Show System Threads.
Cheers,
Max