Bluetooth server application using java WTK 2.5.2 crashes on launch - java

For the last few days, I've been developing an Android application which goal is to use the touch screen to move the cursor on my computer.
I've first implemented the communication between the mobile phone and my computer using WiFi. Everything is ok but I'd like to be able to use bluetooth.
On the phone side, everything is simple and easy. What I am not able to achieve is the bluetooth server.
I've downloaded and (painfully) installed the Java Wireless Toolkit 2.5.2 and the JavaSE jdk.
For now my code is very simple and looks like this :
import java.io.IOException;
import javax.bluetooth.*;
import javax.microedition.io.*;
public class BluetoothServer extends Thread {
//private static LocalDevice localDevice;
static LocalDevice localDevice;
DiscoveryAgent agent;
//start server
private StreamConnection startServer() throws IOException{
System.loadLibrary("zayit");
//Create a UUID for SPP
UUID uuid = new UUID(0x1101);
//Create the servicve url
String connectionString = "btspp://localhost:" + uuid +";name=SampleSPPServer";
//open server url
StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open( connectionString );
//Wait for client connection
System.out.println("\nServer Started. Waiting for clients to connect...");
StreamConnection connection = streamConnNotifier.acceptAndOpen();
return connection;
}
}
I've added external jars to get the import for javax.bluetooth and javax.microedition.
The project builds normally but When I launch it, it crashes with following error :
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xb27d6400, pid=25778, tid=2999303024
#
# JRE version: 6.0_24-b07
# Java VM: Java HotSpot(TM) Server VM (19.1-b02 mixed mode linux-x86 )
# Problematic frame:
# C [libzayit.so+0x23e400] kvm_resetOperandStack+0x8
#
# An error report file with more information is saved as:
# /home/ixm/workspace/RemoteControlServer/hs_err_pid25778.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
Without the System.loadLibrary(), I got following error:
Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: javax.microedition.io.Connector.isNetworkMonitorActive()Z
at javax.microedition.io.Connector.isNetworkMonitorActive(Native Method)
at javax.microedition.io.Connector.<clinit>(Connector.java:153)
at BluetoothServer.startServer(BluetoothServer.java:20)
at BluetoothServer.run(BluetoothServer.java:43)
I have no clue what I should do or try. I did not find anything helpful on the internet.
Can someone help me? Maybe the real question, is: "Is it possible to develop a Java application (for a computer) that use bluetooth?"
Thank you very much!
Best regards,
ixM

I've juste noticed that I installed the wrong version of Java (SE instead of ME). I will not try to install the right one since it is designed for mobile devices.
Instead, I will give it a shot with bluecove. I did not investigate that way before because I thought it was a python library for windows. Apparently, this is not the case and I was blind or stupid at the time I read the project page for the first time.
Sorry

Related

Run Java Jar within Python Google Cloud Function

I'm trying to port over some old Ruby code I used to run on Heroku to a Python-based Google Cloud Function.
This code runs Apple's Reporter tool which is "a command-line tool that you can use to download your Sales and Trends reports and Payments and Financial Reports". Docs can be found here.
The Ruby code worked well for years until yesterday, running on Heroku with a Ruby + Java build pack. A small snippet of this, where options are args received :
options = [
vendor_id,
file_type,
sub_file_type,
'Daily',
trimmed_date,
version
]
Dir.chdir("#{Rails.root}/tmp/") do
stdout, stderr, status = Open3.capture3("java -jar #{Rails.root}/public/jars/Reporter.jar p=Reporter.properties m=Robot.XML Sales.getReport #{options.join(', ')}")
return {:status => status, :error => stderr.to_s, :stdout => stdout.to_s }
end
The error I'm seeing on Heroku after no code or stack updates is Network is available but cannot connect to application. Check your proxy and firewall settings and try again.
Most of our other similar processes have been moved to Google Cloud Functions, so after getting nowhere with the above error I thought I'd move this also.
So a similar snippet this time in Python:
from subprocess import Popen, PIPE
def execute_reporter_jar(vendor_id, trimmed_date, file_type, api_version):
process = Popen(["java -jar Reporter.jar p=Reporter.properties Sales.getReportVersion Sales, Detailed"], stdin=PIPE, stdout=PIPE, shell=True)
out, err = process.communicate()
print("returncode = %s", process.returncode)
print("stdout = %s", out)
print("stderr = %s", err)
This works well locally, but when I deploy to Gooogle Cloud it seemingly runs successfully in a few ms, however, nothing actually happens and when I dig deeper it seems the subprocess is returning a 127 - command not found error. So it seems the cloud function can't access Java.
After a good 24hrs, I've hit a wall with this. Can anyone help? I have zero Java knowledge and I know cloud functions have a Java runtime, but I would prefer to stick with Python.
The ultimate aim is for Apple's reporter to run and save the requested file to Google Cloud Storage.
Thanks in advance!
The execution environment for Cloud Function's with Python runtime (both 3.7 and 3.8) is currently based in Ubuntu 18.04 (check the information in this link).
The runtime only includes the following system packages and running subprocess is usually not a recommended idea as the system packages included are limited.
If it's paramount for you to stick with Python you could try to deploy your function using the BuildPack CLI and extending the builder image to install Java on the Python runtime or if your application can be dockerized consider building an image yourself with Java included and deploying your application in Cloud Run.

