문제

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