SwingX AutoCompleteDecorator JTextField Errors - java

I'm testing out the SwingX AutoCompleteDecorator, the code I'm using is this:
import javax.swing.text.JTextComponent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.JList;
import org.jdesktop.swingx.autocomplete.*;
public class Test extends JFrame
{
public Test()
{
this.setTitle("Testing");
JPanel pan = new JPanel();
JTextComponent test = new JTextField();
((JTextField)test).setColumns(20);
String[] data = {"one", "two", "three", "four"};
JList dataList = new JList(data);
AutoCompleteDecorator.decorate(dataList, test);
pan.add(test);
this.setContentPane(pan);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(280,150,500,200);
}
public static void main(String[] args)
{
Test t = new Test();
}
}
I wind up getting a massive runtime error message that I don't really want to post the stack trace for about an Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.jdesktop.swingx.autocomplete.ListAdaptor.valueChanged(ListAdaptor.java:77)
at javax.swing.JList.fireSelectionValueChanged(JList.java:1798)
at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1812)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415)
at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:459)
at javax.swing.JList.setSelectedIndex(JList.java:2212)
at javax.swing.JList.setSelectedValue(JList.java:2362)
at org.jdesktop.swingx.autocomplete.ListAdaptor.setSelectedItem(ListAdaptor.java:99)
at org.jdesktop.swingx.autocomplete.AutoCompleteDocument.setSelectedItem(AutoCompleteDocument.java:355)
at org.jdesktop.swingx.autocomplete.AutoCompleteDocument.insertString(AutoCompleteDocument.java:303)
at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1386)
at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:884)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1664)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2879)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2926)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2842)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
at java.awt.Component.dispatchEventImpl(Component.java:4731)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
What have I missed?

It's a bug: the culprit is a null ObjectToStringConverter in decorating a textComponent with the items of a JList, using the two-parameter method:
public static void decorate(JList list, JTextComponent textComponent) {
decorate(list, textComponent, null);
}
A quick fix is to use the three-parameter method and pass-in the default converter:
JTextComponent test = new JTextField(20);
String[] data = {"one", "two", "three", "four"};
JList dataList = new JList(data);
AutoCompleteDecorator.decorate(dataList, test, ObjectToStringConverter.DEFAULT_IMPLEMENTATION);
Filed Issue #1570 - fixed as of revision #4305
Morning Musings (can safely be ignored :-)
The technical reason is improper constructor chaining: inserting the default should be handled by the do-it-all constructor (alternatively it should throw a NPE)
public ListAdaptor(JList list, JTextComponent textComponent) {
this(list, textComponent, ObjectToStringConverter.DEFAULT_IMPLEMENTATION);
}
public ListAdaptor(JList list, JTextComponent textComponent, ObjectToStringConverter stringConverter) {
this.list = list;
this.textComponent = textComponent;
this.stringConverter = stringConverter;
// when a new item is selected set and mark the text
list.addListSelectionListener(this);
}
The underlying reason is a subtle shift in ownership of the converter: its usual owner is the custom document which handles the autoComplete, this document guards itself against a null. With a JList variant, its the ListAdaptor which is not accustomed to that burden ... The shift is not incorrect (in fact, the exact way to go), just introduces an ever so slight inconsistency which is easy to overlook.

AutoCompleteDecorator.decorate(dataList, test, false)
just add false settings
or just like these
boolean strictMatching = false;
AutoCompleteDecorator.decorate(UName,items,strictMatching);

Related

How can I show a JTable in a dialog box in NetBeans?

