Convert CSV in ARFF in android

妖精的绣舞 提交于 2019-12-11 07:32:58

问题


i have a cvs file that i want to convert in arff format.

I add this external jar in my build path and in libs/: weka-3.6.6-android.jar

My cvs file not have header row and it is like this:

0.56024569272995,0.34556102752685547,0.4986509583393733,0.025362752945036676,0.4992934039810014,0.56024569272995,0.34556102752685547,0.4986509583393733,0.025362752945036676,0.4992934039810014,0.56024569272995,0.34556102752685547,0.0,0.500127645839251,0.4992934039810014
0.5616480112075806,0.33134251832962036,0.48604997404442984,0.024514018315056698,0.48666570100992756,0.5616480112075806,0.33134251832962036,0.48604997404442984,0.024514018315056698,0.48666570100992756,0.5616480112075806,0.33134251832962036,0.0,0.4874815703186685,0.48666570100992756
0.6170566082000732,0.3362383246421814,0.48836380223366727,0.026372415937359308,0.4890729818269294,0.6170566082000732,0.3362383246421814,0.48836380223366727,0.026372415937359308,0.4890729818269294,0.6170566082000732,0.3362383246421814,0.0,0.4898928868146426,0.4890729818269294

According to weka website this code makes conversion from cvs to arff:

public void convertCSVtoArff(String activity){

    try {
    String file_source = activity + ".csv";
    String file_dest = activity + ".arff";

    // load CSV
    CSVLoader loader = new CSVLoader();
    loader.setSource(new File(file_path + "samples/" + file_source));
    String[] options = {"-H"};
    loader.setOptions(options);

    Instances data = loader.getDataSet();

    // save ARFF
    ArffSaver saver = new ArffSaver();
    saver.setInstances(data);
    saver.setFile(new File(file_path + "samples/" + file_dest));
    saver.setDestination(new File(file_path + "samples/" + file_dest));
    saver.writeBatch();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

When i run the android application, LogCat gives me this error:

E/AndroidRuntime(23492): FATAL EXCEPTION: main
E/AndroidRuntime(23492):     
java.lang.ExceptionInInitializerError
E/AndroidRuntime(23492):at  
weka.core.converters.CSVLoader.readHeader(CSVLoader.java:882)
E/AndroidRuntime(23492):at   
weka.core.converters.CSVLoader.readStructure(CSVLoader.java:534)
E/AndroidRuntime(23492):at   
weka.core.converters.CSVLoader.getStructure(CSVLoader.java:519)
E/AndroidRuntime(23492):at 
weka.core.converters.CSVLoader.getDataSet(CSVLoader.java:552)
E/AndroidRuntime(23492):at 
com.unipa.file.FileOperation.convertCSVtoArff(FileOperation.java:151)
E/AndroidRuntime(23492):at   
      .
      .
      .
E/AndroidRuntime(23492): Caused by: java.lang.NullPointerException
E/AndroidRuntime(23492):    at weka.core.converters.ConverterUtils.<clinit>  
(ConverterUtils.java:741)
E/AndroidRuntime(23492):    ... 19 more

I dont't understand what is the problem.

Can help me to solve this problem?

Thanks in advance and sorry for my english.

来源:https://stackoverflow.com/questions/37373515/convert-csv-in-arff-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!