How can I serialize a HashMap with BitMatrix objects? (QR Codes / zxing) - java

I have a "static class" called QRGenerator, whose purpose is to generate BitMatrix objects and to generate BufferedImage objects from them. This is the code for it:
package ericsonwrp.republica.vintage.caixa;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.EnumMap;
import java.util.Map;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class QRGenerator {
private static BufferedImage image = null;
private static int size = 250;
private static BitMatrix byteMatrix = null;
public static BitMatrix generateBitMatrix(String codeText) {
try {
Map<EncodeHintType, Object> hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hintMap.put(EncodeHintType.MARGIN, 1);
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
byteMatrix = qrCodeWriter.encode(codeText, BarcodeFormat.QR_CODE, size,
size, hintMap);
} catch (WriterException e) {
e.printStackTrace();
}
return byteMatrix;
}
public static BufferedImage generateImage(BitMatrix byteMatrix) {
int width = byteMatrix.getWidth();
image = new BufferedImage(width, width,
BufferedImage.TYPE_INT_RGB);
image.createGraphics();
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, width, width);
graphics.setColor(Color.BLACK);
for (int i = 0; i < width; i++) {
for (int j = 0; j < width; j++) {
if (byteMatrix.get(i, j)) {
graphics.fillRect(i, j, 1, 1);
}
}
}
return image;
}
}
I have another class called "RepublicaVintageFile", whose purpose is to define an unique file to store the "content" of my application, and to provide a method to serialize (And read, which is irrelevant for the question) this "content". This is the code for it:
package ericsonwrp.republica.vintage.caixa;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.HashMap;
public class RepublicaVintageFile {
private HashMap<String, Object> content;
public RepublicaVintageFile() {
setContent(new HashMap<String, Object>());
}
public void serializeContent(String path) throws IOException {
FileOutputStream fout = new FileOutputStream(path, true);
ObjectOutput out = null;
try {
out = new ObjectOutputStream(fout);
out.writeObject(getContent());
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException ex) {
// ignore close exception
}
try {
fout.close();
} catch (IOException ex) {
// ignore close exception
}
}
}
public HashMap<String, Object> getContent() {
return content;
}
public void setContent(HashMap<String, Object> content) {
this.content = content;
}
}
The "content" of my application include BitMatrix objects, which are saved under a label inside a HashMap in a different file (private HashMap<String, BitMatrix> qrItems;). Since serializing the final BufferedImage gives me a java.io.NotSerializableException, I've tried to serialize the BitMatrix objects. But, for my disappointment, that's also impossible. This is the stacktrace:
java.io.NotSerializableException: com.google.zxing.common.BitMatrix
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at java.util.HashMap.internalWriteEntries(Unknown Source)
at java.util.HashMap.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at java.util.HashMap.internalWriteEntries(Unknown Source)
at java.util.HashMap.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at ericsonwrp.republica.vintage.caixa.RepublicaVintageFile.serializeContent(RepublicaVintageFile.java:26)
at ericsonwrp.republica.vintage.caixa.MainFrame.openSaveAsDialog(MainFrame.java:204)
at ericsonwrp.republica.vintage.caixa.MainFrame.access$1(MainFrame.java:177)
at ericsonwrp.republica.vintage.caixa.MainFrame$4.actionPerformed(MainFrame.java:112)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Considering all this, I come to my question: How can I serialize a HashMap with BitMatrix objects? That's important, because I don't want to store 100 (Or more) separate .png files on a folder and have to read the images all the time in order to get their content.

