How do I add an Image to an applet in Eclipse? - java

I am trying to add an image to an applet and I keep on failing. I am following http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html but first of all, getCodeBase() is not defined. Then I got rid of it and came up with this code, which is giving some error messages and is not working. I am just getting a blank screen.
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class Cricket extends Canvas{
BufferedImage background;
/**
*
*/
private static final long serialVersionUID = 1L;
public Cricket() {
setSize(1000,500);
setBackground(Color.white);
}
#Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
try {
URL url = new URL("resources/cricket_homescreen.png");
background = ImageIO.read(url);
} catch (IOException e) {
}
g.drawImage(background, 0, 0, null);
}
}
And I keep on getting these error messages:
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at MTProgramming.getImage(MTProgramming.java:18)
at MTProgramming.paint(MTProgramming.java:30)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.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)
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at MTProgramming.getImage(MTProgramming.java:18)
at MTProgramming.paint(MTProgramming.java:30)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.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)
Any ideas of what I am doing wrong here? (by the way my package explorer shows that the files are fine)

Related

AWT-EventQueue-0 while render TIFF files

I'm trying to develop a image viewer in java, my code works good for almost all the formtas, but at the moment to render the images, I'm using the next code:
private ImageIcon scaleImage(int indice, int w, int h, boolean thumbnail) {
ImageIcon image = null;
ImageIO.setUseCache(false);
if(fileRefernces.get(indice).toLowerCase().endsWith("tif") || fileRefernces.get(indice).toLowerCase().endsWith("tiff") ) {
File initialImage = new File(fileRefernces.get(indice));
try {
BufferedImage bImage = ImageIO.read(initialImage);
image = new ImageIcon(bImage);
bImage.flush();
bImage = null;
} catch (IOException ex) {
//Logger.getLogger(ImageRender.class.getName()).log(Level.SEVERE, null, ex);
}
initialImage = null;
} else {
image = new ImageIcon(fileRefernces.get(indice));
}
int nw = image.getIconWidth();
int nh = image.getIconHeight();
if(nw > w) {
nw = w;
nh = (nw * image.getIconHeight()) / image.getIconWidth();
}
if(nh > h) {
nh = h;
nw = (image.getIconWidth() * nh) / image.getIconHeight();
}
System.gc();
return (thumbnail)
? new ImageIcon(image.getImage().getScaledInstance(nw, nh, Image.SCALE_FAST ))
: new ImageIcon(image.getImage().getScaledInstance(nw, nh, Image.DEFAULT));
}
But, I get the next error while is running.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$2(ImageRender.java:700)
at java.awt.event.InvocationEvent.dispatch(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.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) Exception in thread "Thread-6" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.CompletarMiniaturas(ImageRender.java:752)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$3(ImageRender.java:716)
at java.lang.Thread.run(Unknown Source) Exception in thread "AWT-EventQueue-0" Exception in thread "Thread-9" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$2(ImageRender.java:700)
at java.awt.event.InvocationEvent.dispatch(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.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) java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.CompletarMiniaturas(ImageRender.java:752)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$3(ImageRender.java:716)
at java.lang.Thread.run(Unknown Source) Exception in thread "Thread-10" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.CompletarMiniaturas(ImageRender.java:752)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$3(ImageRender.java:716)
at java.lang.Thread.run(Unknown Source) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$2(ImageRender.java:700)
at java.awt.event.InvocationEvent.dispatch(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.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) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$2(ImageRender.java:700)
at java.awt.event.InvocationEvent.dispatch(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.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) Exception in thread "Thread-11" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.bog.company.render.ImageRender.scaleImage(ImageRender.java:815)
at com.bog.company.render.ImageRender.CompletarMiniaturas(ImageRender.java:752)
at com.bog.company.render.ImageRender.lambda$CargarDocumento$3(ImageRender.java:716)
at java.lang.Thread.run(Unknown Source)
But, this happens with the tif images. Someone has an idea about how to solve it?

Save Word-file with Java (runnable JAR)

