How to solve NumberFormatException when parsing string to double/integer - java

I've written a program & I've built a GUI for it. When I try to run it, it throws an exception NumberFormatException and here's all I got :
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at newtp.GUI$2.actionPerformed(GUI.java:219)
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$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)
So what do I have to do to solve my problem?

Your problem is that your string is empty
java.lang.NumberFormatException: empty String at
To solve this problem, you should fill the string with a string representation of a number (e.g. 3 for a string or 7.7 for a double)
Would be best if you show us your code to see where the problem is.
Example:
Ff you do the following
String string1 = "";
int int1 = Integer.parseInt(string1);
you will receive the exception you received since Java is not able to find the matching int value for and empty string.
If you do
String string2 = "3";
int int2 = Integer.parseInt(string2);
you won't receive an exception, but a variable called int2 containing the value 3.

One solution, as Phiwa said, is just not to pass in an empty string. It's probably better to handle the issue, though.
You can use something like this to assign a default value if the entered value isn't of the correct type:
int x;
try {
//whatever you're doing to parse the string...probably x = Integer.parseInt("32"); or something
catch(NumberFormatException e) {
e.printStackTrace();
x = 12; //or whatever default value you want
}

i've casted the variable when it's empty , that was in the actionListener so i've brought the value ( with textField.getText(); ) the parsing was done ... i forgot to bring in the method that's all ..
thank's for helping guys :)))

Related

Event errors, not sure what they mean [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 3 years ago.
I'm currently getting these errors, I've tried doing a few things to see if that would help. I even used the debugger to find out why these errors are occurring, but i'm still not sure.
If anyone would be able to help it would be really appreciated.
I tried looking at the suggested post and i made the fixes suggested, however this didn't help, the errors still remain the same.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at c3537779.ByteReader.getBytes(ByteReader.java:14)
at c3537779.BytePattern.patternParse(BytePattern.java:37)
at c3537779.FileChooser.PatternOpen(FileChooser.java:95)
at c3537779.GUI$OpenPatternAction.actionPerformed(GUI.java:74)
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)
NullPointerException throws when the object where you try to call some method does not exists. So we have it at c3537779.ByteReader.getBytes(ByteReader.java:14) and you need to debug the process on 14 row of class ByteReader and look what it calls. If You will see something like myName.myMethod(); you should check creation process of myName object because it null.

Opening docx file directly from src generating "File not found" exception

Edited:
I am trying to open a file that is stored in a project file SRC. I am getting a "File not found" exception and I really don't understand why. The file is a docx and I have dropped it in eclipse into my project's src folder.
Here is the code where I try to open the file:
JButton documentationButton = new JButton("Helpfile");
documentationButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
Desktop desktop = null;
if(Desktop.isDesktopSupported()){
desktop = Desktop.getDesktop();
}
try {
ClassLoader classLoader = getClass().getClassLoader();
File fi = new File(classLoader.getResource("ReturnBuilderDocumentation.docx").getFile());
String string = "file:/src/ReturnBuilderDocumentation.docx";
desktop.open(new File(URI.create(string)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Here is the exception generating:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: The file: \src\ReturnBuilderDocumentation.docx doesn't exist.
at java.awt.Desktop.checkFileValidation(Unknown Source)
at java.awt.Desktop.open(Unknown Source)
at nachamultifive.GUIs.MainMenu$3.actionPerformed(MainMenu.java:172)
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$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)
This file is clearly in my project src so I have no idea why the error is generating. Any help is greatly appreciated.
UPDATE:
I also tried with backslashes and another error was generated.
Code:
String string = "\\src\\ReturnBuilderDocumentation.docx";
Error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Illegal character in opaque part at index 5: file:\src\ReturnBuilderDocumentation.docx
at java.net.URI.create(Unknown Source)
at nachamultifive.GUIs.MainMenu$3.actionPerformed(MainMenu.java:172)
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$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)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 5: file:\src\ReturnBuilderDocumentation.docx
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
... 38 more
This code is the problem because it can't find that file at the given path
String string = "file:/src/ReturnBuilderDocumentation.docx";
desktop.open(new File(URI.create(string)));
Reason being is that the src folder doesn't really exist after the code is compiled.
To get the file resource post-compilation, you have to use
getClass().getClassLoader().getResource()
Which you have correctly done here
ClassLoader classLoader = getClass().getClassLoader();
File fi = new File(classLoader.getResource("ReturnBuilderDocumentation.docx").getFile());
So to open the file, you should simply have to do
desktop.open(fi);
Instead of
desktop.open(new File(URI.create(string)));
Check this answer. I don't think URIs can have a space, which is character 26 in your file name. File can accept a String, you could take out the URI and replace it with just the file name, or try to change the URI

How do I make an integer go up and display on a JLabel?

I know this may sound like a stupid question, but I cannot figure this out. I'm pretty new to java, and here's my code:
if (e.getSource() == Game1){
wins++;
Wins.setText(wins+"/30 endings completed!");
/* Game1 g1 = new Game1();
g1.Game1();*/
}
I thought this would work, but it didn't. Here's what I get when I run the code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at WindowObject.actionPerformed(WindowObject.java:92)
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)
If anyone can help me, I will be very grateful, thanks.
Make sure that Integer win is not null. I do see one reason behind NPE is that win is null and you are saying win++ on a null object. During doing ++, while autoboxing, it will throw NPE.
also
Make sure JLabel is not null. If you are calling a method on a null object, it will throw NPE.
Either Integer win or JLabel Win is null or both are null. Else I don't see any reason behind NPE.

When I write .txt in after file name I get nullpointerexception

Whenever I write .txt after a file name I recieve nullpointrexception error. But when I don't write .txt the program seems to run but it always says that the system cannot find the specified file. I have no idea what to do. Please guide me.
This is my code
public void signin(){
//System.out.println(System.getProperty("user.dir"));
File file=new File("C:\\Workplace\\3rdLastLab\\file1.txt");
try{
FileReader fr=new FileReader(file);
BufferedReader br=new BufferedReader(fr);
Scanner sc=new Scanner(br);
String text1=field1.getText();
String text2=field2.getText();
String text3=text1+"."+text2;
while(sc.hasNext()){
String string= sc.next();
if(text3.equals(string)==true){
JOptionPane.showMessageDialog(null, "You are logged in!");
}
else
JOptionPane.showMessageDialog(null, "Wrong user name or password");
}
br.close();
}
catch (IOException e){
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
And i get these errors
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Login.signin(Login.java:36)
at Login.actionPerformed(Login.java:122)
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)
my psychic debugging powers tell me that either field1 or field2 is null when you call getText on them.
String text1=field1.getText();
String text2=field2.getText();
The reason you're only getting the nullpointrexception exception when you add .txt is because you're code throws a fileNotfound exception before that point.
You need to make sure that field1 and field2 are instantiated.
Looking at behavior when you put the correct file name you get a null pointer exception
It looks like you have issue with field1 or field1 ( if they corresponds to line 36)
String text1=field1.getText();
String text2=field2.getText();
which may be null depending on how are you setting these
I am sure %100 that the reading process don't have any problem, because non of BufferedReader and FileReader also Scanner thrown to NullPointerException.
I am sure you have problem with one of your text fields and I am sure that you didn't define one of them (maybe there are more than one), because NullPointerException occurs while a reference data type without initializing.
Please read this post about NullPointerException .

Changing the value of Auto Completing JComboBox

I always get an error of my Auto Completing JComboBox.
To auto complete my jcombobox i used this script of http://w_w.orbital-computer.de/JComboBox/.
When I create them i do it like this:
final Object[] elements = new Object[] {"Please refresh your list"};
comboBox[i] = new JComboBox(elements);
comboBox[i].setEditable(true);
new AutoCompleteJComboBox(comboBox[i]);
It works fine if i just use it with new jcomboboxes, but if i change their values like this:
comboBox[i].removeAllItems();
comboBox[i].setModel(new JComboBox<>(ListWithNames).getModel());
comboBox[i].setEditable(true);
new AutoCompleteJComboBox(comboBox[i]);
I get the following error message:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: bad position: 11
at javax.swing.text.JTextComponent.setCaretPosition(Unknown Source)
at src.AutoCompleteJComboBox.highlightCompletedText(AutoCompleteJComboBox.java:146)
at src.AutoCompleteJComboBox.access(AutoCompleteJComboBox.java:145)
at src.AutoCompleteJComboBoxactionPerformed(AutoCompleteJComboBox.java:30)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopupprocessMouseEvent(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(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomaindoIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomaindoIntersectionPrivilege(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomaindoIntersectionPrivilege(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)
this position 11 is the length of the first value in the ListWithNames, additionally the first item in the list still works fin but by the other items is just the first letter of the text highlighted and than the error appears.
AutoCompleteJComboBox.java is this file with another name in line 146 is
editor.setCaretPosition(this.getLength());
I hope someone can help me with this.
(sorry for that link at the top, but im not allowed to post more than two)

Categories