MalformedInputException in Stream<String> handling - java

This code seems to be returning a java.nio.charset.MalformedInputException: Input length = 1 error and for the life of me I can't figure out why.
Files.lines(Paths.get(fileName))
.forEachOrdered(m -> hashmap.put(LocalDateTime.MIN, m));
hashmap is a HashMap<LocalDateTime, String>
Full stack error:
Exception in thread "main" java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
at java.io.BufferedReader$1.hasNext(Unknown Source)
at java.util.Iterator.forEachRemaining(Unknown Source)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
at java.util.stream.ReferencePipeline$Head.forEachOrdered(Unknown Source)
at FileHandler.inputSavedDonations(FileHandler.java:92)
at StreamHelper.main(StreamHelper.java:36)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
... 6 more
Line 92 is .forEachOrdered(m -> hashmap.put(LocalDateTime.MIN, m));
fileName declaration: private static String fileName = "file";

Related

Sorting 2D Arraylist of Object

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.

JavaFX Chart - Java.lang.IllegalArgumentException : Duplicate series added

I'm using clear() method for removing data from chart.
#FXML
public void restartButtonClicked() {
System.out.println("Restarting...");
timeLine.getKeyFrames().clear();
axesTest.getData().clear();
}
In this function, but once button get clicked - it works.. but second time while I am gonna click it, it throw exception :
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Duplicate series added
at javafx.scene.chart.XYChart.lambda$new$550(Unknown Source)
at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(Unknown Source)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(Unknown Source)
at javafx.collections.ObservableListBase.fireChange(Unknown Source)
at javafx.collections.ListChangeBuilder.commit(Unknown Source)
at javafx.collections.ListChangeBuilder.endChange(Unknown Source)
at javafx.collections.ObservableListBase.endChange(Unknown Source)
at javafx.collections.ModifiableObservableListBase.addAll(Unknown Source)
at sample.Controller.startButtonClicked(Controller.java:138)
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.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(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.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$1500(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.lambda$handleMouseEvent$354(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
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.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
So the problem is in 138 line as well as in 159 line of code from method :
#SuppressWarnings("unchecked")
#FXML
public void startButtonClicked(ActionEvent event) {
if (comboBox.getValue() == null) {
System.out.print("Nie wybrano opcji.");
} else {
if(comboBox.getValue().equals("Gaussian Wave : non-Dispersive")) {
System.out.println("Gaussian Wave : non-Dispersive");
axesTest.setTitle("Gaussian Wave : non-Dispersive");
series.setName("bla");
series1.setName("ssad");
series2.setName("asf");
seriesList.add(series);
seriesList.add(series1);
seriesList.add(series2);
timeLine = new Timeline();
gaussianWave = new GaussianWave( seriesList, axes, timeLine );
seriesList = gaussianWave.draw();
gaussianWave.update(axesTest);
axesTest.getData().retainAll();
axesTest.getData().addAll(seriesList);
} else if(comboBox.getValue().equals("Gaussian Wave : Dispersive")) {
System.out.println("Gaussian Wave : Dispersive");
axesTest.setTitle("Gaussian Wave : Dispersive");
series.setName("bla");
series1.setName("ssad");
series2.setName("asf");
seriesList.add(series);
seriesList.add(series1);
seriesList.add(series2);
timeLine = new Timeline();
gaussianWaveDispersive = new GaussianWaveDispersive( seriesList, axes, timeLine );
seriesList = gaussianWaveDispersive.draw();
gaussianWaveDispersive.update(axesTest);
axesTest.getData().retainAll();
axesTest.getData().addAll(seriesList);
}
}
}
and the problem is in :
axesTest.getData().addAll(seriesList);
Why do I get this exception after clearing all of data from the chart ? How could I fix this?
You clear the ObservableList stored in the dataProperty of the Series:
axesTest.getData().clear();
but you use an intermediate list(?) called seriesList, rather than adding Data directly:
seriesList.add(series);
seriesList.add(series1);
seriesList.add(series2)
...
axesTest.getData().addAll(seriesList);
The problem is you don't clear seriesList before adding the elements, so it contains the elements on the second click twice, which will result in an IllegalArgumentException.
Actually I don't know what happens here:
gaussianWave = new GaussianWave( seriesList, axes, timeLine );
seriesList = gaussianWave.draw();
but it seems that seriesList contains the previous Data objects after these lines.

Java - JOptionPane.showInputDialog errors

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

transform returning null pointer exception but the parameters arent null? [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 8 years ago.
I'm generating a KML file and at the point where I use the transformer API, I get the NullPointerException exception. Here's the code I'm refering too:
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(kml);
StreamResult result = new StreamResult(new File("src/mapa/mapa.kml"));
System.out.print("DESPRES DE CREAR RESULT\n");
if(source == null)
System.out.print("SOURCE IS NULL");
if(result == null)
System.out.print("RESULT IS NULL");
transformer.transform(source, result);
System.out.print("AFTER TRASNFORM\n");
It doesn't print any of the NULL System.outs, however it doesn't print the last one either. Why is it giving me NPE?
Exception:
DESPRES DE CREAR RESULT
ERROR: ''
javax.xml.transform.TransformerException: java.lang.NullPointerException
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at Joc.crearMapa(Joc.java:199)
at MastersOfWar.main(MastersOfWar.java:18)
Caused by: java.lang.NullPointerException
at com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
... 4 more
---------
java.lang.NullPointerException
at com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at Joc.crearMapa(Joc.java:199)
at MastersOfWar.main(MastersOfWar.java:18)
Try the below code
System.out.print(transformerFactory.newTransformer());
It probably returns null, making your transformer object null.

Convert vertex label value of the jgraph to array of strings

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;

Categories

Resources