I have had a few problems trying to get this table to show in NetBeans. Here is the code that I am trying to use. I am aware that the loop is wrong and will fix that at a later date.
I get a runtime error with the following code and I can't work it out.
Object[][] data = null;
String[] columnNames = {"Type", "Grade", "Height", "Width", "Length", "Reinforced Bottom", "Reinforced Corners", "Sealable", "Quantity"};
JTable table = new JTable();
public void showTotalOrder(){
for(int i=0; i<boxes.size(); i++){
for(int j=0; j<1; j++){
data[i][j] = boxes.get(i).getName();
data[i][j+1] = boxes.get(i).getGrade();
data[i][j+2] = boxes.get(i).getHeight();
data[i][j+3] = boxes.get(i).getWidth();
data[i][j+4] = boxes.get(i).getLength();
data[i][j+5] = boxes.get(i).getReinforcedBottom();
data[i][j+6] = boxes.get(i).getReinforcedCorners();
data[i][j+7] = boxes.get(i).getSealable();
data[i][j+8] = boxes.get(i).getQuantity();
}
}
JOptionPane.showMessageDialog(this, table);
}
I believe the problem is with the last line of this method.
The error i receive is:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at coursework.FlexBox.showTotalOrder(FlexBox.java:116)
at coursework.FlexBox.currentOrderButtonActionPerformed(FlexBox.java:530)
at coursework.FlexBox.access$300(FlexBox.java:18)
at coursework.FlexBox$4.actionPerformed(FlexBox.java:435)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
I get a runtime error with the following code and I can't work it out.
Given this stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at coursework.FlexBox.showTotalOrder(FlexBox.java:116)
...
You get a NullPointerException because of data array is initialized to null:
Object[][] data = null;
Please have a read to:
What is a Null Pointer Exception, and how do I fix it?
Creating, Initializing, and Accessing an Array

Exception in thread "AWT-EventQueue-0" - Java [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 8 years ago.
when I try to run this program the following error message appears:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Quiz1.<init>(Quiz1.java:21)
at Opening_Screen.jButton1ActionPerformed(Opening_Screen.java:138)
at Opening_Screen.access$000(Opening_Screen.java:16)
at Opening_Screen$1.actionPerformed(Opening_Screen.java:57)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
As I'm extremely new to Java I have absolutely no idea what any of this means, if someone could show me where in my code this is happening I'd be extremely appreciative!
Here is the code.
public class Quiz1 extends javax.swing.JFrame {
ArrayList <String> quiz1Answers = new ArrayList();
ArrayList <String> quiz1UserAnswers = new ArrayList();
String q1 = this.txtInputQ1.getText();
String q2 = this.txtInputQ2.getText();
String q3 = this.txtInputQ3.getText();
String q4 = this.txtInputQ4.getText();
String q5 = this.txtInputQ5.getText();
String q6 = this.txtInputQ6.getText();
String q7 = this.txtInputQ7.getText();
String q8 = this.txtInputQ8.getText();
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "This is a practice quize to test what you have learned.", "Instructions", + JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "<html>To check your answers press the <b><i>'Check'</b></i> button and enter which question to check", "Instructions", + JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "<html>When completed click the <b><i>'Start Quiz'</b></i> button", "Instructions", + JOptionPane.INFORMATION_MESSAGE);
}
private void txtInputQ6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
if (q1.equals("") || q2.equals("") || q3.equals("") || q4.equals("") || q5.equals("") || q6.equals("") || q7.equals("") || q8.equals(""))
{
JOptionPane.showMessageDialog(null, "Make sure all fields are filled in!", "Error!", + JOptionPane.ERROR_MESSAGE);
}
else
{
quiz1UserAnswers.add(q1);
quiz1UserAnswers.add(q2);
quiz1UserAnswers.add(q3);
quiz1UserAnswers.add(q4);
quiz1UserAnswers.add(q5);
quiz1UserAnswers.add(q6);
quiz1UserAnswers.add(q7);
quiz1UserAnswers.add(q8);
JOptionPane.showMessageDialog(null, "<html>Press the <b><i>'Check Answer'</b></i> button now!", "", + JOptionPane.INFORMATION_MESSAGE);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
Collections.addAll(quiz1Answers, "ottawa", "toronto", "tokyo", "northamerica", "seoul", "Asia", "unitedstates", "50");
}
Thank you in advance!
I'm probably going to assume that you're trying to get the values before even initializing the object. Make sure that the object txtInputQ1 till txtInputQ2 is first created before you call the .getText(); method.

How to only select one item from a number of JLists in Swing

