java - Errors when converting CSV to ARFF in Android using Weka -
i'm sing code , instructions found on weka site https://weka.wikispaces.com/converting+csv+to+arff
reason giving me errors. notice check make sure file exists , readable.
code csvloader.java
https://github.com/rjmarsan/weka-for-android/blob/925a77b566d6e55a775911fbf317234d11ec8024/src/weka/core/converters/csvloader.java
android code
string input = environment.getexternalstoragedirectory().getabsolutepath()+"/homework1/user_patterns.csv"; string output = environment.getexternalstoragedirectory().getabsolutepath()+"/homework1/user_patterns.arff"; instances data = null; try { file inputfile = new file(input); system.out.println(inputfile.exists()); system.out.println(inputfile.canread()); // load csv csvloader loader = new csvloader(); loader.setsource(inputfile); data = loader.getdataset(); // save arff arffsaver saver = new arffsaver(); saver.setinstances(data); saver.setfile(new file(output)); saver.writebatch(); } catch (ioexception err) { system.out.println(err); }
stack trace
09-30 15:23:03.810 22869-22869/com.weka w/dalvikvm﹕ exception ljava/lang/nullpointerexception; thrown while initializing lweka/core/converters/converterutils; 09-30 15:23:03.810 22869-22869/com.weka w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0xa4d12b20) 09-30 15:23:03.814 22869-22869/com.weka e/androidruntime﹕ fatal exception: main process: com.weka, pid: 22869 java.lang.exceptionininitializererror @ weka.core.converters.csvloader.readheader(csvloader.java:882) @ weka.core.converters.csvloader.readstructure(csvloader.java:534) @ weka.core.converters.csvloader.getstructure(csvloader.java:519) @ weka.core.converters.csvloader.getdataset(csvloader.java:552) @ com.weka.mainmenu$1.onclick(mainmenu.java:105) @ android.view.view.performclick(view.java:4438) @ android.view.view$performclick.run(view.java:18422) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ weka.core.converters.converterutils.<clinit>(converterutils.java:741) at weka.core.converters.csvloader.readheader(csvloader.java:882) at weka.core.converters.csvloader.readstructure(csvloader.java:534) at weka.core.converters.csvloader.getstructure(csvloader.java:519) at weka.core.converters.csvloader.getdataset(csvloader.java:552) at com.weka.mainmenu$1.onclick(mainmenu.java:105) at android.view.view.performclick(view.java:4438) at android.view.view$performclick.run(view.java:18422) at android.os.handler.handlecallback(handler.java:733) at android.os.handler.dispatchmessage(handler.java:95) at android.os.looper.loop(looper.java:136) at android.app.activitythread.main(activitythread.java:5001) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:515) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) at com.android.internal.os.zygoteinit.main(zygoteinit.java:601) at dalvik.system.nativestart.main(native method)
note mainmenu.java:105 refers data = loader.getdataset();
try changing code
// load csv csvloader loader = new csvloader(); if(null != inputfile){ loader.setsource(inputfile); data = loader.getdataset(); }else{ log.e("error","error input file null"); }
try , tell me if error in log cat , no crash
Comments
Post a Comment