I'm developing a Django site with an applet Java.
Some days ago the applet start to fail loading in my chrome browser. I was still in developing and I tought that was a cache problem, so to test I started to use firefox.
At today the applet is developed at 90%, and on firefox works smoothy. No problems at all.
So I was working on some JS and I opened chrome (like its debugger), so I cleaned the chrome's cache folder and the java plugin cache, and I open the site.
The applet failed to load. Here is the error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at sun.applet.PluginAppletSecurityContext$5.run(PluginAppletSecurityContext.java:943)
at java.security.AccessController.doPrivileged(Native Method)
at sun.applet.PluginAppletSecurityContext.handleMessage(PluginAppletSecurityContext.java:940)
at sun.applet.AppletSecurityContextManager.handleMessage(AppletSecurityContextManager.java:70)
at sun.applet.PluginStreamHandler.handleMessage(PluginStreamHandler.java:235)
at sun.applet.PluginMessageHandlerWorker.run(PluginMessageHandlerWorker.java:78)
Caused by: java.lang.NumberFormatException: For input string: "0,000000"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1241)
at java.lang.Double.valueOf(Double.java:504)
at java.lang.Double.<init>(Double.java:597)
... 10 more
java.lang.NullPointerException
at sun.applet.PluginAppletViewer.getMember(PluginAppletViewer.java:1020)
at netscape.javascript.JSObject.getMember(JSObject.java:155)
at objects.CommunicationWithJS.parseFloors(CommunicationWithJS.java:75)
at main.MapGenerator.start(MapGenerator.java:27)
at sun.applet.AppletPanel.run(AppletPanel.java:476)
at java.lang.Thread.run(Thread.java:722)
The strange thing is that on Firefox works with no problems...
On loading, the applet calls some JS on the page to load a Json from the site.
This Json is than passed to the applet.
The communication between the applet and the page is managed by the netscape library.
The JS that loads the JSON:
function getFloors() {
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", GET_FLOORS, false );
xmlHttp.send(null);
var json = JSON.parse(xmlHttp.responseText);
return json;
}
And the code on the applet:
public Floor[] parseFloors(URL codebase) {
JSObject jsonFloors = (JSObject) window.eval(GET_FLOORS);
// counter of the number of objects
int i=0;
for (; i < 50; i++)
try {
if (jsonFloors.getSlot(i) == null)
break;
} catch (JSException jse) {
break;
}
Floor[] floors = new Floor[i];
for (int t=0; t < i; t++) {
JSObject jsonFloor = (JSObject) jsonFloors.getSlot(t);
try {
int numero_di_piano = Integer.parseInt(jsonFloor.getMember(NUMERO_DI_PIANO)+"");
URL link = new URL(codebase, jsonFloor.getMember(LINK).toString());
float bearing = Float.parseFloat(jsonFloor.getMember(BEARING).toString());
int id = Integer.parseInt(jsonFloor.getMember(ID).toString());
Floor floor = new Floor(numero_di_piano, link, bearing, id);
floors[t] = floor;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
return floors;
}
The error CommunicationWithJS.java:75 is in
int numero_di_piano = Integer.parseInt(jsonFloor.getMember(NUMERO_DI_PIANO)+"");
The value *NUMERO_DI_PIANO* returned from the server is an integer, I don't understand this strange behaviour.
EDIT:
I cross-tested the japplet with firefox and chrome, using some println.
It comes out that the exception shows up only when I try to extract from the Json an int value.
I succesfully extracted a double and a string.
On firefox the applet still working...
On chrome 0 becames "0,000000" and 4 becomes "4,000000".
ADDITION
I solved the problem forcing the server to convert the integers in strings.
But I don't think it's the correct way to work, it's a workaround.
So, if somebody can come out with a valid answer, I will assign the points.
This is not a complete answer, but based on the error you are getting and the similar issue we're running into loading the website detailed in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=647706 I believe the issue is related to the system locale. Is the system locale something different from en_US?
For a reason I haven't yet been able to understand, when running Java inside Firefox the locale does not influence the formatting methods, but on Chrome/Chromium it does, which leads to it generating locale-formatted floats ("0,0" instead of "0.0" in the Brazilian pt_BR locale, for instance) which Java can then not parse properly (presumably using a locale-independent conversion).
See also Problems using DecimalFormat
Related
I am testing around with PhantomJS a bit.
But I am not sure how to make it work with a java application, th examples I have found are mostly just against files or sites.
So this is what I have now.
var page = require('webpage').create();
address = "http://localhost:8080/logon.do";
page.open(address, function(status) {
wait(5000);
if (status !== 'success') {
console.log('Unable to access network');
} else {
var ua = page.evaluate(function () {
return document.getElementsByTagName('html')[0].outerHTML;
});
console.log(ua);
}
phantom.exit();
});
function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}
Now I know this wait is ugly but it is not important right now.
The server is running and if I go to the url I get a log in page.
I was expecting this log in page to be the output of console.log(ua);
Instead I get the output:
<-html><-head><-/head><-body><-/body><-/html>
What am I missing?
OK this turned out to be very secific for our application so lets close this.
Sascha, yes it is the script called by phantomjs which in turn
I have written a function which takes in a BufferedImage and compares it to a pre-existing image in my hard drive checking if they are same or not.
public boolean checkIfSimilarImages(BufferedImage imgA, File B) {
DataBuffer imgAdata = imgA.getData().getDataBuffer();
int sizeA = imgAdata.getSize();
BufferedImage imgB = null;
try {
imgB = ImageIO.read(B);
} catch (IOException ex) {
Logger.getLogger(SupportClass.class.getName()).log(Level.SEVERE, null, ex);
}
DataBuffer imgBdata = imgB.getData().getDataBuffer();
int sizeB = imgBdata.getSize();
if(sizeA == sizeB) {
for(int i = 0; i < sizeA; i++) {
if (imgAdata.getElem(i) != imgBdata.getElem(i)) {
return false;
}
}
}
return true;
}
This throws IOException "Cant read input file". Idk why this is happening. I am calling the function like this...
while(support.checkIfSimilarImages(currentDisplay, new File(pathToOriginalImage)) == false) {
System.out.println("Executing while-loop!");
bot.delay(3000);
currentDisplay = bot.createScreenCapture(captureArea);
}
where,
String pathToOriginalImage = "C:\\Users\\Chandrachur\\Desktop\\Home.jpg";
I can see that the path is valid. But as I am testing it for File.exists() or File.canRead() or File.absoluteFile().exists() inside the checkIfSimilarImages function and everything is returning false.
I have researched my question here and tried out these suggestions:
It is not only for this location, I have tried a variety of other locations but in vain. Also it is not a problem where I have hidden file extensions and the actual file might be Home.jpg.jpg .
The only thing that might be is that permissions might be different. I dont really know how to verify this, but there is no reason it should have some permission which is not readable by java. It is just another normal jpg file.
Can it be because I am passing the file object reference into a function so in this process somehow the reference is getting modified or something. I just dont know. I am running out of possibilities to test for...
The whole stack trace is as follows:
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at battlesbot.SupportClass.checkIfSimilarImages(SupportClass.java:77)
at battlesbot.AutomatedActions.reachHomeScreen(AutomatedActions.java:72)
at battlesbot.BattlesBot.main(BattlesBot.java:22)
Exception in thread "main" java.lang.NullPointerException
at battlesbot.SupportClass.checkIfSimilarImages(SupportClass.java:81)
at battlesbot.AutomatedActions.reachHomeScreen(AutomatedActions.java:72)
at battlesbot.BattlesBot.main(BattlesBot.java:22)
C:\Users\Chandrachur\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 11 seconds)
I am on Windows 10, IDE is NetBeans.
UPDATE:
Huge thanks to #k5_ . He told me to paste this in path and it worked.
"C:/Users/Chandrachur/Desktop/Home.jpg";
It seems some invisible characters were in the path. But I still don't understand what that means.
Usually this kind of problem lies with access problem or typos in the filename.
In this case there were some invisible unicode characters x202A in the filename. The windows dialog box, the file path was copied from, uses them for direction of writing (left to right).
One way of displaying them would be this loop, it has 4 invisible characters at the start of the String. You would also see them in a debugger.
String x = "C:\\Users\\Chandrachur\\Desktop\\Home.jpg";
for(char c : x.toCharArray()) {
System.out.println( c + " " + (int) c);
}
I'm using netbeans IDE for developing java desktop application with Vdurmont emoji-java2.0.1 Emoji library. Its working with my netbeans IDE development and sent emojis unicode another side its working fine (Showing fine and correct emoji with emotions). Problem: When i clean build and make a .jar with all necessary lib,
it showing this (😡 and ?) on another side web app Vdurmont emoji-java2.0.1 library didn't load or not working with myemojiapp.jar file. *please let me know if any need for this ?..
Object finalmsz = "";
msz = jtp.getText();
MyHtml2Text parser = new MyHtml2Text();
try {
parser.parse(new StringReader(msz));
} catch (IOException ee) {
//handle exception my exp
}
finalmsz = Imoji.parseToUnicode(parser.getText() + str);**
public static String parseToUnicode(String input) {
String result = input;
for (Emoji emoji : EmojiManager.getAll()) {
result = result.replace(emoji.getHtmlHexidecimal(),emoji.getUnicode());
}
return result;
}
Please note this parsing not working with my myemojiapp.jar file (showing this 😡 and ?)
but it works fine on my netbeans during development.
While there are several questions regarding tray selection out there, none of them relate to my problem.
Here's the code I'm using to print:
private static void finalPrint(PDDocument pdoc, boolean pbStationary)
throws BigBangJewelException
{
PrintService lrefSvc;
PrinterJob lrefPJob;
Media lrefMedia;
HashPrintRequestAttributeSet lobjSet;
lrefSvc = getPrinter();
lrefPJob = PrinterJob.getPrinterJob();
try
{
lrefPJob.setPrintService(lrefSvc);
lrefPJob.setPageable(pdoc);
lrefMedia = null;
if ( pbStationary )
lrefMedia = getTray(lrefSvc);
if ( lrefMedia != null )
{
lobjSet = new HashPrintRequestAttributeSet();
lobjSet.add(lrefMedia);
lrefPJob.print(lobjSet);
}
else
lrefPJob.print();
}
catch (Throwable e)
{
throw new BigBangJewelException(e.getMessage(), e);
}
}
private static PrintService getPrinter()
throws BigBangJewelException
{
String lstrPrinter;
PrintService[] larrServices;
int i;
try
{
lstrPrinter = (String)Engine.getUserData().get("Printer");
larrServices = PrinterJob.lookupPrintServices();
for ( i = 0; i < larrServices.length; i++ )
{
if (larrServices[i].getName().indexOf(lstrPrinter) != -1)
return larrServices[i];
}
}
catch (Throwable e)
{
throw new BigBangJewelException(e.getMessage(), e);
}
throw new BigBangJewelException("Impressora definida (" + lstrPrinter + ") não encontrada.");
}
private static Media getTray(PrintService prefSvc)
{
Media[] larrMedia;
String lstrAux;
int i;
larrMedia = (Media[])prefSvc.getSupportedAttributeValues(Media.class, null, null);
if ( larrMedia == null )
return null;
for ( i = 0; i < larrMedia.length; i++ )
{
lstrAux = larrMedia[i].toString().toLowerCase();
if (lstrAux.contains("tray") && lstrAux.contains("3"))
{
return larrMedia[i];
}
}
return null;
}
The baffling thing is, this code used to work. The machine had a bunch of Xerox printers defined, and the code would correctly identify the wanted printer, and the wanted tray, and everything worked wonderfully.
Then, one day, overnight, it stopped working. It still finds the right printer, but now, it always prints to tray 1.
The only thing that changed was that an extra HP printer was added to the machine.
I can confirm that the code is finding the tray and sending it to the print job, but it's getting ignored.
Again, there are many questions out there regarding this issue, but my problem is that the code worked well for four years, then stopped working for no apparent reason.
Can anyone shed any light on this subject?
Edit: New information: Uninstalling the HP printer made the Xerox printers work right again. Why would installing one driver affect Java's ability to communicate with a different driver?
Edit 2: Further information: If we install the HP global printer driver instead of the specific printer driver, everything works correctly. I'll leave the question unanswered to see if anyone can come up with a good explanation before the bounty expires, then I'm going to put this edit in an answer and accept it.
If I got you question correctly, you the content of lobjSet is unchanged, yet it the print result is different, with the new driver installed.
I checked the code for PnterJob.print(PrintRequestAttributeSet) and was surprised that it completely ignores the attribute set.
So I looked at where the PrintService is coming from, the code is a little lengthy, but I guess it interacts somehow with the installed printer drivers to create appropriate instances. So the new driver changes this, returning a different PrintService. There is no way I can tell in what exact way this thing changes, but if you can recreate both scenarios (and it seems you can), it should be fairly easy to use a debugger to find the exact place where the behavior of the code changes.
The solution to our particular situation was to change the printer drivers for the HP printer.
Originally, we had installed the specific driver for the printer in question, which caused this behavior. Installing HP's global driver instead made the problem go away.
Unfortunately, we do not know why. Jens Schauder's answer contains clues as to how to go about finding out.
I'm using grph library for a university project (www.i3s.unice.fr/~hogie/grph/)
but i have a problem only on Linux with that library, when i create a new Graph object, i receive the following exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.elendev.wesproject.graph.GraphFactory.main(GraphFactory.java:19)
Caused by: java.lang.NullPointerException
at toools.os.OperatingSystem.getLocalOS(OperatingSystem.java:47)
at grph.Grph.setCompilationDirectory(Grph.java:353)
at grph.Grph.<clinit>(Grph.java:246)
... 1 more
I tried to call directly getLocalOS function, with:
System.out.println(toools.os.OperatingSystem.getLocalOS());
and i receive the same exception. I cannot find information about that library, and the project launched on a macbook works perfectly.
The operating system i'm currently using is gentoo linux 32bit.
And the jdk version is: 1.7.0_65
Any idea of what could be the problem?
Not sure whether this can count as an answer, but it could at least help to solve the issue:
The exception comes from the toools.os.OperatingSystem.getLocalOS method. Although the .JAR file from the website that you mentioned has a whopping 39 megabytes, the source code of this class is not contained in it.
There seems to be no information available about this class at all. Neither Google nor Maven finds anything related to the toools package. One has to assume that it is an abandoned utility class that passed away a long time ago.
However, the method in question can be disassembled to the following code:
public static OperatingSystem getLocalOS()
{
if (localOS == null)
{
if (new RegularFile("/etc/passwd").exists())
{
if (new Directory("/proc").exists())
{
if (new RegularFile("/etc/fedora-release").exists()) {
localOS = new FedoraLinux();
} else if (ExternalProgram.commandIsAvailable("ubuntu-bug")) {
localOS = new UbuntuLinux();
} else {
localOS = new Linux();
}
}
else if (new Directory("/Applications").exists()) {
localOS = new MacOSX();
} else {
localOS = new Unix();
}
}
else if (System.getProperty("os.name").startsWith("Windows")) {
localOS = new Windows();
} else {
localOS = new OperatingSystem();
}
localOS.name = System.getProperty("os.name");
localOS.version = System.getProperty("os.version");
}
return localOS;
}
From this, you can possibly derive the conditions that must be met in order to properly detect your OS as a linux OS. Particularly, when there is a file named /etc/passwd, and a directory /proc, this should be sufficient to identify the OS as a Linux. You may want to give it a try...