So i have a GUI which creates Jlists when categories are created. I only want the user to be able to select one item from any jlist at a time. I also am retrieving information about that item selected, its position in a linked list for example. However with my code so far i get an error, but it doesn't seem to affect functionality, was wondering if anyone could help me work how why or how to fix it?
This is my code:
public void addListener(final JList jList, final int curListCount) {
jList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
jLabel2.setText("");
if (isSelected == true) {
isSelected = false;
jList.clearSelection();
jLabel2.setText("");
}
String selectedString = (jList.getSelectedValue().toString());
jLabel2.setText(selectedString);
int selectedIndex = jList.getSelectedIndex();
isSelected = true;
System.out.println("Array position is: " + curListCount);
System.out.println("LinkedList position is: " + selectedIndex);
}
});
}
And the error that comes up is:
'Array position is: 3 LinkedList position is: 0 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at smartChart.wbt$1.valueChanged(wbt.java:57)
at javax.swing.JList.fireSelectionValueChanged(JList.java:1798)
at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1812)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415)
at javax.swing.DefaultListSelectionModel.removeSelectionIntervalImpl(DefaultListSelectionModel.java:576)
at javax.swing.DefaultListSelectionModel.clearSelection(DefaultListSelectionModel.java:420)
at javax.swing.JList.clearSelection(JList.java:2045)
at smartChart.wbt$1.valueChanged(wbt.java:54)
at javax.swing.JList.fireSelectionValueChanged(JList.java:1798)
at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1812)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:154)
at javax.swing.DefaultListSelectionModel.setValueIsAdjusting(DefaultListSelectionModel.java:685)
at javax.swing.JList.setValueIsAdjusting(JList.java:2142)
at javax.swing.plaf.basic.BasicListUI$Handler.mouseReleased(BasicListUI.java:2796)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)'
Any ideas? Thanks in advance.
String selectedString = (jList.getSelectedValue().toString());
Looks like this line throws the exception.
You clear selection in the same listener and it in turn calls selection change.
Try to move the value obtaining to be before jList.clearSelection().
Also I would introduce a flag to show the selection change from user's click or from your code which clears selection. Set the flag isMyCode to true (default false) and skip processing if it's true.

AWT-EventQueue-0 error

I have written the following code. Basically I want to activate autocomplete (in a RSyntaxTextArea environment) if the entered character is not space. Everything is working smoothly, but the fact that sometimes I will get the AWT-EventQueue-0 error. The program will still run and function but the error message shows up.
I have other elements in my code, but I am quite sure it is from this bit of added code. Any particular reason for this? I have noticed this error happening when I move the mouse to a second screen.
public static CompletionProvider provider = createModelCompletionProvider();
public static AutoCompletion ac = new AutoCompletion(provider);
public static KeyListener ListenerTOntology = new KeyListener() {
#Override
public void keyPressed(KeyEvent e) {}
#Override
public void keyReleased(KeyEvent e) {}
#Override
public void keyTyped(KeyEvent e) {
dumpInfo("Typed", e);}
private void dumpInfo(String s, KeyEvent e) {
char temp = e.getKeyChar();
if(temp!=' ' )
ac.doCompletion();}
};
Error message:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.fife.ui.rtextarea.FoldIndicator.findOpenFoldClosestTo(FoldIndicator.java:162)
at org.fife.ui.rtextarea.FoldIndicator.access$300(FoldIndicator.java:60)
at org.fife.ui.rtextarea.FoldIndicator$Listener.mouseMoved(FoldIndicator.java:671)
at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:329)
at java.awt.Component.processMouseMotionEvent(Component.java:6550)
at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3339)
at java.awt.Component.processEvent(Component.java:6274)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4505)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
So, I discovered what caused this. You need to use a CaretListener instead of KeyListener. Since RSyntaxTextArea does not contain a DocumentListner.

Adding a new Class File to my project in NetBeans

