java - When I write .txt in after file name I get nullpointerexception -
whenever write .txt after file name recieve nullpointrexception error. when don't write .txt program seems run says system cannot find specified file. have no idea do. please guide me. code
public void signin(){ //system.out.println(system.getproperty("user.dir")); file file=new file("c:\\workplace\\3rdlastlab\\file1.txt"); try{ filereader fr=new filereader(file); bufferedreader br=new bufferedreader(fr); scanner sc=new scanner(br); string text1=field1.gettext(); string text2=field2.gettext(); string text3=text1+"."+text2; while(sc.hasnext()){ string string= sc.next(); if(text3.equals(string)==true){ joptionpane.showmessagedialog(null, "you logged in!"); } else joptionpane.showmessagedialog(null, "wrong user name or password"); } br.close(); } catch (ioexception e){ joptionpane.showmessagedialog(null, e.getmessage()); } }
and these errors
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ login.signin(login.java:36) @ login.actionperformed(login.java:122) @ javax.swing.abstractbutton.fireactionperformed(unknown source) @ javax.swing.abstractbutton$handler.actionperformed(unknown source) @ javax.swing.defaultbuttonmodel.fireactionperformed(unknown source) @ javax.swing.defaultbuttonmodel.setpressed(unknown source) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(unknown source) @ java.awt.component.processmouseevent(unknown source) @ javax.swing.jcomponent.processmouseevent(unknown source) @ java.awt.component.processevent(unknown source) @ java.awt.container.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source) @ java.awt.lightweightdispatcher.processmouseevent(unknown source) @ java.awt.lightweightdispatcher.dispatchevent(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.window.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$200(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)
looking @ behavior when put correct file name null pointer exception
it looks have issue field1
or field1
( if corresponds line 36)
string text1=field1.gettext(); string text2=field2.gettext();
which may null depending on how setting these
Comments
Post a Comment