I've managed to "save" and "load" the BitMatrix objects translating them into boolean 2-dimensional arrays.
private HashMap<String, BitMatrix> qrMatrixes;
private HashMap<String, boolean[][]> qrMatrixBooleanArrays;
As you can see, I have a HashMap of < String, BitMatrix >, with an equivalent in boolean[][] format. That's how I make such "translation" (Transferring the bits from each BitMatrix objects to the boolean[][] arrays):
for (Map.Entry<String, BitMatrix> e : getQrMatrixes().entrySet()) {
boolean[][] b = new boolean[e.getValue().getHeight()][e.getValue().getWidth()];
for (int j = 0; j < e.getValue().getHeight(); j++) {
for (int k = 0; k < e.getValue().getWidth(); k++) {
b[j][k] = e.getValue().get(j, k);
}
}
qrMatrixBooleanArrays.put(e.getKey(), b);
}
Java's Serializer serializes such object (HashMap< String, boolean[][] >) with no problems, no matter how nested it is (I've imagined that it would work with primitive types, with an old-fashioned array). Here's the whole method to update the list with the QR Codes, after loading the file:
public void updateList() {
if (MainFrame.getCurrentFile() != null) {
setQrMatrixes(new HashMap<String, BitMatrix>());
setQrMatrixBooleanArrays(new HashMap<String, boolean[][]>());
for (Map.Entry<String, boolean[][]> e : ((HashMap<String, boolean[][]>) MainFrame.getCurrentFile().getContent().get("Qr Codes")).entrySet()) {
getQrMatrixBooleanArrays().put(e.getKey(), e.getValue());
}
for (Map.Entry<String, boolean[][]> e : getQrMatrixBooleanArrays().entrySet()) {
BitMatrix b = new BitMatrix(e.getValue().length, e.getValue().length);
for (int i = 0; i < e.getValue().length; i++) {
for (int j = 0; j < e.getValue()[i].length; j++) {
if (e.getValue()[i][j] == true) {
b.set(i, j);
}
}
}
getQrMatrixes().put(e.getKey(), b);
qrListModel.addElement(e.getKey());
}
} else {
System.out.println("No file is loaded.");
}
}
I'm afraid it's a bit hard to be more clear. Explore the docs for the BitMatrix object, and just copy the contents into a primitive 2d array. Good luck!

Related

Why do I need to reset setText() in a JLabel to prevent errors?

As a follow-up to this question that I posted earlier, I am wondering about the cause of the issue I had.
The problem was that I was getting this error when updating a JLabel with a lot of HTML text.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.html.StyleSheet$ListPainter.paint(Unknown Source)
at javax.swing.text.html.ListView.paintChild(Unknown Source)
at javax.swing.text.BoxView.paint(Unknown Source)
at javax.swing.text.html.BlockView.paint(Unknown Source)
at javax.swing.text.html.ListView.paint(Unknown Source)
at javax.swing.text.BoxView.paintChild(Unknown Source)
at javax.swing.text.BoxView.paint(Unknown Source)
at javax.swing.text.html.BlockView.paint(Unknown Source)
at javax.swing.text.BoxView.paintChild(Unknown Source)
at javax.swing.text.BoxView.paint(Unknown Source)
at javax.swing.text.html.BlockView.paint(Unknown Source)
at javax.swing.text.BoxView.paintChild(Unknown Source)
at javax.swing.text.BoxView.paint(Unknown Source)
at javax.swing.text.html.BlockView.paint(Unknown Source)
at javax.swing.plaf.basic.BasicHTML$Renderer.paint(Unknown Source)
at javax.swing.plaf.basic.BasicLabelUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
The HTML that's being set is generated by a StringBuilder and the converted .toString. Something like this, but more extensive:
public static String entityOverviewHTML() {
StringBuilder sb = new StringBuilder();
List<Entity> entities = Entity.getEntities();
sb.append("<html><div style='padding: 12px;'>");
sb.append("<h1>People: alive</h1>");
// A lot of appending: also loop through getEntities (dynamic, can change)
// and get contents from each entity in #getEntityInfo below
if (entities.size() > 0) {
sb.append("<ul>");
for (Entity e: entities) {
getEntityInfo(e);
}
sb.append("</ul>");
}
sb.append("</div></html>");
return sb.toString();
}
private static StringBuilder getEntityInfo(Entity e) {
StringBuilder sbInfo = new StringBuilder();
// A lot of appending: append info of Entity e such as e.getFirstName()
sbInfo.append("<li>");
sbInfo.append(e.getFirstName())
sbInfo.append("</li>");
return sbInfo;
}
After some events, the HTML will change after which I call a custom refresh method:
public static void bringToFront() {
getInstance().setVisible(true);
getInstance().setExtendedState(JFrame.ICONIFIED);
getInstance().setExtendedState(JFrame.NORMAL);
}
public static void refresh() {
// text is a JLabel
text.setText(entityOverviewHTML());
bringToFront();
}
And it's then that the errors at the top of this post happen, however not always! I haven't figured out why this happens, but I did find that when resetting the text to an empty string and then calling entityOverviewHTML solves the issue.
public static void refresh() {
text.setText(""); // Here we go
text.setText(entityOverviewHTML());
bringToFront();
}
text is defined as a Class variable:
private static JLabel text = new JLabel();
What I like to know is: why? How can this single line of seemingly obsolete code solve the problem? Exactly what is the problem?
The problem is that your refresh() method is not called on the Swing EDT.
Swing is not threadsafe (https://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html) which means that the call text.setText(entityOverviewHTML()); corrupts the internal data structures that your JLabel instance uses to display the text.
Your refresh-method needs to be rewritten like this:
public static void refresh() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
text.setText(entityOverviewHTML());
bringToFront();
}
});
} catch (InvocationTargetException | InterruptedException e) {
e.printStackTrace();
}
}
Usually when JLabel is instantiated, it has no width , if it is instantiated with empty text width is zero. When JLabel text is updated it won't show up as its size is not set properly.
Use preferred size: text.setPreferredSize(new Dimension(x, y)); then text.setText(html)

