0

在我的应用程序中,我根据从数据库中获得的数据计算了一些特征(平均值、最大值、分箱分布等)。但是当我尝试将这些功能写入文件时,它只显示 null 其中特定的功能变量。我看着并试图找到问题的根源,但找不到解决方案。这是我计算在文件上显示 null 的值(它仅在 binz10 上显示 null):

i=1;

    first=minZ;
    next=minZ+zInterval;
    while(i<=10){
        Cursor myCursor2;
        if(i==10)
            myCursor2=db.rawQuery("SELECT * from Koordinatlar where zKoor>="+first+" AND zKoor<="+next+" AND zaman>="+firstTime+" AND zaman<="+lastTime,null);
        else
            myCursor2=db.rawQuery("SELECT * from Koordinatlar where zKoor>="+first+" AND zKoor<"+next+" AND zaman>="+firstTime+" AND zaman<="+lastTime,null);       

        myContentValues.put("binZ"+i, myCursor2.getCount());
        i++;
        first=next;
        next=next+zInterval;
    }

这就是我将它写入文件(csv 格式)的地方:

private void dosyayaYaz(){

    Cursor dataReader;

        File myFile;  
        myFile= new File("sdcard/"+label+"-features.csv");


            try {
                myFile.createNewFile();
            FileOutputStream fOut = new FileOutputStream(myFile);
            OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);

            myOutWriter.append("ortX;ortY;ortZ;stdX;stdY;stdZ;maxX;maxY;maxZ;aadX;aadY;aadZ;averageResultantAcc;binX1;binX2;binX3;binX4;binX5;binX6;binX7;binX8;binX9;binX10;binY1;binY2;binY3;binY4;binY5;binY6;binY7;binY8;binY9;binY10;binZ1;binZ2;binZ2;binZ3;binZ4;binZ5;binZ6;binZ7;binZ8;binZ9;binZ10;label");
            myOutWriter.append("\n");


            dataReader=db.rawQuery("SELECT * FROM Features", null);

            while(dataReader.moveToNext()){


                Float ortX1=(dataReader.getFloat(dataReader.getColumnIndex("ortX")));
                Float ortY1=(dataReader.getFloat(dataReader.getColumnIndex("ortY")));
                Float ortZ1=(dataReader.getFloat(dataReader.getColumnIndex("ortZ")));
                Float maxX1=(dataReader.getFloat(dataReader.getColumnIndex("maxX")));
                Float maxY1=(dataReader.getFloat(dataReader.getColumnIndex("maxY")));
                Float maxZ1=(dataReader.getFloat(dataReader.getColumnIndex("maxZ")));
                Float stdX1=(dataReader.getFloat(dataReader.getColumnIndex("stdX")));
                Float stdY1=(dataReader.getFloat(dataReader.getColumnIndex("stdY")));
                Float stdZ1=(dataReader.getFloat(dataReader.getColumnIndex("stdZ")));
                Float aadX1=(dataReader.getFloat(dataReader.getColumnIndex("aadX")));
                Float aadY1=(dataReader.getFloat(dataReader.getColumnIndex("aadY")));
                Float aadZ1=(dataReader.getFloat(dataReader.getColumnIndex("aadZ")));

                int binX1=(dataReader.getInt(dataReader.getColumnIndex("binX1")));
                int binX2=(dataReader.getInt(dataReader.getColumnIndex("binX2")));
                int binX3=(dataReader.getInt(dataReader.getColumnIndex("binX3")));
                int binX4=(dataReader.getInt(dataReader.getColumnIndex("binX4")));
                int binX5=(dataReader.getInt(dataReader.getColumnIndex("binX5")));
                int binX6=(dataReader.getInt(dataReader.getColumnIndex("binX6")));
                int binX7=(dataReader.getInt(dataReader.getColumnIndex("binX7")));
                int binX8=(dataReader.getInt(dataReader.getColumnIndex("binX8")));
                int binX9=(dataReader.getInt(dataReader.getColumnIndex("binX9")));
                int binX10=(dataReader.getInt(dataReader.getColumnIndex("binX10")));

                int binY1=(dataReader.getInt(dataReader.getColumnIndex("binY1")));
                int binY2=(dataReader.getInt(dataReader.getColumnIndex("binY2")));
                int binY3=(dataReader.getInt(dataReader.getColumnIndex("binY3")));
                int binY4=(dataReader.getInt(dataReader.getColumnIndex("binY4")));
                int binY5=(dataReader.getInt(dataReader.getColumnIndex("binY5")));
                int binY6=(dataReader.getInt(dataReader.getColumnIndex("binY6")));
                int binY7=(dataReader.getInt(dataReader.getColumnIndex("binY7")));
                int binY8=(dataReader.getInt(dataReader.getColumnIndex("binY8")));
                int binY9=(dataReader.getInt(dataReader.getColumnIndex("binY9")));
                int binY10=(dataReader.getInt(dataReader.getColumnIndex("binY10")));

                int binZ1=(dataReader.getInt(dataReader.getColumnIndex("binZ1")));
                int binZ2=(dataReader.getInt(dataReader.getColumnIndex("binZ2")));
                int binZ3=(dataReader.getInt(dataReader.getColumnIndex("binZ3")));
                int binZ4=(dataReader.getInt(dataReader.getColumnIndex("binZ4")));
                int binZ5=(dataReader.getInt(dataReader.getColumnIndex("binZ5")));
                int binZ6=(dataReader.getInt(dataReader.getColumnIndex("binZ6")));
                int binZ7=(dataReader.getInt(dataReader.getColumnIndex("binZ7")));
                int binZ8=(dataReader.getInt(dataReader.getColumnIndex("binZ8")));
                int binZ9=(dataReader.getInt(dataReader.getColumnIndex("binZ9")));
                int binZ10=(dataReader.getInt(dataReader.getColumnIndex("binZ10")));

                String tempLabel=(dataReader.getString(dataReader.getColumnIndex("label")));

                Float averageResultantAcc1=(dataReader.getFloat(dataReader.getColumnIndex("averageResultantAcc")));


                myOutWriter.append(String.format("%f",ortX1)+";"+String.format("%f",ortY1)+";"+String.format("%f",ortZ1)+";"+String.format("%f",stdX1)+";"+String.format("%f",stdY1)+";"+String.format("%f",stdZ1)+";"+String.format("%f",maxX1)+";"+String.format("%f",maxY1)+";"+String.format("%f",maxZ1)+";"+String.format("%f",aadX1)+";"+String.format("%f",aadY1)+";"+String.format("%f",aadZ1)+";"+String.format("%f",averageResultantAcc1)+";"+String.format("%d",binX1)+";"+String.format("%d",binX2)+";"+String.format("%d",binX3)+";"+String.format("%d",binX4)+";"+String.format("%d",binX5)+";"+String.format("%d",binX6)+";"+String.format("%d",binX7)+";"+String.format("%d",binX8)+";"+String.format("%d",binX9)+";"+String.format("%d",binX10)+";"+String.format("%d",binY1)+";"+String.format("%d",binY2)+";"+String.format("%d",binY3)+";"+String.format("%d",binY4)+";"+String.format("%d",binY5)+";"+String.format("%d",binY6)+";"+String.format("%d",binY7)+";"+String.format("%d",binY8)+";"+String.format("%d",binY9)+";"+String.format("%d",binY10)+";"+String.format("%d",binZ1)+";"+String.format("%d",binZ2)+";"+String.format("%d",binZ3)+";"+String.format("%d",binZ4)+";"+String.format("%d",binZ5)+";"+String.format("%d",binZ6)+";"+String.format("%d",binZ7)+";"+String.format("%d",binZ8)+";"+String.format("%d",binZ9)+";"+String.format("%d",binZ10)+";"+tempLabel);
                myOutWriter.append("\n");

            }

            myOutWriter.close();
            fOut.close();



            Toast toast=Toast.makeText(this.myContext, "Feature'lar başarıyla üretilip dosyaya yazıldı...",Toast.LENGTH_SHORT);
            toast.show();

        } 
        catch(IOException ex){
            Toast toast=Toast.makeText(this.myContext, "Dosyaya yazma sırasında bir hata oluştu"+" "+ex.toString(),Toast.LENGTH_LONG);
            toast.show();
        }

}
4

1 回答 1

0

我终于可以找到解决方案了。所有的问题是我在填写文件中的功能文本时不小心。

于 2013-01-19T20:56:36.840 回答