Adding a new Class File to my project in NetBeans - java

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.

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

Retrieve an image(Long Blob) from database(SQL) and display it into JLabel

public void displayPhoto() {
con = null;
rs = null;
PreparedStatement preparedStatement = null;
BufferedImage bufImg = null;
String displaySQL = "select * from images where USERNAME =?";
try {
con = getDBConnection();
preparedStatement = con.prepareStatement(displaySQL);
preparedStatement.setString(1, currentuser.getText().trim());
rs = preparedStatement.executeQuery();
while (rs.next()) {
InputStream in = rs.getBinaryStream("IMAGES");
bufImg = ImageIO.read(in);
displayPhoto.setIcon(new ImageIcon(bufImg));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
This is my code and it says NullPointersException.
Here is the full error message
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:228)
at MyProfile.displayPhoto(MyProfile.java:398)
at MyProfile.<init>(MyProfile.java:197)
at Login.actionPerformed(Login.java:93)
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: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)
I've been doing this for a month and I still can't retrieve the image from database, sorry but I don't have any idea about ImageIO and Stream stuff,
displayPhoto = JLabel
and it was positioned using setBounds in a Container
IMAGES = column name,
images = table name,
currentuser = label with text of the user
How to do it and why do I get this error?
You should check that your IMAGES column has no null values for that user. However, the mostly likely cause is ImageIO is unable to read your stored bytes. According to the ImageIO.read() javadoc:
If no registered ImageReader claims to be able to read the resulting stream, null is returned.
The most likely cause is the IMAGE type is not one that ImageIO can handle, or it's corrupt and ImageIO can't read it. As of JDK 1.7, ImageIO by default only handles the following image types:
JPG
PNG
BMP
WBMP
GIF
If your images are a different type, you'll need to go through extra steps to read them.

SwingX AutoCompleteDecorator JTextField Errors

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);

Read with ImageIO non-applet

Okay, so I have all of my classes inside of a few packages:
Game/src/package1/Class.class
and I want to get into a file in:
Game/res/Terrain.png
How would I do this?
public Screen(Game game){
this.game=game;
try {
URL url = new URL("/res/Terrain.png");
textures = ImageIO.read(url);
} catch (IOException e) {
e.printStackTrace();
}
}
then i get this error:
java.net.MalformedURLException: no protocol: /res/Terrain.png
at java.net.URL.<init>(URL.java:583)
at java.net.URL.<init>(URL.java:480)
at java.net.URL.<init>(URL.java:429)
at kore.survival.Screen.<init>(Screen.java:25)
at kore.survival.Game.<init>(Game.java:27)
at kore.survival.Game.main1(Game.java:99)
at kore.survival.LoginFrame.jButton1ActionPerformed(LoginFrame.java:201)
at kore.survival.LoginFrame.access$200(LoginFrame.java:16)
at kore.survival.LoginFrame$3.actionPerformed(LoginFrame.java:82)
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:703)
at java.awt.EventQueue.access$000(EventQueue.java:102)
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
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:676)
at java.awt.EventQueue$4.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
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)
Assuming that the resource is embedded with the Jar...
textures = ImageIO.read(getClass().getResource("/res/Terrain.png"));

Database not found error in Apache Derby

First, this is my first time with Apache Derby. I am using netbeans, willing to use embedded apache derby, and I followed the following tutorial for configuring and installing the database
http://netbeans.org/kb/docs/ide/java-db.html#starting
The attached image will show my database status in netbeans
My database name is "contact". Table name is "FRIENDS".
Following is my test code
DatabaseConnector.java
import java.sql.*;
public class DataBaseConnector
{
private Connection con;
public DataBaseConnector()
{
}
private void createConnection()
{
try
{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
con = DriverManager.getConnection("jdbc:derby:contact","yohan","xyz");
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void closeConnection()
{
try
{
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void insertData(int id, String firstName, String lastName)
{
createConnection();
try
{
PreparedStatement ps = con.prepareStatement("insert into FRIENDS values(?,?,?)");
ps.setInt(1, id);
ps.setString(1, firstName);
ps.setString(2, lastName);
int result = ps.executeUpdate();
if(result>0)
{
System.out.println("Data Inserted");
}
else
{
System.out.println("Something happened");
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
closeConnection();
}
}
}
DatabaseUI.java
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class DatabaseUI extends JFrame
{
private JLabel firstName, id, lastName;
private JTextField idTxt, firstNameTxt, lastNameTxt;
private JButton ok;
public DatabaseUI()
{
firstName = new JLabel("First Name: ");
lastName = new JLabel("Last Name: ");
id = new JLabel("ID: ");
firstNameTxt = new JTextField(10);
lastNameTxt = new JTextField(10);
idTxt = new JTextField(10);
ok = new JButton("OK");
ok.addActionListener(new OKAction());
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(4,2));
centerPanel.add(id);
centerPanel.add(idTxt);
centerPanel.add(firstName);
centerPanel.add(firstNameTxt);
centerPanel.add(lastName);
centerPanel.add(lastNameTxt);
centerPanel.add(new JPanel());
centerPanel.add(ok);
getContentPane().add(centerPanel,"Center");
this.pack();
this.setVisible(true);
}
private class OKAction implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
DataBaseConnector db = new DataBaseConnector();
int id = Integer.parseInt(idTxt.getText());
db.insertData(id, firstNameTxt.getText().trim(), lastNameTxt.getText().trim());
}
}
public static void main(String[]args)
{
new DatabaseUI();
}
}
But, when I am trying to insert data into the database, it is giving me the following error
run:
java.sql.SQLException: Database 'contact' not found.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at DataBaseConnector.createConnection(DataBaseConnector.java:17)
at DataBaseConnector.insertData(DataBaseConnector.java:40)
at DatabaseUI$OKAction.actionPerformed(DatabaseUI.java:52)
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:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
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:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
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:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.sql.SQLException: Database 'contactDB' not found.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 53 more
java.lang.NullPointerException
at DataBaseConnector.insertData(DataBaseConnector.java:43)
at DatabaseUI$OKAction.actionPerformed(DatabaseUI.java:52)
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:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
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:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
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:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
java.lang.NullPointerException
at DataBaseConnector.closeConnection(DataBaseConnector.java:29)
at DataBaseConnector.insertData(DataBaseConnector.java:65)
at DatabaseUI$OKAction.actionPerformed(DatabaseUI.java:52)
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:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
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:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
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:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Please help me. Thanks
The connection URL "jdbc:derby:contact" specifies that the 'contact' database should be found in the current working directory of your process, but that's probably not where it's actually located. When your Java program is run, the current working directory is probably been set somewhere else. You can confirm this by printing out the current working directory at the start of your program.
To get around this for now, you can specify the full path to your database: "jdbc:derby:/path/to/my/db/contact".
If that gets you farther, then you can keep going, but at some point you'll have to think more about where you want your database to be permanently located and how you want to specify that in your program.
Kindly look at your derby/jdbc connection,
This line here:
con = DriverManager.getConnection("jdbc:derby:contact","yohan","xyz");
Check if it looks similar to:
"jdbc:derby://localhost:1527/contact"
Or, as what I've seen, the name of your database is ContactDB... Kindly check...
Thanks...

Categories