6 Replies - 402 Views - Last Post: 29 September 2015 - 10:30 AM Rate Topic: -----

#1 Francesco93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-September 15

(Applet) - NullPointerException on getResource() ONLY IN BROWSER

Posted 29 September 2015 - 09:35 AM

Hi guys, i'm writing here because i'm really getting sick on a strange problem with my applet...


I made this simple applet:

package gui.clientGUI;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

@SuppressWarnings("serial")
public class MyApplet extends JApplet {
	public MyApplet() {
	}

	public void init() {
        try {
          
        	SwingUtilities.invokeLater(new Runnable() {
            
        		public void run() {
                
        			initUI();
                }
            });
        } catch (Exception e) {
            
        	e.printStackTrace();
        }
    }

    private void initUI() {
        
        JButton btnStartApplication = new JButton("Start Application");
        btnStartApplication.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
            	SS oi = new SS();
                oi.setVisible(true);
            }
        });
        getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        getContentPane().add(btnStartApplication);
    }
}

@SuppressWarnings("serial")
class SS extends JWindow {

	private JLabel lblNewLabel;
    private JLabel label;

    public SS() {
        setBounds(new Rectangle(0, 0, 883, 590));
        setLocationRelativeTo(null);
        getContentPane().setLayout(null);

        lblNewLabel = new JLabel("Welcome", SwingConstants.CENTER);
        lblNewLabel.setForeground(Color.RED);
        lblNewLabel.setFont(new Font("Segoe UI", Font.BOLD | Font.ITALIC, 24));
        lblNewLabel.setBounds(0, 313, 883, 41);
        getContentPane().add(lblNewLabel);

        label = new JLabel("");
        label.setIcon(new ImageIcon(getClass().getResource("/gui/resources/Qtminer_background.jpg")));
		label.setBounds(0, 0, 883, 592);
        getContentPane().add(label);

        setVisible(true);
    }
}


this is the HTML tag:

<applet 
    code="gui.clientGUI.MyApplet.class" 
    archive="QTminer.jar"
    alt="Java is DISABLED in this browser!"
    width="800"
    height="800">
This browser does not recognize the applet element! 
</applet>


The attachment shows what does my jar contains..


The problem is that everytime i try to execute my applet in my IDE, everything works.

BUT: when trying to execute applet in browser, i get everytime a NullPointerException right here:

Quote

java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)


That is:

label.setIcon(new ImageIcon(getClass().getResource("/gui/resources/Qtminer_background.jpg")));
		label.setBounds(0, 0, 883, 592);


Please can you help me to solve this? I'm really sure the path is correct, what should i do??? Do i have to modify my classpath file or Manifest?

Really thanks for your help.

P.S= Sorry for my bad english, i'm italian.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: (Applet) - NullPointerException on getResource() ONLY IN BROWSER

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3464
  • View blog
  • Posts: 15,676
  • Joined: 20-September 08

Re: (Applet) - NullPointerException on getResource() ONLY IN BROWSER

Posted 29 September 2015 - 09:54 AM

Make sure you've completely emptied the browser/JRE cache. You could be looking at an earlier iteration

Using another browser could help too

This post has been edited by g00se: 29 September 2015 - 09:54 AM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#3 Francesco93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-September 15

Re: (Applet) - NullPointerException on getResource() ONLY IN BROWSER

Posted 29 September 2015 - 09:59 AM

View Postg00se, on 29 September 2015 - 09:54 AM, said:

Make sure you've completely emptied the browser/JRE cache. You could be looking at an earlier iteration

Using another browser could help too



Done, nothing happened. i'm doing these tests with Internet Explorer since Google Chrome doesn't support java applications anymore.

Other suggestions? is really my code that is not working or should i face problems about something else?

P.S= i'm using windows 10.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3464
  • View blog
  • Posts: 15,676
  • Joined: 20-September 08

Re: (Applet) - NullPointerException on getResource() ONLY IN BROWSER

Posted 29 September 2015 - 10:07 AM

It looks fine. If you can post the jar somewhere, i'll try it

Incidentally, if the applet is not on a web server, it's really pointless using one
Was This Post Helpful? 0
  • +
  • -

#5 Francesco93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-September 15

Re: (Applet) - NullPointerException on getResource() ONLY IN BROWSER

Posted 29 September 2015 - 10:15 AM

View Postg00se, on 29 September 2015 - 10:07 AM, said:

It looks fine. If you can post the jar somewhere, i'll try it

Incidentally, if the applet is not on a web server, it's really pointless using one



here it is:

http://www.francesco...org/applet.html

WAAAIIITTT WAITTT WAAAAIT



I just tried it on the link i posted before and it works!!!! SOMETHING DENIED ACCESS TO MY LOCAL FILE ON MY COMPUTER.

Damned windows 10....

Really, sorry for having bothered you...
Was This Post Helpful? 0
  • +
  • -

#6 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1461
  • View blog
  • Posts: 3,289
  • Joined: 30-January 11

Re: (Applet) - NullPointerException on getResource() ONLY IN BROWSER

Posted 29 September 2015 - 10:27 AM

I would be thanking Windows 10 for blocking that kind of behaviour by default. There isn't any reason to use applets these days unless it's an explicit requirement for these exact reasons.
Was This Post Helpful? 0
  • +
  • -

#7 Francesco93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-September 15

Re: (Applet) - NullPointerException on getResource() ONLY IN BROWSER

Posted 29 September 2015 - 10:30 AM

Yes, you are right, unfortunately i must take an exam and if i didn't have this website my application would have never run.


However, i have an other problem now that is not really linked to this, should i do an other thread or could we continue here?

P.S=Really thanks for your time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1