i creating 'save' specific file , 'open' specific file. save feature working since have implemented 'open' feature has stopped working. when open feature run printing it's contents console @ moment below error shown in console , first item of array list shown in console. 'open' , 'save' features right @ bottom of code before 2 classes 'record' , 'getrecord' used 'save' , 'open' functions. confused , not sure how proceed don't know whats wrong.
how code appears:
miopen.setonaction(new eventhandler<actionevent>(){ @override public void handle(actionevent arg0) { fileinputstream fis=null; try{ fis = new fileinputstream("testsave.txt"); } catch (filenotfoundexception e){ e.printstacktrace(); } system.out.println("test open b4"); string openstring = new string(); bufferedreader bwo = new bufferedreader(new inputstreamreader(fis)); try { while( (openstring=bwo.readline()) != null) { string [] g = openstring.split(","); system.out.println("test open"); system.out.println(openstring); getrecordsarray.add(new getrecord(g[0], double.parsedouble(g[1]), double.parsedouble(g[2]), double.parsedouble(g[3]), double.parsedouble(g[4]), double.parsedouble(g[5]), double.parsedouble(g[6]), double.parsedouble(g[7]))); } } catch (numberformatexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } try { fis.close(); } catch (ioexception e1) { e1.printstacktrace(); } }}); misave.setonaction(new eventhandler<actionevent>(){ @override public void handle(actionevent arg0) { filechooser.settitle("testsave1.txt"); try (bufferedwriter bw = new bufferedwriter(new filewriter("testsave1.txt", true))) { for(record r : records) bw.write(r.name + "," + r.age + "," + r.gender + "," + r.ethnicity + "," + r.answera + "," + r.answerb + "," + r.answerc + "," + count); bw.newline(); } catch (ioexception e) { e.printstacktrace(); } system.out.println("saved"); if (autoreturn==1){ system.out.println("saved fade"); fadetransition ft = new fadetransition(duration.millis(3000), savemsg1); ft.setfromvalue(0); ft.settovalue(1); ft.play(); fadetransition ft2 = new fadetransition(duration.millis(3000), savemsgl1); ft2.setfromvalue(0); ft2.settovalue(1); ft2.play(); } }}); } void savefile(file save) { fileoutputstream fos=null; try{ fos = new fileoutputstream(save); } catch (filenotfoundexception e){ e.printstacktrace(); } try{ fos.close(); } catch (ioexception e){ e.printstacktrace(); } } }
this error thrown in console when 'open' button run:
exception in thread "javafx application thread" java.lang.arrayindexoutofboundsexception: 1 @ surveyapp$10.handle(surveyapp.java:1181) @ surveyapp$10.handle(surveyapp.java:1) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:86) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:49) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.control.menuitem.fire(menuitem.java:462) @ com.sun.javafx.scene.control.skin.contextmenucontent$menuitemcontainer.doselect(contextmenucontent.java:1405) @ com.sun.javafx.scene.control.skin.contextmenucontent$menuitemcontainer.lambda$createchildren$343(contextmenucontent.java:1358) @ com.sun.javafx.event.compositeeventhandler$normaleventhandlerrecord.handlebubblingevent(compositeeventhandler.java:218) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:80) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:54) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.scene$mousehandler.process(scene.java:3757) @ javafx.scene.scene$mousehandler.access$1500(scene.java:3485) @ javafx.scene.scene.impl_processmouseevent(scene.java:1762) @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2494) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:352) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:275) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.lambda$handlemouseevent$355(glassvieweventhandler.java:388) @ com.sun.javafx.tk.quantum.quantumtoolkit.runwithoutrenderlock(quantumtoolkit.java:389) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(glassvieweventhandler.java:387) @ com.sun.glass.ui.view.handlemouseevent(view.java:555) @ com.sun.glass.ui.view.notifymouse(view.java:937)
obviously text read in file , try split via ',' doesn't consist of structure expect hard-coded array indices:
getrecordsarray.add(new getrecord(g[0], double.parsedouble(g[1]), double.parsedouble(g[2]), double.parsedouble(g[3]), double.parsedouble(g[4]), double.parsedouble(g[5]), double.parsedouble(g[6]), double.parsedouble(g[7])));
Comments
Post a Comment