Speech Recognition jar throwing error on its execution Grammar class not found

I have created a jar of my project on Speech Recognition in JAVA through Sphinx. My code is executing perfectly but when I am creating its jar through "runnable jar file->copy required libraries into sub folder", and executing it through cmd with command " java -jar {jar name}.jar" it opens but after selecting the speak button or invoking sphinx method it gives error edu.cmu.sphinx.jsapi.JSGFGrammar class not found.
I am not getting any way how to resolve this.
my speech to text code is:
package com.ongraph;
import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;
public class SpeechToTextOperation {
ConfigurationManager cm;
SpeechRecognizer speechRecognizer;
Result result;
Recognizer recognizer;
Microphone microphone;
private final static String STOP = "stop";
private final static String XML_FILE = "helloworld.config.xml";
public void voiceGet() throws InterruptedException {
String resultString = null;
int count_Check = 0;
if (cm == null) {
cm = new ConfigurationManager(getClass().getClassLoader().getResource(XML_FILE));
}
if (recognizer == null) {
recognizer = (Recognizer) cm.lookup("recognizer");
microphone = (Microphone) cm.lookup("microphone");
microphone.clear();
}
recognizer.allocate();
if (!(microphone.startRecording())) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
instructions();
//SpeechRecognizer.please_Speak.setVisible(true);
while (true) {
System.out
.println("Start speaking. Speak 'Stop' to Stop Recording.");
if(count_Check == 0)
{
SpeechRecognizer.textArea.append("\n Start speaking...\n");
count_Check++;
}
Result result = recognizer.recognize();
resultString = result.getBestFinalResultNoFiller();
if (resultString != null && !"".equals(resultString)
&& !resultString.contains(STOP)) {
SpeechRecognizer.textArea.append(resultString + "\n");
} else {
SpeechRecognizer.textArea
.append("'Application Stopped. Press 'Speak' again to restart'");
recognizer.deallocate();
microphone.stopRecording();
break;
}
}
}
public void voiceStop() {
microphone.clear();
cm = null;
}
public void instructions() {
// TODO Auto-generated method stub
SpeechRecognizer.please_Speak.setVisible(true);
}
}
errors in cmd are:
class not found !java.lang.ClassNotFoundException: edu.cmu.sphinx.jsapi.JSGFGrammar
Exception in thread "AWT-EventQueue-0" Property Exception component:'flatLinguist' property:'grammar' - mandatory property is not set!
edu.cmu.sphinx.util.props.InternalConfigurationException
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:291)
at edu.cmu.sphinx.linguist.flat.FlatLinguist.newProperties(FlatLinguist.java:246)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:279)
at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.newProperties(SimpleBreadthFirstSearchManager.java:179)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:279)
at edu.cmu.sphinx.decoder.AbstractDecoder.newProperties(AbstractDecoder.java:65)
at edu.cmu.sphinx.decoder.Decoder.newProperties(Decoder.java:37)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:279)
at edu.cmu.sphinx.recognizer.Recognizer.newProperties(Recognizer.java:90)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:460)
at edu.cmu.sphinx.util.props.ConfigurationManager.lookup(ConfigurationManager.java:161)
at com.ongraph.SpeechToTextOperation.voiceGet(SpeechToTextOperation.java:24)
at com.ongraph.SpeechRecognizer$1.actionPerformed(SpeechRecognizer.java:50)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Overall it's better to use latest version 5prealpha and the API described at http://cmusphinx.sourceforge.net/wiki/tutorialsphinx4
As for your exception, it says that class is not found. You need to pack that class into jar in order to run your code. There could be also a difference in package name. Recently edu.cmu.sphinx.jsapi package was renamed to edu.cmu.sphinx.jsgf. You might have issues to update that.

