null pointer exception when programming for android phone from processing IDE - java

i am relatively new to java programming and programming for android and have been experimenting with android bluetooth comms using the Ketai library for the processing IDE specifically for use with android and tried to run the example program bluetoothcursors.pde that comes with the library but i keep getting the "application has stopped unexpectedly" error and the console indicates a null pointer exception error. The actual output is below:
FATAL EXCEPTION: Animation Thread
java.lang.NullPointerException
at ketai.net.bluetooth.KBluetoothListener.<init>(KBluetoothListener.java:56)
at ketai.net.bluetooth.KetaiBluetooth.start(KetaiBluetooth.java:207)
at processing.test.bluetoothcursors.BluetoothCursors.setup(BluetoothCursors.java:80)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:1019)
However i cant seem to see where the null pointer exception is coming from. I assume the null pointer exception relates to a variable that has not been instantiated properly. I have tried a process of elimination to try and isolate the cause but i get the same error but with slightly different source. I have also posted this question on the processing forum but have not received a reply. I just assumed that since it was part of the examples for the library it would work so maybe the error is being created somewhere else. I have tried other library examples and theses all work fine so i dont think its my setup. I also have other bluetooth programs working on android from processing but these use pure java code and are harder to follow.
I have had a look at some of the similar questions which have been sort-of helpful but i am still stuck.
I have set the correct bluetooth etc permissions and am using android version 2.3.3 and processing version 2.0.
Any help with this is much appreciated.
Cheers.

Related

Getting "Could not initialize class sun.security.ec.SunEC" How to Proceed?

After coming back to a part of my code base that hadn't been touched for a few weeks, I got the rather terse message: "Could not initialize class sun.security.ec.SunEC" from my functional REST test cases.
I'm not making much progress figuring out how tackle this one, there's no other error information (no stack trace) and not much on the Internet. I expect an update has changed something since everything was working.
Does anyone have any suggestions or insight for fixing this one?
Ubuntu 16.10
Java 8, Oracle, "1.8.0_131"
The problem was caused by a missing library libsunec.so. I was using the alpine docker container V3.4 which contained the library, but when I upgraded to V3.5, a "glich" in my build process actually had me still using V3.4. When that was indirectly "fixed," and I unknowingly started using V3.5, the error was suddenly, and confusingly, uncovered because libsunec.so was left out of alpine V3.5. See: https://bugs.alpinelinux.org/issues/6809

haarcascade_frontalface_alt.xml not working

I am currently working on a java project on face detection. I am using OpenCV API opencv_310 available at the official site and started writing the program following
this tutorial
But the main problem is that this tutorial was written more than five years ago. So the OpenCV APIs and working procedures have changed over the years. So I encountered a problem regarding the file haarcascade_frontalface_alt.xml.
new CvHaarClassifierCascade(cvLoad(FACE_CASCADE_PATH));
This line of code throws the following exception:
OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file ........\opencv\modules\core\src\persistence.cpp, line 4991
Exception in thread "main" java.lang.RuntimeException: ........\opencv\modules\core\src\persistence.cpp:4991: error: (-2) The node does not represent a user object (unknown type?) in function cvRead
So I browsed the Internet for a while and found this. It says the old C API does not support the newer haarcascade format. It also suggests to try with the C++ API.
What should I do now? I don't know how to try the C++ API. It will be highly appreciable if you can give some instructions on how to deal with the problem.
Thanks.
Try checking this tutorial which is from opencv site. This has a link to the source code. The xml file which you have trouble is the trained data.. if you would like to just download this file, you can find it here
regards

Thread.setDefaultUncaughtExceptionHandler for Errors

I am working on an Android app where for uncaught exceptions I do this
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()...);
This way when an uncaught exception is thrown I log it and send a request to my issue tracker to create a new issue. I would like to do the same for errors. Is there a way to intercept uncaught errors in Java or Android? I have combed through stackoverflow and Google and have not found anything.
After comments on the functionality of this and the fact that I was not able to find any info regarding this, and not being able to find and info related to this, I did some testing and it does in fact get called when an error is thrown as well. The name is misleading but it does in fact work with errors as well. Thanks to the comments for the guidance.

Exception in VOCE sample C++ app

I've been playing around with the C++ api of Voce for speech recognition in one of my projects. So far, I've been able to compile the C++ version of one of the sample apps provided by Voce named recognitionTest (provided under the samples directory in voce-0.9.1).
However, when I try running recognitionTest.exe, I hit an IndexOutOfBoundsException (console output is provided below).
[Voce] Java virtual machine created
[Voce] Initializing recognizer. This may take some time...
[Voce] Initialization complete
This is a speech recognition test. Speak digits from 0-9 into the microphone. Speak 'quit' to quit.
Exception in thread "Recognition thread" java.lang.IndexOutOfBoundsException: Index: 110,Size: 109
at java.util.SubList.rangeCheck(Unknown Source)
at java.util.SubList.get(Unknown Source)
at edu.cmu.sphinx.decoder.scorer.ScoreableJob.getFirst(ThreadedAcousticScorer.java:516)
at edu.cmu.sphinx.decoder.scorer.ThreadedAcousticScorer.scoreScoreables(ThreadedAcousticScorer.java:310)
at edu.cmu.sphinx.decoder.scorer.ThreadedAcousticScorer.calculateScores(ThreadedAcousticScorer.java:276)
at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.scoreTokens(SimpleBreadthFirstSearchManager.java:337)
at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.recognize(SimpleBreadthFirstSearchManager.java:258)
at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.recognize(SimpleBreadthFirstSearchManager.java:226)
at edu.cmu.sphinx.decoder.Decoder.decode(Decoder.java:94)
at edu.cmu.sphinx.recognizer.Recognizer.recognize(Recognizer.java:116)
at edu.cmu.sphinx.recognizer.Recognizer.recognize(Recognizer.java:135)
at voce.SpeechRecognizer.run(SpeechRecognizer.java:129)
at java.lang.Thread.run(Unknown Source)
I'm using Windows 8 and 32-bit version of java 1.5.
Question: Has someone encountered a similar error before? The exception seems to be thrown by the underlying cmusphinx library. So, I'm unable to debug the issue.
Any help would be greatly appreciated!
Please let me know if any additional info would be helpful in figuring out the issue.
Thanks in advance!

Is there any general rule of thumb for what would cause an "EXCEPTION_ACCESS_VIOLATION (0xc0000005)"?

I have searched the internet for an answer to what could be causing "EXCEPTION_ACCESS_VIOLATION (0xc0000005)" in java but I couldn't find anything beyond reinstall your jvm. I know that it is a problem with my code, what in my code could cause this?
This exception always occurs directly after I have Created a Database Connection, and it always has to do with ntdll.dll.
This means that there was a crash, probably a null pointer access, in native code (C or C++) loaded by Java, in this case, probably a database driver. If you have access to the source code for the native library, you can try debugging it by attaching a native debugger (like Visual Studio) to the Java process before the crash occurs. Otherwise, you'll need to report a bug to whoever wrote the buggy native code. Note that it may not technically be a "bug" in the native code. It could be that your code is passing in a bad parameter and they're just not handling error checking very well.
Looks like a bug in the JVM or the database driver or both. Maybe a different version will work?

Categories