Tesseract Fatal error encountered!" == NULL:Error:Assert failed:in file globaloc.cpp, line 75

1 - I downloaded tesdata on the git hub https://github.com/tesseract-ocr/tessdata
2 - Extract the folder and passed the path to the Tesseract class
3 - When running the application the following error is displayed
Extract the folder and passed the path to the Tesseract class
When running the application the following error is displayed
Code snippet executed
public class TesseractOcrTest {
private final String tesseractPath = "/home/tessdata/";
#Test
public void shouldReturnTrueIfRunOcrEquals() throws Exception {
String result = new TesseractOcr(tesseractPath).runOcr("bw_HighResolution_en.jpeg").trim();
assertEquals(
"Optical Character Recognition in Java\nis made easy with the help of Tesseract", result);
}
}
Error
Error: Illegal Parameter specification!
"Fatal error encountered!" == NULL:Error:Assert failed:in file globaloc.cpp, line 75
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f52a582d69b, pid=8957, tid=8966
#
# JRE version: OpenJDK Runtime Environment (11.0.7+10) (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
# Java VM: OpenJDK 64-Bit Server VM (11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C [libtesseract.so.4+0x25969b] ERRCODE::error(char const*, TessErrorLogCode, char const*, ...) const+0x16b
Note: When I change the path from tesdata to the OS installation path (private final String tesseractPath = "/usr/share/tesseract-ocr/4.00/tessdata/";) I can do it perfectly. It just doesn't work if I point to the tesdata downloaded from the git hub.
What am I doing wrong? When downloaded from github do you need to do any more configuration?
You've probably used incompatible language data. For the current Tesseract verion, use tessdata_best or tessdata_fast, which comes with Linux distros. (You can verify by checking the file size.)
https://github.com/tesseract-ocr
Make sure you have installed only one version of tesseract
Fist check with version of tesseract you used (installed). Use the latest version (4.x or 5 alpha)
Test OCR with tesseract executable instead of wrapper - it can provide more information for finding problem.

Fatal Error: Invalid Layout of java.lang.String at value

I got an extremely annyoing error in Eclipse (in the console):
Invalid layout of java.lang.String at value
A fatal error has been detected by the Java Runtime Environment:
Internal Error (javaClasses.cpp:129), pid=15238, tid=140306591237888
fatal error: Invalid layout of preloaded class
JRE version: 7.0_07-b10
Java VM: Java HotSpot(TM) 64-Bit Server VM (23.3-b01 mixed mode linux-amd64 compressed ops)
Failed to write core dump. Core dumps have been disabled. To enable core dumping, try ulimit -c unlimited" before starting Java again
An error report file with more information is saved as:
/home/till/workspace/Encrypt/hs_err_pid15238.log
If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp
Log Download
I cant't make any sense of this, because even Eclipse doesn't display any errors (in the code editor)...
This is a real productivity-killer, because it blocks all progress.
If anyone has any ideas on how to solve this, please answer this question.
Thank you really much in advance,
Till
In case of an Android project, you have to remove Android Lib from the launch configuration for that specific class. Use the "walkthrough" below as a guide.
Project->Properties->Run/Debug Settings;
Select your Class and click "Edit";
Open the tab "Classpath" and remove Android Lib from "Bootstrap Entries";
Apply everything and Run the class again.
I had same problem,then(as Jeff Schultz said here) I tried:
Run As -> Android Application
and problem solved.But I don't know the reason that causes this problem.I hope this help you!
This happened to me after:
Inserting a class in the Android Application project where I had forgotten to remove public static void main(String args[]) function. (Had previously performed a quick test of the class).
Tried to run the Application while I had opened and focused the above class on Eclipse editor.
The funny thing was that, after the Eclipse error, no matter on what class I switched the focus on, when I was trying to run the application again, I was stuck with the same error.
Inspired by Odyr Sohn solution, I managed to solve the problem (from Project->Properties->Run/Debug Settings deleting the faulty Launch configuration), but as soon as I was trying to run the application from this class, the same thing was happening again. When I removed public static void main(String args[]) function from the class, the problem was solved for good.
You should make a run configuration for an "Android application". If you make it for "Java Application" by mistake this error will show.
Same thing happened to me. I created a TestActivity and I guess it had a public static void main(String args[]) function. I went into the properties and then the Run/Debug and deleted TestActivity and it worked just fine.
I had the same problem, solved it by:
Run->Run Configurations;
Click on left on "Android Application"-> Button on top "New";
then type in a name and "Browse" the Project -> works!
I had a similar problem on the fatal error: Invalid layout of preloaded class with Kepler Service Release 1 using windows 7.
Project -> Properties -> Java Build Path -> Order and Export --> check mark any
unchecked library or Android version and then hit OK. Then run as Android application.

