Libgdx Android - GL Thread (NullPointerException) & Missing Class File - java

i'm using the LibGdx framework to create a game and I'm using Eclipse 4.4 (Luna). Whilst i'm debugging my application this method is breaking.
#Override
public void run() {
setName("GLThread " + getId());
if (LOG_THREADS) {
Log.i("GLThread", "starting tid=" + getId());
}
try {
guardedRun();
} catch (InterruptedException e) {
// fall thru and exit normally
} finally {
sGLThreadManager.threadExiting(this);
}
}
inside the GLSurfaceView Android class, with the stack trace:
Thread [GLThread 232] (Suspended (exception NullPointerException))
GLSurfaceView$GLThread.run() line: 1243
I know what a NullPointerException is, I know somewhere is passing a null value, but what I would like to know is how can I find out where?
With these types of questions, I can only assume you'll need more code but I don't know where I should be looking, I'll post code from the Java classes on request if anyone has an idea of where I should be looking.
Note: I'm not using GLSurfaceView directly anywhere in my code, I'm assuming it's a library from Libgdx. Unless it's something i'm missing?
UPDATE: Found the issue in detail.
GLSurfaceView$GLThread.class [in android.opengl [in C:\Users\me\AppData\Local\Android\android-sdk\platforms\android-8\android.jar]] does not exist

Solution:
An AtlasRegion was being called from the renderer class without being assigned a value in the assets class hence the null Exception
What is a NullPointerException, and how do I fix it?
changing that to a field that is declared solved this problem for me on the code side.
For the solution to the backend issue:
GLSurfaceView$GLThread.class [in android.opengl [in C:\Users\me\AppData\Local\Android\android-sdk\platforms\android-8\android.jar]] does not exist
I downloaded source codes from Google, and assigned the source code inside the SDK folder, C:\Users\me\AppData\Local\Android\android-sdk\sources\, if you don't already have a source folder create one, put the sources in there and it should reload the class that was being handled. (in this case GLSurfaceView.class for API 2.2)
Another way In Eclipse 4.4 (Luna) or any other eclipse I do believe, go onto your project folder right click > properties > java build path and assign the source file for android.jar in your dependent libraries.

Related

Google Guava getTopLevelClasses returns empty set

I've been searching around all over the internet to no avail. I am attempting to use Guava to get all the classes in a package of mine, but it is not behaving as intended. It always returns an empty set, making it impossible to do anything with the given results. Could there be a problem with System Variables, or some other road-block?
Here is some of my code.
String packageName = "me.travja.package";
ImmutableSet<ClassPath.ClassInfo> root = null;
try {
System.out.println(ClassPath.from(getClass().getClassLoader()));
root = ClassPath.from(getClass().getClassLoader()).getTopLevelClasses();//.getTopLevelClassesRecursive(packageName);
} catch (IOException e) {
e.printStackTrace();
}
for (ClassPath.ClassInfo info : root) {
System.out.println(info.getPackageName() + " -- " + info.getSimpleName());
}
It never hits the last sout because it's empty, but the one that prints the classpath prints 'com.google.common.reflect.ClassPath#33571c14' which isn't super useful. But to my knowledge, shouldn't that resemble more of my application's directory?
Thank you for your help with this. It's been bugging me for too long.
EDIT: I did some digging around. It seems that it works as intended if my file path doesn't contain a Space. I read a little that this used to be a problem with Guava in older versions, but I even tried using Maven and shading the latest version of Guava. Is there any way to fix this, or do I just have to be cautious that my file path never has a space in it?
After doing some more digging, one of the other dependencies that I was using had shaded an older version of Guava and that is what my code was using. As a result, it was broken. I used a decompiler so I could manually shade the ClassPath class from a newer Guava into my own code, and imported that. Works flawlessly now.

Exception: Unmarshalling unknown type code occurred at run time

I am working on Android app and we are working as a team. I am facing a serious issue. And that is when ever I try to get the data from intent it gives me following exception
Parcel android.os.Parcel#355932a: Unmarshalling unknown type code
4784211 at offset 712
I know on SO there are a lot of helping material related to this issue, but my case is different and quiet mind boggling .....
Here is a quick code to see how I am getting my object
try {
if (data.hasExtra("KEY_MY_MODEL")) {
MyCustomModel newSelectedModel = data.getParcelableExtra("KEY_MY_MODEL");
//DO SOME THING WITH OBJECT
}
} catch (Exception e) {
e.printStackTrace();
}
Case1:
I am getting exception on first line if (data.hasExtra("KEY_MY_MODEL")) {
and this is quiet funny because when I inspect the intent object (data) while debugging and if I look into intent object using debugging I can see all my custom object.
The keys of getting object are same, if in any case the key is wrong I think the code inside the if condition must not get run. as it will return false.
But instead of returning false it is giving the above mentioned exception.
Case2: As I told you we are working in team, the same set of code is running perfectly on other system, but when I run app from my system and install app on device, it is giving the exception I mentioned above.
This is very much frustrating. I think there is something wrong with proguard, as I read on S.O but its still not helpful. Any Idea why this is happening? This looks like a big bug.
Note: I am using A.S 3.5 and on other system A.S 3.5 is in use, even we have same set of sdk, configurations and other things are quiet
identical on both sides...
It seems to be a ProGuard issue
Just add this line in proguard.rules.pro/txt
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}

