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.

有帮助吗?

解决方案

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

其他提示

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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top