UnsatisfiedLinkError when trying to run Real time Java code on Websphere Real Time JVM on Linux

I'm trying to run real time java code using the Websphere Realtime Java VM on Ubuntu Linux 32 bit.
I could get the code to build, but for some reason the VM is unable to locate the native libraries that implement the javax.realtime classes and throws an UnsatisfiedLinkError. Any ideas on how to fix this will be appreciated.
import javax.realtime.*;
public class HelloRTWorld {
public static void main(String[] args) {
RealtimeThread rt = new RealtimeThread() {
public void run() {
System.out.println("Hello RT World");
}
};
rt.start();
}
}
This is the error trace:
Exception in thread "main" java.lang.UnsatisfiedLinkError: javax/realtime/RealtimeThread.putAsyncHandlerClassToThread(Ljava/lang/Class;)V
at javax.realtime.RealtimeThread.<clinit>(RealtimeThread.java:122)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:233)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at net.suhrid.HelloWorld.main(HelloWorld.java:9)
You don't need to put any jars on the command-line specifically, but you do need to run with -Xrealtime to activate real-time support.
You may also have trouble with the Ubuntu kernel not providing sufficient real-time performance (so WRT could fail to start with this option). The supported real-time operating systems are Red Hat's MRG and Novell SLERT.
I had exactly the same problem. I added to my project the realtime.jar library provided with Websphere IBM Realtime but couldn't make my script run (I got the same output in the console than you). Finally I added -Xrealtime in the VM Argumnets (in the Arguments tab of the Run Configurations menu) and succeed!

Java cannot resolve DNS address from AIX: UnknownHostException

I'm having this strange error.
On AIX, if I can reach my server from the command line ( using ping / telnet )
But If I try using java I've got UnkownHostException
This is due to Java cannot somehow "use" the DNS but I don't know why. If I use the IP address it works fine.
This is my test program.
import java.net.*;
public class Test {
public static void main( String [] args ) throws Exception {
String host = args[0];
int port = Integer.parseInt( args[1] );
System.out.println("Connecting to: " + host + " at port: " + port );
Socket socket = new Socket( host, port );
System.out.println("Connected!");
socket.close();
System.out.println("Closed!");
}
}
Is anyone aware of some kind of configuration under AIX that forbids programs ( like java ) to access DNS information?
I ( well the sysadm ) have added my address in /etc/hosts but it doesn't work either.
Thanks in advance
Java version:
Java(TM) 2 Runtime Environment, Standard Edition (build pap32dev-20080315 (SR7))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc-32 j9vmap3223-20080315 (JIT enabled)
I am having this problem as well. I have an number of java programs installed on Ubuntu64, and none of them can resolve domain names (there are multiple JRE's too - some of them are IBM products). If I put the domain name in the hosts file with the IP address, then it works for those domains only. Every other non java program works just fine with domain resolution. WEIRD!
If I find the answer, I will post it here. If you have the answer, help us please!
Java doesn't seem to respect the ordering of DNS lookups specified on the system. For example, on my Solaris system in /etc/nsswitch.conf I have defined:
hosts: files nis dns
Java want to go to dns first, which I don't understand. It seems like it's possible to change the ordering, by setting sun.net.spi.nameservice.provider.n properties.
One workaround I've found is to append a '.' at the end of a host name. For example, if in /etc/hosts, I have
192.168.1.1 mailhost
In my java app, I would specify InetAddress.getAllByName("mailhost.").
Setting the System property
sun.net.spi.nameservice.provider.1=dns,sun
fixed this problem for me on Ubuntu
Check if you need to use a proxy and if so specify its details on the command line
http://helpdesk.objects.com.au/java/how-to-tell-a-java-application-to-use-a-proxy-server
You have to check in the /etc/services files.
I had the same error and it was because the service:
domain ..........
was commented.

Categories