I got an error in my line 508 where I have this code
buf = fgc.grabFrame();
CODE:
startC.addActionListener(new ActionListener()
{
#Override
public void actionPerformed(ActionEvent e)
{
// Grab a frame
FrameGrabbingControl fgc = (FrameGrabbingControl)
player.getControl("javax.media.control.FrameGrabbingControl");
buf = fgc.grabFrame();
// Convert it to an image
BufferToImage btoi = new BufferToImage((VideoFormat)buf.getFormat());
img = btoi.createImage(buf);
// show the image
//imgpanel.setImage(img);
// save image
try {
saveJPG(img,"c:\\test.jpg");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}):
STACK:
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at com.colorfulwolf.webcamapplet.WebcamApplet$6.actionPerformed(WebcamApplet.java:508)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
What's going wrong with this line ?
You need to assign player to an instance:
public static Player player = new Player();
Related
I am trying to delete a student from database, but I got this error:
java.sql.SQLException: database is locked
at org.sqlite.core.DB.throwex(DB.java:859)
at org.sqlite.core.DB.exec(DB.java:142)
at org.sqlite.jdbc3.JDBC3Connection.commit(JDBC3Connection.java:165)
at Controller.deleteStudent(Controller.java:232)
at Test$9.actionPerformed(Test.java:227)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I read other posts on stackoverflow and all of them said that all connections needs to be closed to open a new connection. I did this, but I still got the same problem.
Here's my code:
public static void deleteStudent(int id) {
try {
con = null;
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:test.db");
con.setAutoCommit(false);
stmt = null;
stmt = con.createStatement();
int result = stmt.executeUpdate("DELETE FROM STUDENTS WHERE ID=" + id + ";");
System.out.println(result);
con.commit();
stmt.close();
con.close();
output();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
Do you have ideas why I still get this error?
I have an editable combo box with a key listener. I want to write some text in it and with every letter, it has to make a string with the text I have inserted (or deleted).
But when I want to get the string I get a NullPointerException.
combobox.getEditor().getEditorComponent()
.addKeyListener(new KeyListener()
{
String value="";
#Override
public void keyTyped(KeyEvent e)
{
value = combobox.getSelectedItem().toString();
System.out.println(value);
}
#Override
public void keyReleased(KeyEvent e)
{
}
#Override
public void keyPressed(KeyEvent e)
{
}
});
Stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at auftrag_paket.Neuer_Auftrag_ohneMwSt$25.keyTyped(Neuer_Auftrag_ohneMwSt.java:2037)
at java.awt.Component.processKeyEvent(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.WaitDispatchSupport$2.run(Unknown Source)
at java.awt.WaitDispatchSupport$4.run(Unknown Source)
at java.awt.WaitDispatchSupport$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(Unknown Source)
at java.awt.Dialog.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at auftrag_paket.Auftragsverwaltung$14.actionPerformed(Auftragsverwaltung.java:1865)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Has anyone any ideas?
Don't use a KeyListener that is old code when using AWT. Swing has newer and better API's.
Instead you should be using a DocumentListener. Read the section from the Swing tutorial on How to Write a Document Listener for more information.
To capture any character typed in combobox using KeyListener, you should do it inside keyReleased method, try the following code:
combobox.getEditor().getEditorComponent()
.addKeyListener(new KeyListener()
{
String value="";
#Override
public void keyTyped(KeyEvent e)
{
}
#Override
public void keyReleased(KeyEvent e)
{
value = combo.getSelectedItem().toString();
value = ((JTextField)combo.getEditor().getEditorComponent()).getText();
System.out.println(value);
}
#Override
public void keyPressed(KeyEvent e)
{
}
});
I'm trying an xsl transformation with saxon and I'm having trouble with the file names:
package com.fop;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XMLtoFO {
private static StreamResult out;
private static StreamSource xml;
private static StreamSource xsl;
private static Transformer transformer;
// TODO
protected static void xmlToFO(String inputXSL, String[] inputxml,
String[] fofilname) throws Exception {
if (true) {
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
}
for (int i = 0; i < inputxml.length; i++) {
try {
out = new StreamResult( fofilname[i] );
xml = new StreamSource( inputxml[i] );
xsl = new StreamSource( inputXSL );
transformer = TransformerFactory.newInstance().newTransformer( xsl );
transformer.transform( xml, out );
System.err.println("\n--------------------------------------------------------------------------------------------\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Error on line 12 of root-template.xsl:
java.net.URISyntaxException: Illegal character in path at index 19: 3-Leiter-Steuerung,Methode 2_result.fo.xml
; SystemID: file:/C:/Users/z003a5bp/Desktop/root-template.xsl; Line#: 12; Column#: -1
net.sf.saxon.trans.XPathException: java.net.URISyntaxException: Illegal character in path at index 19: 3-Leiter-Steuerung, Methode 2_result.fo.xml
at net.sf.saxon.serialize.Emitter.makeOutputStream(Emitter.java:200)
at net.sf.saxon.serialize.Emitter.makeWriter(Emitter.java:160)
at net.sf.saxon.serialize.XMLEmitter.openDocument(XMLEmitter.java:145)
at net.sf.saxon.serialize.XMLEmitter.startElement(XMLEmitter.java:309)
at net.sf.saxon.event.NamespaceReducer.startElement(NamespaceReducer.java:73)
at net.sf.saxon.event.ComplexContentOutputter.startContent(ComplexContentOutputter.java:558)
at net.sf.saxon.event.ComplexContentOutputter.startElement(ComplexContentOutputter.java:183)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:424)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:373)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:660)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:138)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:431)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:373)
at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:239)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1057)
at net.sf.saxon.Controller.transformDocument(Controller.java:2080)
at net.sf.saxon.Controller.transform(Controller.java:1903)
at com.fop.XMLtoFO.xmlToFO(XMLtoFO.java:29)
at com.fop.Layout.output(Layout.java:151)
at com.fop.Layout.actionPerformed(Layout.java:168)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.net.URISyntaxException: Illegal character in path at index 19: 3-Leiter-Steuerung, Methode 2_result.fo.xml
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parseHierarchical(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
at net.sf.saxon.serialize.Emitter.makeOutputStream(Emitter.java:172)
... 55 more
The problem is that many filenames have spaces or commas or things like that. What would be the best way to handle that? Have all input files pass through a character-escaping method?
I was looking at this and guess my problem is something similar:
http://sourceforge.net/p/saxon/discussion/94027/thread/b43bb749/
But that discussion is a little over my head.
UPDATE: I changed the constructors accordingly. Now I get this:
Error
I/O error reported by XML parser processing
file:/C:/Users/z003a5bp/Desktop/Workspace/FOP/file:C:/Users/z003a5bp/Desktop/3-Leiter-Steuerung,%20Methode%202.xml: C:\Users\z003a5bp\Desktop\Workspace\FOP\file:C:\Users\z003a5bp\Desktop\3-Leiter-Steuerung, Methode 2.xml (the filename, directory name or volume label syntax is incorrect)
net.sf.saxon.trans.XPathException: I/O error reported by XML parser processing file:/C:/Users/z003a5bp/Desktop/Workspace/FOP/file:C:/Users/z003a5bp/Desktop/3-Leiter-Steuerung,%20Methode%202.xml: C:\Users\z003a5bp\Desktop\Workspace\FOP\file:C:\Users\z003a5bp\Desktop\3-Leiter-Steuerung, Methode 2.xml (the filename, directory name or volume label syntax is incorrect)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:427)
at net.sf.saxon.event.Sender.send(Sender.java:169)
at net.sf.saxon.Controller.transform(Controller.java:1890)
at com.fop.XMLtoFO.xmlToFO(XMLtoFO.java:29)
at com.fop.Layout.output(Layout.java:151)
at com.fop.Layout.actionPerformed(Layout.java:168)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Users\z003a5bp\Desktop\Workspace\FOP\file:C:\Users\z003a5bp\Desktop\3-Leiter-Steuerung, Methode 2.xml (the filename, directory name or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:396)
... 41 more
This is how I read the files:
protected static void openXMLChooser() {
setUIManager();
FileFilter filter = new FileNameExtensionFilter("XML files", "xml");
chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
chooser.addChoosableFileFilter(filter);
chooser.showOpenDialog(null);
if (chooser.getSelectedFile() != null
&& chooser.getSelectedFiles() != null)
infoarea.append("No file(s)\n");
}
And this is how I change the filename:
protected String[] fileName(String exten) {
file = chooser.getSelectedFiles();
pdffilename = new String[file .length];
for (int i = 0; i < file .length; i++) {
pdffilename[i] = file [i].getName();
b = new StringBuilder(pdffilename[i]);
b.replace(pdffilename[i].lastIndexOf("."),
pdffilename[i].lastIndexOf("l") + 1, "_result"+exten+"");
pdffilename[i] = b.toString();
}
return pdffilename;
}
And here I call the function:
XMLtoFO.xmlToFO(inputxsl, inputxml, this.fileName("fo.xml"));
Filenames are not URIs; you are using a filename where a URI is expected.
The simplest answer is to use the constructors for StreamSource that expect a File rather than a URI. So change
new StreamSource(X)
to
new StreamSource(new File(X))
because the "new File()" constructor works with file names. (Internally, the file name will be automatically converted to a URI, but you don't need to worry about that).
I have a JFrame and on the frame I have JButton, what I want is when that file is clicked that the user can load a file using the java JFileChooser.
I declare the FileChooser like this.
JFileChooser fc;
And then here is my code in the action listener for the button.
JButton btnLoad = new JButton("Load .txt");
btnLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showOpenDialog(OpenFile.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would open the file.
System.out.println("Opening: " + file.getName() + ".");
} else {
System.out.println("Open command cancelled by user.");
}
}
});
The error that it is producing me is
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at maple.Netflix$2.actionPerformed(Netflix.java:73)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Here is line 73.
int returnVal = fc.showOpenDialog(Netflix.this);
Just declaring the JFileChooser variable is not enough, as you need to initialize the reference variable, fc, to a valid object first before using it. This is the same as for any other reference variable.
JFileChooser fc = new JFileChooser();
The value of fc is null. It needs to be set to that of an appropriate object before you call methods on it.
Code
public void actionPerformed (ActionEvent e) {
JFileChooser fileChooser=new JFileChooser();
int a=fileChooser.showOpenDialog(null);
if(a==JFileChooser.APPROVE_OPTION) {
FilefileToOpen=fileChooser.getSelectedFile();
BufferedImage bi;
try {
bi = ImageIO.read(new File("C:\\Users\\nexboy94\\Desktop\\IT 2297- Object-Oriented Analysis and Design Project\\Refresh.png"));
lblNewLabel_UploadResidentImageLabel.setIcon(new ImageIcon(bi));
} catch (IOException e2) {
e2.printStackTrace();
}
}
}
Error is this
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ui.CreateResident$8.actionPerformed(CreateResident.java:260)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)