These are the msg .... the problem is in the first line (
javax.swing.ImageIcon.<init>(ImageIcon.java:138)
and the others are in consequence of it ?
Thanks a lot.
PS- I am reading "Core Java 2 " vol 1 - Fundamentals (Mc Graw Hill ) .
this is chapter 10....and this is a bug in its program
ResourceTest.java......!!!!
My best guess* is that in the code lines invoked before
that, a call to getResource was made for the image file
(a .jpg, .gif, .png etc.). But it could not be found on the
classpath.
>These are the msg .... the problem is in the first line (
>javax.swing.ImageIcon.<init>(ImageIcon.java:138)
>and the others are in consequence of it ?
The other lines I trimmed are simply the execution
path of the code. They indicate what parts of the code
were visited before the failure. There is only one error.
>PS- I am reading "Core Java 2 " vol 1 - Fundamentals (Mc Graw Hill ) .
> this is chapter 10....
* ..but I am not reading that book, and cannot find
the code on the net, and you did not post it.
So everything I wrote above is simply 'guesses'.
>..and this is a bug in its program
>ResourceTest.java......!!!!
Please fix those sticky '.' and '!' keys.
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200704/1
> class AboutPanel extends JPanel
> {
> public AboutPanel()
> {
> setLayout(new BorderLayout());
>
> // aggiunge area di testo
> textArea = new JTextArea();
> add(new JScrollPane(textArea), BorderLayout.CENTER);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> // add About button
> URL aboutURL = AboutPanel.class.getResource("about.gif");
// I ' ve added the instrution below to trace the preceding
// instruction and I get null . And the about.gif image is
// in the same folder of the .java program .
>
> System.out.println(aboutURL);
>
> JButton aboutButton = new JButton("About",
> new ImageIcon(aboutURL));
> aboutButton.addActionListener(new AboutAction());
> add(aboutButton, BorderLayout.SOUTH);
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Thanks a lot in advance.
Since we do not yet know why this program is failing,
it might be the parts that are not shown, that are causing
the error.
>..and among + signs where I get the error.
>
>> class AboutPanel extends JPanel
What package is AboutPanel declared in? *
..
>> URL aboutURL = AboutPanel.class.getResource("about.gif");
>
> // I ' ve added the instrution below to trace the preceding
> // instruction and I get null .
That was a sensible thing to check.
>...And the about.gif image is
> // in the same folder of the .java program .
* If AboutPanel is in package (and directory)
"helpcomponents", the path to "about.gif" is
"helpcomponents/about.gif".
>
> import java.awt.*;
> import java.awt.event.*;
> import java.io.*;
> import java.net.*;
> import javax.swing.*;
>
> public class ResourceTest
> {
> public static void main(String[] args)
> {
> ResourceTestFrame frame = new ResourceTestFrame();
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> frame.setVisible(true);
> }
> }
>
> /**
> Un frame con un pannello che ha componenti che mostrano
> accesso alle risorse da un file JAR.
> */
> class ResourceTestFrame extends JFrame
> {
> public ResourceTestFrame()
> {
> setTitle("ResourceTest");
> setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
> setContentPane(new AboutPanel());
> }
>
> public static final int DEFAULT_WIDTH = 300;
> public static final int DEFAULT_HEIGHT = 300;
> }
>
> /**
> Un pannello con un'area di testo e un pulsante "About". Premendo
> il pulsante si riempie l'area di testo con un testo da una risorsa.
> */
> class AboutPanel extends JPanel
> {
> public AboutPanel()
> {
> setLayout(new BorderLayout());
>
> // aggiunge area di testo
> textArea = new JTextArea();
> add(new JScrollPane(textArea), BorderLayout.CENTER);
>
> // aggiunge pulsante About
> URL aboutURL = AboutPanel.class.getResource("about.gif");
>
> System.out.println(aboutURL);
>
>
> JButton aboutButton = new JButton("About",
> new ImageIcon(aboutURL));
> aboutButton.addActionListener(new AboutAction());
> add(aboutButton, BorderLayout.SOUTH);
> }
>
> private JTextArea textArea;
>
> private class AboutAction implements ActionListener
> {
> public void actionPerformed(ActionEvent event)
> {
> try
> {
> // legge testo da risorse nell'area di testo
> InputStream in = AboutPanel.class.
> getResourceAsStream("about.txt");
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(in));
> String line;
> while ((line = reader.readLine()) != null)
> textArea.append(line + "\n");
> }
> catch(IOException exception)
> {
> exception.printStackTrace();
> }
> }
> }
> }
What? What is only a file? Are you
referring to the GIF, the Java source, the
package (directory) it is in? Something else?
> .., can you test it ?
What to do you want me to test?
Please refrain from top-posting. I
find it very confusing.
<http://www.physci.org/codes/javafaq.html#toppost>
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via http://www.javakb.com
> What? What is only a file? Are you
> referring to the GIF, the Java source, the
> package (directory) it is in? Something else?
Java source ,of course !
> What to do you want me to test?
the program , if you want ,
not if it is a tragedy , of course.
> Please refrain from top-posting. I
> find it very confusing.
It's a tragedy , I'm afraid.
>