1

我必须从 96000 字节的文本文件中读取一些数据,以便绘制折线图。我尝试读取每 2 个字节并将它们组合成 2 个字节,然后我制作了 8 个数组,每个数组有 6000 个整数。但是我遇到了上述错误!如果我尝试只使用 1,2 或 3 个数组,它可以工作,但 4 个数组不能

有人可以帮我看看我在哪里做错了。我从昨天阅读了不同的讨论,并没有真正看到任何合适的答案。我得到的是内存/堆的问题。

这是我的代码。

byte LSB;
     byte MSB;
    public  Intent getIntent(Context context) throws IOException{
        InputStream data_in ;

            data_in = context.getAssets().open("demodta.txt");

             int[] x = new int[6000]; // x values
             int[] y1= new int[6000]; // y1 values
             int[] y2= new int[6000]; // y2 values
             int[] y3= new int[6000]; // y3 values
             int[] y4= new int[6000]; // y4 values
             int[] y5= new int[6000]; // y5 values
             int[] y6= new int[6000]; // y6 values
             int[] y7= new int[6000]; // y7 values
             int[] y8= new int[6000]; // y8 values  
             int i =0;


//      while(true) {
    int j=0;
         try {

         int size = data_in.available();
         byte[] buffer = new byte[size];
         data_in.read(buffer);

             for( i=0;i<12000;i=i+2){                
                 LSB =  buffer[i];
                 MSB = buffer[i+1];
                  int current= ((MSB<<8)| (LSB & 0xFF));
                y1[j]=  current;
                j++;
              }
                j=0;
             for(i=12000;i<24000;i=i+2){
                LSB =  buffer[i];
                MSB = buffer[i+1];
                int current= ((MSB<<8)| (LSB & 0xFF));
                y2[j]=  current;
                j++;
              }
             j=0;
             for(i=24000;i<36000;i=i+2){
                LSB =  buffer[i];
                 MSB = buffer[i+1];
                 int current= ((MSB<<8)| (LSB & 0xFF));
                 y3[j]=  current;
                 j++;
               }
             j=0;
             for(i=36000;i<48000;i=i+2){
                LSB =  buffer[i];
                 MSB = buffer[i+1];
                 int current= ((MSB<<8)| (LSB & 0xFF));
                 y4[j]=  current;
                 j++;
               }
             j=0;
             for(i=48000;i<60000;i=i+2){
                LSB =  buffer[i];
                 MSB = buffer[i+1];
                 int current= ((MSB<<8)| (LSB & 0xFF));
                 y5[j]=  current;
                 j++;
               }
             j=0;
             for(i=60000;i<72000;i=i+2){
                LSB =  buffer[i];
                 MSB = buffer[i+1];
                 int current= ((MSB<<8)| (LSB & 0xFF));
                 y6[j]=  current;
                 j++;
               }
             j=0;
             for(i=72000;i<84000;i=i+2){
                LSB =  buffer[i];
                 MSB = buffer[i+1];
                 int current= ((MSB<<8)| (LSB & 0xFF));
                 y7[j]=  current;
                 j++;
               }
             j=0;
             for(i=84000;i<96000;i=i+2){
                LSB =  buffer[i];
                 MSB = buffer[i+1];
                 int current= ((MSB<<8)| (LSB & 0xFF));
                 y8[j]=  current;
                 j++;
               }
         }

 for(int k=0;k<6000;k++){
     x[k]=k;
    }

        TimeSeries series1 = new TimeSeries("line1");
        for(int k=0;k<x.length;k++){
            series1.add(x[k], y1[k]);
        }
        TimeSeries series2 = new TimeSeries("line2");
        for(int k=0;k<x.length;k++){
            series2.add(x[k], y2[k]);
        }
        TimeSeries series3 = new TimeSeries("line3");
        for(int k=0;k<x.length;k++){
            series3.add(x[k], y3[k]);
        }
        TimeSeries series4 = new TimeSeries("line4");
        for(int k=0;k<x.length;k++){
            series4.add(x[k], y4[k]);
        }
        TimeSeries series5 = new TimeSeries("line5");
        for(int k=0;k<x.length;k++){
            series5.add(x[k], y5[k]);
        }
        TimeSeries series6 = new TimeSeries("line6");
        for(int k=0;k<x.length;k++){
            series6.add(x[k], y6[k]);
        }
        TimeSeries series7 = new TimeSeries("line7");
        for(int k=0;k<x.length;k++){
            series7.add(x[k], y7[k]);
        }
        TimeSeries series8 = new TimeSeries("line8");
        for(int k=0;k<x.length;k++){
            series8.add(x[k], y8[k]);
        }

这是我的 MainActivity

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button strt = (Button) findViewById(R.id.LineGraph);

        strt.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                lineGraph line = new lineGraph();

                Intent lineIntent = null;
                try {
                    lineIntent = line.getIntent(getBaseContext());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


                startActivity(lineIntent);

            }
        });
    }

我的 LogCat 给出以下输出:

05-27 19:39:00.180: D/dalvikvm(5556): GC_FOR_ALLOC freed 0K, 10% free 14410K/15879K, paused 68ms
05-27 19:39:00.750: D/dalvikvm(5556): GC_FOR_ALLOC freed 961K, 16% free 13452K/15879K, paused 72ms
05-27 19:39:00.830: D/dalvikvm(5556): GC_FOR_ALLOC freed 0K, 10% free 14348K/15879K, paused 77ms
05-27 19:39:00.830: I/dalvikvm-heap(5556): Grow heap (frag case) to 14.945MB for 917520-byte allocation
05-27 19:39:00.920: D/dalvikvm(5556): GC_FOR_ALLOC freed 0K, 10% free 15244K/16839K, paused 78ms
05-27 19:39:01.320: D/dalvikvm(5556): GC_FOR_ALLOC freed 1206K, 15% free 14407K/16839K, paused 74ms
05-27 19:39:01.320: I/dalvikvm-heap(5556): Grow heap (frag case) to 15.643MB for 1589467-byte allocation
05-27 19:39:01.410: D/dalvikvm(5556): GC_FOR_ALLOC freed <1K, 14% free 15958K/18439K, paused 73ms
05-27 19:39:01.420: E/JavaBinder(5556): !!! FAILED BINDER TRANSACTION !!!
4

1 回答 1

0

不能这样吗。。

 for( i=0;i<12000;i=i+2){ y1[j]= current; j++; }
 TimeSeries series1 = new TimeSeries("line1"); 
for(int k=0;k<x.length;k++){ series1.add(x[k], y1[k]); } 
 for(i=12000;i<24000;i=i+2){ y1[j]= current; j++; } 
于 2012-05-29T15:31:00.277 回答