java - Getting an unexpected error when trying to load files into a JList -
i'm trying build java-based network manager unix-based systems, ran trouble cant quite find source of:
exception in thread "main" java.lang.nullpointerexception @ net.argvarg.networkmanual.selectconfdialog.loadconflist(selectconfdialog.java:51) @ net.argvarg.networkmanual.selectconfdialog.<init>(selectconfdialog.java:20) @ net.argvarg.networkmanual.main.run(main.java:16) @ net.argvarg.networkmanual.main.main(main.java:7) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ com.intellij.rt.execution.application.appmain.main(appmain.java:134)
here the parts of file giving error:
package net.argvarg.networkmanual; import javax.swing.*; import java.awt.event.*; import java.io.file; public class selectconfdialog extends jdialog { private defaultlistmodel conflist = new defaultlistmodel(); private jlist conflistcontainer = new jlist(conflist); private file[] confs = new file(main.absolutepathtoconfsdir).listfiles(); private void loadconflist() { (int = 0; < confs.length - 1; i++) { conflist.addelement(confs[i].getname()); } } }
any appreciated, thank you.
based on comments above, here resolve
private void loadconflist() { if(confs == null || confs.length == 0){ conflist.addelement("failed load conf."); return; }//confs == null | empty (int = 0; < confs.length - 1; i++) { conflist.addelement(confs[i].getname()); } }//loadconflist()
credit goes @madprogrammer, if posts answer, mark his.
Comments
Post a Comment