Question

I'm having a problem with the following code.It's throwing a NullPointerException.

    private org.jdesktop.swingx.JXImageView Logo;
    public Login(){
    try{
        Logo.setImageString("logo_medical.jpg");
    }
    catch(Exception e){
        System.out.println(e);
    }
    initComponents();
}        

The picture "log_medical.jpg" is included int the src folder of the project.

Était-ce utile?

La solution

where is the intialization??

 private org.jdesktop.swingx.JXImageView Logo  =  ???

with out that you are trying to use it

 Logo.setImageString("logo_medical.jpg"); //here Logo is null

You should instantiate in order to use it

private org.jdesktop.swingx.JXImageView Logo  = new JXImageView();

And Follow java naming conventions

Logo should be logo

Autres conseils

Logo is not initialized, it is set to null. Not sure what init is doing but you may have to put it before anything else, try this:

   private org.jdesktop.swingx.JXImageView Logo;
    public Login(){
    initComponents();
    try{
        Logo.setImageString("logo_medical.jpg");
    }
    catch(Exception e){
        System.out.println(e);
    }
} 
private org.jdesktop.swingx.JXImageView Logo;

is just a reference.You need to instantiate Logo variable.

private org.jdesktop.swingx.JXImageView Logo = new org.jdesktop.swingx.JXImageView();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top