New value added to Java Enum not available during debug

I am having the following problem:
I have an Enum that was originally declared with 5 elements.
public enum GraphFormat {
DOT,
GML,
PUML,
JSON,
NEO4J,
TEXT {
#Override
public String getFileExtension() {
return ".txt";
}
};
Now I need to add an additional element to it (NEO4J). When I run my code or try to debug it I am getting an exception because the value can't be found in the enum.
I am using IntelliJ as my IDE, and have cleaned the cache, force a rebuild, etc.. and nothing happens. When I look at the .class file created on my target folder, it also has the new element.
Any ideas on what could be causing this issue ?
I found my problem and want to share here what was causing it. My code was actually for a Maven plug-in which I was pointing to another project of mine to run it as a goal. However the pom.xml of my target test project was pointing to the original version of the plug-in instead of the one I am working on, and that version of course is outdated and does not include the new value. Thank you.

JavaFX: Getting Stage of running Applications

For testing a application with TestFX i need to get the actual primary stage of a running application. This means that i haven't the code, i can just run the application through a jar.
Is there any possible solution for this? Scenic View does this already, but i was not able to reproduce this functionallity, especially because it seems that they use the deprecated funtion
Windows.impl_getWindows
which is not working in my case.
Try this:
import com.sun.javafx.robot.impl.FXRobotHelper;
static Collection<Stage> getAllJavaFXStages() {
try {
return FXRobotHelper.getStages();
} catch ( NullPointerException npe ) {
// nasty NPE if no stages exist
return Collections.emptyList();
}
}
```
Based on my own testing framework code: Automaton.
EDIT:
If you want to get a Stage from a different JVM instance than where you're running your code, then there's no simple way.
You're right, ScenicView does it, but it uses tools.jar to do it. This is not a standard jar you get in your runtime, so you must add it manually (placing it in jre/lib/ext should do it, you'll normally find it in lib only).
I tracked down the code where ScenicView seems to be doing it in their BitBucket repo.
Check the function getRunningJavaFXApplications for example.
Have fun using that in your tests!

Static Initialization on OpenCV Android [duplicate]

This question already has answers here:
OpenCV in Android Studio
(14 answers)
Closed 6 years ago.
i'm trying to run OpenCV Tutorial 1 - Add OpenCV with static initialization using this
i don't want a separate OpenCV Manager application installed) but i get an "OpenCV error: Cannot load info library for OpenCV."
I did the following things:
added a libs folder with armeabi, armeabi-v7a, and x86 folders inside of it (from OpenCV-2.4.2-android-sdk/sdk/native/libs/)
added the static {if (!OpenCVLoader.initDebug())} code just below private Sample1View mView;
removed the below code
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this,
mOpenCVCallBack))
what seems to be the problem?
You should add the code:
mOpenCVCallBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);
after:
if(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
If you remove:
if(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
code block then nobody calls.
Hope it can help you.
I have the same problem, I have solved the problem by adding the following code at the first of my Activity class:
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
}
}
Also I added
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
before the line
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
and commented the line
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
Good luck.
The log message:
"OpenCV error: Cannot load info library for OpenCV."
shuld not worry you. At least in my app it tells me something like OpenCV libs init is OK afterwards.
In the sample code the CameraBridgeViewBase object gets enabled when the BaseLoaderCallback gets called. That happens when the async loading of the opencv library has finished.
When you load the library statically, try adding a call to mOpenCVCameraView.enableView() in your onResume() method (after loading the lib of coourse).
initAsync() needs a callback to load opencv libs and your jni libs.
check the callback function and make it right in the if (!OpenCVLoader.initDebug()), not in the callback!
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
Log.i(TAG, "OpenCV load not successfully");
} else {
System.loadLibrary("mixed_sample");
//System.loadLibrary("my_jni_lib2");
InitFeature(width,height);
mOpenCvCameraView.enableView();
}
it works for the tutorial 2 in OCV4Android2.4.5.

Categories