Exception in line ExamXML.compareXMLString(s1, s2);
fragment code is
static public void main(String[] argv) throws IOException {
String s1 = readFile("src/main/resources/file1.xml");
String s2 = readFile("src/main/resources/file2.xml");
String s = ExamXML.compareXMLString(s1, s2);
System.out.println(s);
}
the run result is :
java.lang.ClassCastException: org.apache.xerces.parsers.AbstractSAXParser$LocatorProxy cannot be cast to org.xml.sax.ext.Locator2
at com.a7soft.examxml.ExamXMLHandler.setDocumentLocator(ExamXMLHandler.java:215)
at org.apache.xerces.parsers.AbstractSAXParser.startDocument(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startDocument(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.a7soft.examxml.ExamXMLHandler.loadXML(ExamXMLHandler.java:111)
at com.a7soft.examxml.ExamXML.loadXML(ExamXML.java:246)
at com.a7soft.examxml.ExamXML.parseXMLTags(ExamXML.java:262)
at com.a7soft.examxml.ExamXML.compareXMLString(ExamXML.java:281)
at com.happyelements.odin.monster.Main.main(Main.java:55)
null
How can I fix this?
I have a solution of this problem.
System.setProperty("javax.xml.parsers.SAXParserFactory",
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
Thank you!
Related
I have 2D Arralist of Object and i want to sort it upon first column which contains LocalDate
i used this code to sort it
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy");
formatter = formatter.withLocale( Locale.US );
ArrayList<ArrayList<Object>> cusKashf = new ArrayList<ArrayList<Object>>();
cusKashf.addAll(new ReadBillDeateals().readSell(textField_4.getText()));
Collections.sort(cusKashf , new Comparator<ArrayList<Object>>() {
#Override
public int compare(ArrayList<Object> entry1, ArrayList<Object> entry2) {
return ((LocalDate.parse(entry1.get(0).toString(), formatter)).compareTo((LocalDate.parse(entry2.get(0).toString(), formatter))));
}
});
the problem is this code make an exception, i wonder where's the mistake in me code
this is the exception report
java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at reports.Kashf$7$1.compare(Kashf.java:327)
at reports.Kashf$7$1.compare(Kashf.java:1)
at java.util.TimSort.countRunAndMakeAscending(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.ArrayList.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at reports.Kashf$7.actionPerformed(Kashf.java:324)
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$Actions.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
In your cusKashf List check if the sublist is not empty.
#Override
public int compare(ArrayList<Object> entry1, ArrayList<Object> entry2) {
if(Objects.isNull(entry1) || entry1.isEmpty()) return -1;
if(Objects.isNull(entry2) || entry2.isEmpty()) return -1;
return ((LocalDate.parse(entry1.get(0).toString(), formatter)).compareTo((LocalDate.parse(entry2.get(0).toString(), formatter))));
}
One of the lists you are trying to compare are empty, try surrounding by a try and catch or check if a list is empty before getting item 0.
Hello all I am experiencing issues with my JOptionPane.showInputDialog input field.
The issue i am experiencing that is when the cancel button is selected or the OK button is selected with empty or with categorical i am greeted with an error. Any suggestions.
My first attempt at fixing this i changed the c int into an interger therefore i could use an if statement along with null such as
Integer cInterger = new Integer(c);
if (cInterger.equals(null)){
return;}
Along with
cInterger == null
cInterger !=null
But to no avail
int a = 0; //
int b = 0; //
int c = 0; //
if (selected) {
if (command.equals("amount")) {
Scanner readFile = null;
try {
readFile = new Scanner(new FileReader("BANK.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String account = "";
account = readFile.nextLine();
String amount = JOptionPane.showInputDialog(frame,"Enter an amount"); //assign user input to string amount
a= Integer.parseInt(account); //conversion of scanned string to int for easy subtraction
b= Integer.parseInt(amount);
c = a-b;
try {
if( c == 0){
JOptionPane.showMessageDialog(null,"Granted.","Granted",JOptionPane.WARNING_MESSAGE);}
else if (c > 0){
JOptionPane.showMessageDialog(null,"Granted.","Granted",JOptionPane.INFORMATION_MESSAGE); }
else{
JOptionPane.showMessageDialog(null,"Denied.","Denied",JOptionPane.ERROR_MESSAGE);}
Resulting errors
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: null
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Options$1MyItemListener.itemStateChanged(Options.java:58)
at javax.swing.AbstractButton.fireItemStateChanged(Unknown Source)
at javax.swing.AbstractButton$Handler.itemStateChanged(Unknown Source)
at javax.swing.DefaultButtonModel.fireItemStateChanged(Unknown Source)
at javax.swing.JToggleButton$ToggleButtonModel.setSelected(Unknown Source)
at javax.swing.ButtonGroup.setSelected(Unknown Source)
at javax.swing.JToggleButton$ToggleButtonModel.setSelected(Unknown Source)
at javax.swing.JToggleButton$ToggleButtonModel.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$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)
If you take a look at the JavaDocs, you will find that
Returns: user's input, or null meaning the user canceled the input
So attempting to parse null makes no sense, instead you should be using something like...
if (amount != null) {
a = Integer.parseInt(amount);
//...
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "" seems reasonably obvious.
if (amount != null) {
if (amount.trim().length() > 0) {
//...
} else {
JOptionPane.showMessageDialog(frame, "The amount you entered is invalid");
}
You should also check the account value as well
So this is my first time posting, please be gentle :3
General overview:
My goal is to be able to give my program a XSD file, then the program generates a bean, generates a nice GUI using reflection on the bean, then I can enter appropriate values into the textfields and then the program updates the bean with the values and finally marshalls the bean into a nice XML.
It's coming along pretty good, but yesterday I stumbled over an error that I can't figure out..
StackTrace
java.lang.ClassNotFoundException: X.Y.Z.BEAN_FILE_WITHOUT_.JAVA
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at X.Y.Z.GenerateXMLService.generateBean(GenerateXMLService.java:101)
at X.Y.Z.view.Gui$1.handle(Gui.java:56)
at X.Y.Z.view.Gui$1.handle(Gui.java:1)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1800(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
generateBean
public Class generateBean(File xsd) {
String finalDir = System.getProperty("user.dir") + "/src/main/java";
String xsdDir = xsd.getParentFile().getAbsolutePath();
try {
Process p = Runtime.getRuntime().exec(
"cmd /c cd " + xsdDir + " && xjc -d " + finalDir
+ " -p PACKAGE_PATH_GOES_HERE " + xsd.getName().toString());
p.waitFor();
} catch (IOException | InterruptedException e) {
Gui.errorPopUp(e);
}
/**
* Get the newly created files and put them in an array
*/
File[] fList = new File[2];
fList = new File("DIRECTORY_PATH_GOES_HERE").listFiles();
/**
* Get the file that isn't Objectfactory.java ---> that's the bean
*/
for (File file : fList) {
if (!"ObjectFactory.java".equals(file.getName())) {
String beanName = file.getName();
String beanBinaryName = "PACKAGE_PATH_GOES_HERE"
+ beanName.substring(0, beanName.length() - 5);
Class beanClass = null;
try {
beanClass = Class.forName(beanBinaryName); //this is line 101
return beanClass;
} catch (ClassNotFoundException e) {
Gui.errorPopUp(e);
}
}
}
return null;
}
So I checked first if the beanBinaryName is correct, and I think it is. It has the following format:
com.foo.foo.some.more.foo.beanbag.bean
Then I started googling with the error message and stumbled accross this post:
Link to the blog
But to be honest I didn't really understand what he was trying to explain. The stacktrace looks similar, but I just started with java a few months ago and still consider myself a newbie. Do you have any advice what the error might be? Thank in advance!
EDIT / SOLUTION:
My first mistake was trying to use class.forName() on a .java file. This only works with compiled files, e.g. .class.
After I fixed that i was still getting error messages, but after playing around with the URLClassLoader it worked :D I renamed and refactored this method compared to the method at the top, so in this one we really only get the class, while in my first example I also generate the .java files. I now do this in a seperate method to keep things organized.
public Class getClassFromBean() {
File[] fList = new File[3];
fList = new File("foo/beanbag").listFiles();
Class beanClass = null;
for (File file : fList) {
String lastSix = file.getName().toString().substring(file.getName().length() - 6);
if (".class".equals(lastSix)) {
String beanBinaryName = "foo.beanbag."
+ file.getName().toString().substring(0, file.getName().toString().length() - 6);
try {
File root = new File(System.getProperty("user.dir") + "/src/main/java");
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI()
.toURL() });
beanClass = Class.forName(beanBinaryName, true, classLoader);
} catch (ClassNotFoundException | MalformedURLException e) {
Gui.errorPopUp(e);
}
return beanClass;
}
}
return beanClass;
}
Method Class.forName() works only for compiled classes i.e. for files with extension '.class'. You cannot just put '.java' file to your classpath.
I'm attempting to accept 5 numbers in a textField from the user, in order to sort them using different methods (bubbleSort, mergeSort, quickSort). Unfortunately, I keep having "java.lang.NullPointerException" thrown. I've looked around a bit, and the closest I could find to my issue is NumberFormatException when attempting to parse string as an integer, but that was simply due to an empty space. I threw in a .trim() just for good measure though, to no avail.
public class SortWindow {
private JFrame frame;
private JTextField textFieldInput;
private String[] list;
private int[] numList;
private static JTextArea textAreaOutput;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SortWindow window = new SortWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public SortWindow() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
//Buttons
JButton buttonBubble = new JButton("Bubble");
buttonBubble.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textAreaOutput.setText("");
list = textFieldInput.getText().split(" ");
numList[0] = Integer.parseInt(list[0].trim());
for (int i = 0; i < list.length; i++){
numList[i] = Integer.parseInt(list[i]);
}
bubbleSort(numList);
}
});
buttonBubble.setBounds(12, 13, 115, 40);
frame.getContentPane().add(buttonBubble);
//Text Fields
textFieldInput = new JTextField(5);
textFieldInput.setBounds(177, 13, 243, 40);
frame.getContentPane().add(textFieldInput);
textFieldInput.setColumns(10);
textAreaOutput = new JTextArea();
textAreaOutput.setLineWrap(true);
textAreaOutput.setText("In the box above, enter 5 numbers separated by spaces.");
textAreaOutput.setEditable(false);
textAreaOutput.setBounds(177, 66, 243, 176);
frame.getContentPane().add(textAreaOutput);
}
}
list is an array of Strings, and when I enter 1 2 3 4 5 (or any other combination - I even tried just entering a single digit and seeing what happened using my second line, but it still threw the exception) into the textField in my GUI, it stores it correctly within the String array, and I can successfully print the individual Strings within it perfectly fine using System.out.print(). My problem only arises when I attempt to use any of the following four lines (I only included the second line to make sure there wasn't something wrong with my for loop).
I can provide the rest of my code if needed, but I figured I'd start with this, since I can't think of anything else that would be affecting it.
EDIT: Added a much larger part of my class to the OP. The exception is thrown in line 60, which is:
numList[0] = Integer.parseInt(list[0].trim());
EDIT2: As requested, this is what I am given.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at SortWindow$2.actionPerformed(SortWindow.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.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)
your numList size might not been initialized. you can try like this and see if its okay:
int[] numList=new int[5];
String[] list = textFieldInput.getText().split(" ");
for (int i = 0; i < list.length; i++){
numList[i] = Integer.parseInt(list[i]);
}
System.out.println(Arrays.toString(numList));
That Exception means that the Item in your list is Empty (has value of null), check your list items the problem is there, and not in the parsing part!
try :
System.out.println(list[0]);
and watch the output.
Basically I have this code to print the cell label of each vertex I click of the jgraph. I am trying to store the values of the cells into a string array. I have tried this:
graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
ArrayList<Object> objarr = new ArrayList<Object>() ;
if (e.getButton() == 3 && e.getClickCount() == 1) {
long x = e.getX();
long y = e.getY();
Object cell = graphComponent.getCellAt((int) x, (int)y);
System.out.println(graph.convertValueToString(cell));
objarr.add(cell);
}
String[] stringArray = objarr.toArray(new String[100]) ;
}
});
}
I get these errors when i try to click a vertex:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.toArray(Unknown Source)
at GUIquery$2.mousePressed(GUIquery.java:498)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.AWTEventMulticaster.mousePressed(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)
Here is the process to resolve such a problem.
at java.util.ArrayList.toArray(Unknown Source)
at GUIquery$2.mousePressed(GUIquery.java:498)`
Line 498 must be
String[] stringArray = objarr.toArray(new String[100]) ;
Check ArrayList documentation for <T> T[] toArray(T[] a)
When called this tries to store ArrayList<Object> members of type Object in a String[]. So it gave an ArrayStoreException. The root of the problem is that the computer has no idea what type cell is. You declared is as an Object, so that's its type. If getCellAt() returns strings, use String cell.
As a note that is not an elegant solution here, if you had an Object obj_str that you knew was a String, you could cast it with
String str = (String)obj_str;