I´m trying to build an application which can read information from Excel files and place the data into a document. The document is a form of a template with columns in. Everything works just fine until the saving part.
It work, almost, like it should when I run the program directly in IntelliJ. However, when I install the application to an runnable JAR with Maven - the JAR won't work.
The file is saved as desired... But the new file contains nothing if I run the application from JAR. When i run directly in IntelliJ, the new file is been created and opened, but of 3 columns / row, only 2 has data in it.
What can I do?
Link to template document
http://www.labelmedia.de/englisch/doc/70%20x%2032%20mm%20-%20Art.%2088%2010%2027%2070%2032.doc
Thank you in advanced
package utils;
import model.Customers;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class WriteToDocument {
String TARGET_FILE = "src\\main\\java\\utils\\template\\template.doc";
private int postInList = 0;
public WriteToDocument() {}
public WriteToDocument(ArrayList<Customers> list) throws IOException {
list.remove(0);
HWPFDocument doc = null;
try {
doc = openDocument(TARGET_FILE);
Range range = doc.getRange();
TableIterator itr = new TableIterator(range);
while (itr.hasNext()) {
Table table = itr.next();
for (int rowIndex = 0; rowIndex < table.numRows(); rowIndex++) {
TableRow row = table.getRow(rowIndex);
for (int colIndex = 0; colIndex < row.numCells(); colIndex++) {
TableCell cell = row.getCell(colIndex);
//WRITE IN TABLE //
if (postInList < list.size()) {
cell.getParagraph(0).replaceText(list.get(postInList).getName() + "\n\r" +
"\n\r" + list.get(postInList).getAddress() + "\n\r" +
list.get(postInList).getPostcode() + " " + list.get(postInList).getCity(), false);
postInList++;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
saveDocument(doc);
}
}
private HWPFDocument openDocument(String file) throws Exception {
System.out.println("OPEN");
return new HWPFDocument(new POIFSFileSystem(new FileInputStream(file)));
}
private static void saveDocument(HWPFDocument doc) throws IOException {
System.out.println("SAVE");
try (FileOutputStream out = new FileOutputStream(new File("test.doc"))) {
doc.write(out);
out.flush();
System.out.println("File saved");
doc.close();
out.close();
Desktop dt = Desktop.getDesktop();
dt.open(new File("test.doc"));
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
Stacktrace
java.io.FileNotFoundException: src\main\java\utils\template\template.doc (Det går inte att hitta sökvägen)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at utils.WriteToDocument.openDocument(WriteToDocument.java:56)
at utils.WriteToDocument.<init>(WriteToDocument.java:25)
at utils.ReadExcel.writeToDocument(ReadExcel.java:64)
at utils.ReadExcel.<init>(ReadExcel.java:57)
at MainFrameController$1.actionPerformed(MainFrameController.java:31)
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)
SAVE
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at utils.WriteToDocument.saveDocument(WriteToDocument.java:62)
at utils.WriteToDocument.<init>(WriteToDocument.java:49)
at utils.ReadExcel.writeToDocument(ReadExcel.java:64)
at utils.ReadExcel.<init>(ReadExcel.java:57)
at MainFrameController$1.actionPerformed(MainFrameController.java:31)
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)
Most probably you are missing libraries when it is exported as a JAR. You are using Apache POI as external libraries. Inside the IDE all the libraries were applied but when exported, they seems to be missing. Just run the jar file from command prompt to be 100% clear about the issue. In IDEs like NetBeans the libraries are exported into a separate folder called lib have a look for similar related to your IDE as well.

NullPointerException when calling getSelectedItem() on an editable JComboBox

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

why i am getting Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError?

i found a java file on the web that allows me to read a pdf in a url and save it to my local machine,
i have sucsesfully compiled it and customized as a javabean so i can useit in my app, but when i test it i am getting the next error message.
i have added the library (PDFOne.jar file) to my project in netbean and averything compiles well.
in fact, the program detect my pdf url and validate it saying is a valid pdf file, but then the error comes:
any tip ? i am completely new in java world.
thanks in advance
Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: com/gnostice/pdfone/PdfDocument
at Read_PDF_From_URL.setProperty(Read_PDF_From_URL.java:51)
at oracle.forms.handler.ComponentItem.setCustomProperty(Unknown Source)
at oracle.forms.handler.ComponentItem.onUpdate(Unknown Source)
at oracle.forms.handler.JavaContainer.onUpdate(Unknown Source)
at oracle.forms.handler.UICommon.onUpdate(Unknown Source)
at oracle.forms.engine.Runform.onUpdateHandler(Unknown Source)
at oracle.forms.engine.Runform.processMessage(Unknown Source)
at oracle.forms.engine.Runform.processSet(Unknown Source)
at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
at oracle.forms.engine.Runform.onMessage(Unknown Source)
at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
at oracle.ewt.lwAWT.LWComponent.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$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.lang.ClassNotFoundException: com.gnostice.pdfone.PdfDocument
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 39 more
here is part of the source code:
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.net.URL;
import java.net.URLConnection;
import oracle.forms.properties.*;
import oracle.forms.ui.*;
import com.gnostice.pdfone.PdfDocument;
import java.net.MalformedURLException;
public class Read_PDF_From_URL extends VTextArea {
private static final ID GEN = ID.registerProperty("sav");
public boolean setProperty(ID id, Object value) {
boolean retorno = true;
try {
if (id == GEN) {
System.out.println("if");
URL url1 =
new URL("http://www.gnostice.com/downloads/Gnostice_PathQuest.pdf");
byte[] ba1 = new byte[1024];
int baLength;
FileOutputStream fos1 = new FileOutputStream("sibdownload.pdf");
// Contacting the URL
System.out.print("Connecting to " + url1.toString() + " ... ");
URLConnection urlConn = url1.openConnection();
// Checking whether the URL contains a PDF
if (!urlConn.getContentType().equalsIgnoreCase("application/pdf")) {
System.out.println("FAILED.\n[Sorry. This is not a PDF.]");
} else {
try {
// Read the PDF from the URL and save to a local file
InputStream is1 = url1.openStream();
while ((baLength = is1.read(ba1)) != -1) {
fos1.write(ba1, 0, baLength);
}
fos1.flush();
fos1.close();
is1.close();
// Load the PDF document and display its page count
System.out.print("DONE.\nProcessing the PDF ... ");
PdfDocument doc = new PdfDocument();
try {
doc.load("sibdownload.pdf");
System.out.println("DONE.\nNumber of pages in the PDF is " +
I have resolved my question... The first thing was that I've needed to include the jar file in my classpath and the second thing that I've needed to sign the jar file.

NullPointerException when try to capture imagem from webcam

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

Categories