what ( com.microsoft.sqlserver.jdbc.SQLServerException:The index 0 is out of range )exception means

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.PrintWriter;
import java.sql.*;
import java.net.*;
public class connection {
JTextField textfeild;
JButton button;
String text;
Socket sock;
PrintWriter writer;
JButton button1;
public static void main(String[] args) {
connection user1 = new connection();
user1.go();
}//main method close
public void go() {
JFrame frame12 = new JFrame();
JPanel centerpanel12 = new JPanel();
centerpanel12.setLayout(new BoxLayout(centerpanel12, BoxLayout.Y_AXIS));
textfeild = new JTextField(20);
centerpanel12.add(textfeild);
//textfeild.addActionListener(new textfeildlitner());
frame12.add(centerpanel12);
button = new JButton("Click Me");
centerpanel12.add(button);
button.addActionListener(new buttonlitner());
button1 = new JButton("DataDisplay");
centerpanel12.add(button1);
button1.addActionListener(new buttonlitner1());
frame12.getContentPane().add(BorderLayout.CENTER, centerpanel12);
frame12.pack();
frame12.setVisible(true);
frame12.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//go method close
/*class textfeildlitner implements ActionListener{
public void actionPerformed(ActionEvent ev){
}
}//inner class textfeildlitner close*/
class buttonlitner implements ActionListener {
public void actionPerformed(ActionEvent ev) {
button.setText("I AM Clicked");
String name = textfeild.getText();
System.out.println(name);
textfeild.setText("");
textfeild.requestFocus();
}//method close
}//inner class close
class buttonlitner1 implements ActionListener {
void connection() {
try {
String user = "SQlUI";
String pass = "123456";
String db = "jdbc:sqlserver://localhost:1234;" + ";databaseName=SQlUI";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(db, user, pass);
Statement s1 = con.createStatement();
ResultSet r1 = s1.executeQuery("select * from Table_1");
String[] result = new String[20];
if (r1 != null) {
while (r1.next()) {
for (int i = 0; i < result.length; i++) {
for (int j = 0; j < result.length; j++) {
result[j] = r1.getString(i);
System.out.println(result[j]);
break;
}//for j close
}//for i close
}//if closeclose
}//try close
} catch (Exception ex) {
ex.printStackTrace();
}//catch close
}//connection() close
public void actionPerformed(ActionEvent ev) {
button1.setText("Processing");
new buttonlitner1().connection();
}//method close
}//inner class close
}//outer class close
And the exception which i am getting for this code-
com.microsoft.sqlserver.jdbc.SQLServerException: The index 0 is out of range.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyValidColumnIndex(SQLServerResultSet.java:531)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(SQLServerResultSet.java:2049)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:2082)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:2067)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getString(SQLServerResultSet.java:2392)
at connection$buttonlitner1.connection(connection.java:76)
at connection$buttonlitner1.actionPerformed(connection.java:89)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
When i am changing the value of i from 0 to 1 then it displays result for 1st row but again it throws exception saying that the index 3 is out of range.
I have posted the same code and after making the changes (as suggested by the experts on stackoverflow) it gave me a new type of exception.
I am putting the link of the previous question-Getting Checked Exception while running a SQL Program and the question was Getting Checked Exception while running a SQL Program
In SQL (unlike generally in Java) evrything is indexed starting from 1 - both rows and columns.
Why do you have 2 loops inside your r1.next() loop?
Think what your code
for (int j = 0; j < result.length; j++) {
result[j] = r1.getString(i);
System.out.println(result[j]);
break;
}
actually does.

Applet runs in eclipse but not in browser - java security