I have created a GUI for plotting a reporting:
GUI:
package aatmPackage;
import java.awt.Color;
import java.awt.Shape;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.util.ShapeUtilities;
public class GuiAATM extends javax.swing.JFrame {
...
private void reportButtonActionPerformed(java.awt.event.ActionEvent evt) {
report Report = new report();
setReportLog("Report Generated Successfully\n");
}
}
I created another project and tested it which works fine to generate a report. Now When I am adding that class to my GuiAATM project , (where the user when clicks report button should generate the report) I am getting below error:
log4j:WARN Parsing warning 2 and column 38
log4j:WARN URI was not reported to parser for entity [dtd]
log4j:WARN Parsing warning 2 and column 38
log4j:WARN missing system ID, using log4j.dtd
log4j:ERROR Could not parse url [jar:file:/D:/Glaswegian/Java/DynamicCharts/dynamicreports-3.1.0-project-with-dependencies%20(1)/dynamicreports-3.1.0/dist/dynamicreports-examples-3.1.0-sources.jar!/log4j.xml].
gnu.xml.dom.DomEx: The operation violates XML Namespaces.
More Information: xmlns is reserved
Node Name: #document
at gnu.xml.dom.DomDocument.createAttributeNS(DomDocument.java:589)
at gnu.xml.dom.DomDocument.createAttribute(DomDocument.java:561)
at gnu.xml.dom.DomDocument.defaultAttributes(DomDocument.java:456)
at gnu.xml.dom.DomDocument.createElementNS(DomDocument.java:440)
at gnu.xml.pipeline.DomConsumer$Handler.startElement(DomConsumer.java:602)
at gnu.xml.dom.Consumer$Backdoor.startElement(Consumer.java:203)
at gnu.xml.pipeline.EventFilter.startElement(EventFilter.java:570)
at gnu.xml.pipeline.ValidationConsumer.startElement(ValidationConsumer.java:1177)
at gnu.xml.aelfred2.SAXDriver.startElement(SAXDriver.java:836)
at gnu.xml.aelfred2.XmlParser.parseElement(XmlParser.java:1037)
at gnu.xml.aelfred2.XmlParser.parseDocument(XmlParser.java:416)
at gnu.xml.aelfred2.XmlParser.doParse(XmlParser.java:167)
at gnu.xml.aelfred2.SAXDriver.parse(SAXDriver.java:320)
at gnu.xml.aelfred2.XmlReader.parse(XmlReader.java:294)
at gnu.xml.dom.JAXPFactory$JAXPBuilder.parse(JAXPFactory.java:186)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)
at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:612)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:711)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
at org.apache.log4j.Logger.getLogger(Logger.java:104)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289)
at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116)
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at net.sf.dynamicreports.report.defaults.Defaults.<clinit>(Defaults.java:42)
at net.sf.dynamicreports.design.transformation.TemplateTransform.getPageHeight(TemplateTransform.java:663)
at net.sf.dynamicreports.design.transformation.PageTransform.transform(PageTransform.java:44)
at net.sf.dynamicreports.design.base.DRDesignReport.transform(DRDesignReport.java:132)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:107)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:99)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperReportDesign(JasperReportBuilder.java:260)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.getJasperParameters(JasperReportBuilder.java:287)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:298)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.show(JasperReportBuilder.java:327)
at aatmPackage.report.build(report.java:70)
at aatmPackage.report.<init>(report.java:26)
at aatmPackage.GuiAATM.reportButtonActionPerformed(GuiAATM.java:1214)
at aatmPackage.GuiAATM.access$400(GuiAATM.java:34)
at aatmPackage.GuiAATM$5.actionPerformed(GuiAATM.java:968)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.extensions.ExtensionsEnvironment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: gnu.xml.dom.DomElement.getTextContent()Ljava/lang/String;
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseExportFonts(SimpleFontExtensionHelper.java:317)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamily(SimpleFontExtensionHelper.java:285)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamilies(SimpleFontExtensionHelper.java:232)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:193)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:162)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:56)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:110)
at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:153)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:82)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:308)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.show(JasperReportBuilder.java:327)
at aatmPackage.report.build(report.java:70)
at aatmPackage.report.<init>(report.java:26)
at aatmPackage.GuiAATM.reportButtonActionPerformed(GuiAATM.java:1214)
at aatmPackage.GuiAATM.access$400(GuiAATM.java:34)
at aatmPackage.GuiAATM$5.actionPerformed(GuiAATM.java:968)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
BUILD SUCCESSFUL (total time: 6 seconds)
My report.java file is:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package aatmPackage;
import static net.sf.dynamicreports.report.builder.DynamicReports.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Color;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.datasource.DRDataSource;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.dynamicreports.report.builder.style.FontBuilder;
public class report {
public report() {
build();
}
private void build() {
StyleBuilder boldStyle = stl.style().bold();
// FontBuilder boldFont = stl.fontArialBold().setFontSize(12);
Color MAROON = new Color(122, 5, 5);
StyleBuilder titleLineOne = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT).setFontSize(15).setForegroundColor
(MAROON);
StyleBuilder titleNextLine = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT).setFontSize(12).setForegroundColor
(MAROON);
StyleBuilder bodyTitleStyle = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.LEFT).setFontSize(12);
StyleBuilder bodyStyle = stl.style().setFontSize(11);
StyleBuilder signatureStyle = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT);
StyleBuilder footerLeft = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.LEFT).setForegroundColor
(MAROON) ;
StyleBuilder footerRight = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT).setForegroundColor
(MAROON) ;
//BufferedImage img = new BufferedImage(1200,1200,BufferedImage.TYPE_INT_RGB);
BufferedImage img = null;
try {
// img = ImageIO.read(new File("D:/Hysteresis.png"));
img = ImageIO.read(new File("D:/Hysteresis.png"));
} catch (IOException e) {
}
BufferedImage logo = null;
try {
// img = ImageIO.read(new File("D:/Hysteresis.png"));
logo = ImageIO.read(new File("D:/Logo.jpg"));
} catch (IOException e) {
}
try {
report()//create new report design
// .setColumnTitleStyle(boldStyle)
// .setColumnStyle(boldStyle)
.highlightDetailEvenRows()
.columns(//add columns
col.column(null,"Col_1", type.stringType())
.setStyle(bodyStyle),
col.column(null,"Col_2", type.stringType())
.setStyle(bodyStyle)
)
.summary(
cmp.verticalList()
// .add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10))
.add(
cmp.text("\n"),
cmp.filler().setStyle(stl.style().setTopBorder(stl.pen1Point())),
cmp.text("\nHYSTERISIS PLOT\n").setStyle(bodyTitleStyle),
cmp.text(" 1.\n").setStyle(
bodyStyle),
// .add(cmp.image(getClass().getResourceAsStream
// ("D:/Hysteresis.png")).setFixedDimension(300, 300))
cmp.horizontalList()
.add(cmp.image(img).setFixedDimension(350, 250),
//cmp.text("ANALYSIS\n").setStyle(bodyTitleStyle),
cmp.text("Right Lobe Change:160.04%\n").setStyle(bodyStyle),
cmp.text("Left Lobe Change: 35.38%\n").setStyle(bodyStyle),
cmp.text("Hysteresis Change: 81.50%\n").setStyle(bodyStyle)),
//cmp.filler().setStyle(stl.style().setTopBorder(stl.pen1Point())),
cmp.text("REMARKS\n\n\n\n\n\n\n\n").setStyle(bodyTitleStyle),
cmp.text("Doctor Signature").setStyle(signatureStyle))
)
.title(
cmp.horizontalList()
.add(
cmp.image(logo).setFixedDimension(70, 70),
cmp.verticalList()
.add(
cmp.text(" Ltd").setStyle(titleLineOne),
cmp.text(", ").setStyle(titleNextLine),
cmp.text("Mobile +").setStyle(titleNextLine))
)
/* cmp.horizontalList()
.add( cmp.text("Allahabad Bypass Varanasi").setStyle(boldCenteredStyle))
*/
.newRow()
.add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10))
)//shows report title
// .pageFooter(cmp.pageXofY())//shows number of page at page footer
.pageFooter(
Templates.footerComponent,
//cmp.text(" \t\t\t\t\t\t\t\t"
// + " ")
cmp.horizontalList()
.add(cmp.text("Emsol Software Solution").setStyle(footerLeft),
cmp.text("copyright: gauravbvelex#gmail.com").setStyle(footerRight))
)
.setDataSource(createDataSource())//set datasource
.show();//create and show report
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("Col_1", "Col_2");
dataSource.add("Name","Sample");
dataSource.add("Age","26");
dataSource.add("Sex","Female");
dataSource.add("Weight","53 Kg");
dataSource.add("BMI","20");
dataSource.add("Massage Duration (Mins)","4.5");
dataSource.add("RPM","26");
dataSource.add("Doctor Attended","Doctor");
dataSource.add("Date","24-Feb-2013");
return dataSource;
}
}
This report works fine when run as a separate project, then I tried creating a sample jFrame and then added this .java file and run it. When I clicked the button it created the report. But the actual project (which I developed in 20 days GUI and the functionalities) it throws the error shown. I even tried to put the report code in the gui file itself but got the same error. I am not able to resolve the issue.
Can anyone please help?
Thanks
Ok I got the resolution...
It seems Dynamic Charts uses jFreeChart Libraries. I was manually importing libraries for dynamic Charts as well as jFreeChart.
Resolution was : Delted all libraries and then imported only for dynamic charts.
I guess .xml for both libraries were conflicting.
Looks like you have multiple implementations .jar files for XML parsing (maybe multiples versions of xerces in classpath ?).
gnujaxp.jar also could be the source of the problem.

Categories