Search code examples
javaswingx

NullPointerException in JXImageView


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.


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