Below is applet code, it uses jna.jar (https://github.com/twall/jna) to access a DLL file in system32.
import javax.swing.*;
import javax.print.*;
import java.security.*;
import java.util.ArrayList;
import com.sun.jna.Library;
import com.sun.jna.Native;
import java.awt.*;
import java.awt.event.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;
import com.sun.jna.win32.StdCallLibrary;
public class CallApplet extends JApplet implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 4654357272074276081L;
static JTextField output;
private final String ButtonText = "Print";
public void init() {
Container contentHolder = getContentPane();
contentHolder.setLayout(new BorderLayout(18,18));
output = new JTextField(20);
//add(output);
contentHolder.add(output, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
JButton b = new JButton(ButtonText);
b.addActionListener(this);
buttonPanel.add(b);
contentHolder.add(buttonPanel, BorderLayout.SOUTH);
validate();
}
public void actionPerformed(ActionEvent evt)
{
//get the text of the button that was pushed
String command = evt.getActionCommand();
output.setText(command);
// if myButton was pressed, output a message
if(ButtonText.equals(command)) {
try {
this.mprintt("TSC TTP-244 Plus");
} catch (Exception e) {
}
}
}
public void setMessage(String message) {
output.setText(message);
}
public interface TscLibDll extends Library {
TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary ("TSCLIB", TscLibDll.class);
int about ();
int openport (String pirnterName);
int closeport ();
int sendcommand (String printerCommand);
int setup (String width,String height,String speed,String density,String sensor,String vertical,String offset);
int downloadpcx (String filename,String image_name);
int barcode (String x,String y,String type,String height,String readable,String rotation,String narrow,String wide,String code);
int printerfont (String x,String y,String fonttype,String rotation,String xmul,String ymul,String text);
int clearbuffer ();
int printlabel (String set, String copy);
int formfeed ();
int nobackfeed ();
int windowsfont (int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content);
}
public void mprintt(String printer) {
try {
//TscLibDll.INSTANCE.about();
TscLibDll.INSTANCE.openport(printer);
//TscLibDll.INSTANCE.downloadpcx("C:\\UL.PCX", "UL.PCX");
TscLibDll.INSTANCE.sendcommand("REM ***** This is a test by JAVA. *****");
TscLibDll.INSTANCE.setup("35", "15", "3", "8", "0", "3", "-1");
TscLibDll.INSTANCE.clearbuffer();
//TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");
TscLibDll.INSTANCE.printerfont ("290", "8", "3", "0", "1", "1", "ARTICLE NO");
TscLibDll.INSTANCE.barcode("290", "35", "128", "50", "1", "0", "2", "2", "123456789");
//TscLibDll.INSTANCE.windowsfont(400, 200, 48, 0, 3, 1, "arial", "DEG 0");
//TscLibDll.INSTANCE.windowsfont(400, 200, 48, 90, 3, 1, "arial", "DEG 90");
//TscLibDll.INSTANCE.windowsfont(400, 200, 48, 180, 3, 1, "arial", "DEG 180");
//TscLibDll.INSTANCE.windowsfont(400, 200, 48, 270, 3, 1, "arial", "DEG 270");
TscLibDll.INSTANCE.printlabel("1", "1");
TscLibDll.INSTANCE.closeport();
output.setText("printed");
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
output.setText(sw.toString());
}
}
}
My Html code
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<applet codebase ="." code="CallApplet.class"
archive="CallApplet.jar,jna.jar,platform.jar"
height="100" width="100"/>
</body>
</html>
I can see the applet loaded and all swing elements in browser when i try to click print it just wont do anything. In eclipse run it works fine.
I know this is security issue so i have also added policy (C:\Program Files\Java\jre7\lib\security\java.policy file)
grant codeBase "http://localhost:8080/appletproj/*" {
permission java.security.AllPermission;
};
Stacktrace
Exception in thread "AWT-EventQueue-7" java.lang.NoClassDefFoundError: com/sun/jna/Library
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.access$100(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at CallApplet.mprintt(CallApplet.java:185)
at CallApplet.actionPerformed(CallApplet.java:60)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Library
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 55 more
But even this does not help. please guide me where am I going wrong.
SOLUTION
Frankly i did not got solution to work, rather it was not a security issue so creating new question with actual error
So to get the exact error i enabled java console (suggested by andrew), you can go here for how to do it.
UPDATE
After few days I got it working, the issue was jna.jar and platform.jar which were already signed so whenever i signed them using jarsigner it never worked and i never got any error (so i never looked at them), when i verified it using jarsigner i figured it out. Then i unsigned them and signed it using same key which i used with my jar (Hope it will help others)
..also added policy .. But even this does not help.
Policy files are rarely, if ever, a good idea. If the code needs to be trusted, digitally sign the archive(s).

Rhino reports missing : after property id

I'm using Rhino 1.7 R4 with envjs 1.2 on Mac OSX with JDK 1.6.0_33
If I run:
java -jar rhino-1.7R4.jar -opt -1
And then:
load('env.rhino-1.2.js')
Then the script is loaded successfully.
When I load the same JS script from Java via RhinoTest.java:
import org.apache.commons.io.IOUtils;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextAction;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.tools.shell.Main;
import org.mozilla.javascript.tools.shell.ShellContextFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class RhinoTest {
static final Logger LOGGER = LoggerFactory.getLogger(RhinoTest.class);
static private Scriptable SCRIPTABLE;
static private List<Script> scripts;
public static void main(String[] args) {
ShellContextFactory cxFactory = Main.shellContextFactory;
cxFactory.call(new ContextAction() {
#Override
public Object run(Context cx) {
final Initiator initiator = new Initiator(cx).init();
LOGGER.trace("Run script");
try {
return initiator.execute();
} finally {
}
}
class Initiator {
Initiator(Context context) {
this.cx = context;
}
Initiator init() {
if (SCRIPTABLE == null)
createScriptable();
initContext();
return this;
}
Object execute() {
return null;
}
void createScriptable() {
LOGGER.trace("init standard objects");
SCRIPTABLE = cx.initStandardObjects();
LOGGER.trace("set optimization level to -1");
cx.setOptimizationLevel(-1);// bypass the 64k limit // interpretive mode
attachJs("env.rhino-1.2.js");
LOGGER.trace("set optimization level to 9");
cx.setOptimizationLevel(9);
}
#SuppressWarnings("deprecation")
private void attachJs(String jsFileName) {
InputStream in = null;
InputStreamReader reader = null;
if (LOGGER.isDebugEnabled()) LOGGER.debug("loading " + jsFileName);
try {
in = RhinoTest.class.getResourceAsStream(jsFileName);
if (in == null)
throw new RuntimeException("cannot find js file : " + jsFileName);
reader = new InputStreamReader(in);
if (scripts == null)
scripts = new ArrayList<Script>();
scripts.add(cx.compileReader(SCRIPTABLE, reader, jsFileName, 1, null));
if (LOGGER.isDebugEnabled()) LOGGER.debug("loaded " + jsFileName);
} catch (IOException e) {
throw new RuntimeException("cannot load js file : " + jsFileName, e);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(reader);
}
}
void initContext() {
LOGGER.trace("set optimization level to -1");
cx.setOptimizationLevel(-1);// bypass the 64k limit // interpretive mode
for (Script s : scripts) {
s.exec(cx, SCRIPTABLE);
}
}
private final Context cx;
}
});
}
}
I get:
Exception in thread "main" org.mozilla.javascript.EvaluatorException: missing : after property id (env.rhino-1.2.js#2121)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(Unknown Source)
at org.mozilla.javascript.DefaultErrorReporter.error(Unknown Source)
at org.mozilla.javascript.Parser.addError(Unknown Source)
at org.mozilla.javascript.Parser.reportError(Unknown Source)
at org.mozilla.javascript.Parser.mustMatchToken(Unknown Source)
at org.mozilla.javascript.Parser.primaryExpr(Unknown Source)
at org.mozilla.javascript.Parser.memberExpr(Unknown Source)
at org.mozilla.javascript.Parser.unaryExpr(Unknown Source)
at org.mozilla.javascript.Parser.mulExpr(Unknown Source)
at org.mozilla.javascript.Parser.addExpr(Unknown Source)
at org.mozilla.javascript.Parser.shiftExpr(Unknown Source)
at org.mozilla.javascript.Parser.relExpr(Unknown Source)
at org.mozilla.javascript.Parser.eqExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitAndExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitXorExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitOrExpr(Unknown Source)
at org.mozilla.javascript.Parser.andExpr(Unknown Source)
at org.mozilla.javascript.Parser.orExpr(Unknown Source)
at org.mozilla.javascript.Parser.condExpr(Unknown Source)
at org.mozilla.javascript.Parser.assignExpr(Unknown Source)
at org.mozilla.javascript.Parser.argumentList(Unknown Source)
at org.mozilla.javascript.Parser.memberExprTail(Unknown Source)
at org.mozilla.javascript.Parser.memberExpr(Unknown Source)
at org.mozilla.javascript.Parser.unaryExpr(Unknown Source)
at org.mozilla.javascript.Parser.mulExpr(Unknown Source)
at org.mozilla.javascript.Parser.addExpr(Unknown Source)
at org.mozilla.javascript.Parser.shiftExpr(Unknown Source)
at org.mozilla.javascript.Parser.relExpr(Unknown Source)
at org.mozilla.javascript.Parser.eqExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitAndExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitXorExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitOrExpr(Unknown Source)
at org.mozilla.javascript.Parser.andExpr(Unknown Source)
at org.mozilla.javascript.Parser.orExpr(Unknown Source)
at org.mozilla.javascript.Parser.condExpr(Unknown Source)
at org.mozilla.javascript.Parser.assignExpr(Unknown Source)
at org.mozilla.javascript.Parser.expr(Unknown Source)
at org.mozilla.javascript.Parser.statementHelper(Unknown Source)
at org.mozilla.javascript.Parser.statement(Unknown Source)
at org.mozilla.javascript.Parser.parseFunctionBody(Unknown Source)
at org.mozilla.javascript.Parser.function(Unknown Source)
at org.mozilla.javascript.Parser.primaryExpr(Unknown Source)
at org.mozilla.javascript.Parser.memberExpr(Unknown Source)
at org.mozilla.javascript.Parser.unaryExpr(Unknown Source)
at org.mozilla.javascript.Parser.mulExpr(Unknown Source)
at org.mozilla.javascript.Parser.addExpr(Unknown Source)
at org.mozilla.javascript.Parser.shiftExpr(Unknown Source)
at org.mozilla.javascript.Parser.relExpr(Unknown Source)
at org.mozilla.javascript.Parser.eqExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitAndExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitXorExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitOrExpr(Unknown Source)
at org.mozilla.javascript.Parser.andExpr(Unknown Source)
at org.mozilla.javascript.Parser.orExpr(Unknown Source)
at org.mozilla.javascript.Parser.condExpr(Unknown Source)
at org.mozilla.javascript.Parser.assignExpr(Unknown Source)
at org.mozilla.javascript.Parser.expr(Unknown Source)
at org.mozilla.javascript.Parser.primaryExpr(Unknown Source)
at org.mozilla.javascript.Parser.memberExpr(Unknown Source)
at org.mozilla.javascript.Parser.unaryExpr(Unknown Source)
at org.mozilla.javascript.Parser.mulExpr(Unknown Source)
at org.mozilla.javascript.Parser.addExpr(Unknown Source)
at org.mozilla.javascript.Parser.shiftExpr(Unknown Source)
at org.mozilla.javascript.Parser.relExpr(Unknown Source)
at org.mozilla.javascript.Parser.eqExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitAndExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitXorExpr(Unknown Source)
at org.mozilla.javascript.Parser.bitOrExpr(Unknown Source)
at org.mozilla.javascript.Parser.andExpr(Unknown Source)
at org.mozilla.javascript.Parser.orExpr(Unknown Source)
at org.mozilla.javascript.Parser.condExpr(Unknown Source)
at org.mozilla.javascript.Parser.assignExpr(Unknown Source)
at org.mozilla.javascript.Parser.expr(Unknown Source)
at org.mozilla.javascript.Parser.statementHelper(Unknown Source)
at org.mozilla.javascript.Parser.statement(Unknown Source)
at org.mozilla.javascript.Parser.parse(Unknown Source)
at org.mozilla.javascript.Parser.parse(Unknown Source)
at org.mozilla.javascript.Context.compileImpl(Unknown Source)
at org.mozilla.javascript.Context.compileReader(Unknown Source)
at org.mozilla.javascript.Context.compileReader(Unknown Source)
at RhinoTest$1$Initiator.attachJs(RhinoTest.java:85)
at RhinoTest$1$Initiator.createScriptable(RhinoTest.java:63)
at RhinoTest$1$Initiator.init(RhinoTest.java:44)
at RhinoTest$1.run(RhinoTest.java:28)
at org.mozilla.javascript.Context.call(Unknown Source)
at org.mozilla.javascript.ContextFactory.call(Unknown Source)
at RhinoTest.main(RhinoTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Please help
Wladimir,
You were right it was a version thing.
It turns out that the batik libs I imported included another version of rhino.
By excluding batik-js from my project for each batik dependency this issue went away.

Categories

Resources