2012-06-06 4 views
-1

나는 매우 새로운 Android 버전 &을 사용하고 있으며, 스스로 작성한 Android 앱을 배우려고합니다. CSV 파일에서 값을 읽고 그 값을 계획하려고 할 때 문제가 발생했습니다. 좀 더 구체적으로, 나는 Androidplot 예제를 수정하려고했습니다.csv 파일을 android에서 배열로 변환 할 수 없습니다.

원래 Androidplot 예제가 작동하지만 수정 된 코드는 작동하지 않습니다 ... 문제를 찾으려고했으나 실패했습니다. 실패했습니다 ... 코드를 디버그하려고 할 때마다 ActivityThread.java가 튀어 나오고

catch (Exception e) { 
     if (!mInstrumentation.onException(activity, e)) { 
      throw new RuntimeException(
       "Unable to start activity " + component 
       + ": " + e.toString(), e); 
     } 
    } 

이 사람이 문제가 정말 무엇인지 말해 줄 수 : 다음 코드에 약간 가리키는 화살표가있다? 어떤 도움이 많이

다음

내 수정 된 코드입니다) = 이해 될 것이다 :

package edu.ius.rwisman.AndroidPlotExample; 

import android.app.Activity; 

import android.graphics.Color; 
import android.os.Bundle; 
import com.androidplot.xy.SimpleXYSeries; 
import com.androidplot.series.XYSeries; 
import com.androidplot.xy.*; 
import java.io.BufferedReader; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileReader; 
import java.io.IOException; 
import java.text.DecimalFormat; 
import java.util.Arrays; 


public class AndroidPlotExampleActivity extends Activity 
{ 

private XYPlot mySimpleXYPlot; 

@SuppressWarnings("null") 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // Initialize our XYPlot reference: 
    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); 
    Number[] series1Numbers = null; 
    Number[] series2Numbers = null; 
    int row = 0; 
    // Create two arrays of y-values to plot: 
    try { 

     File file = new File("/home/hanrui/workspace/table.csv"); 
     BufferedReader reader = new BufferedReader(new FileReader(file)); 
     reader.readLine(); 
     String line = null; 
     while((line=reader.readLine())!=null&&row<24){ 
      String item[] = line.split(","); 

      String last = item[item.length-1]; 
      int value = Integer.parseInt(last); 
      series1Numbers[row] = value; 
      series2Numbers[row] = value; 
      row++; 
     } 
    } catch (FileNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 



    // Turn the above arrays into XYSeries: 
    XYSeries series1 = new SimpleXYSeries(
      Arrays.asList(series1Numbers),   // SimpleXYSeries takes a List so turn our array into a List 
      SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value 
      "Series1");        // Set the display title of the series 

    // Same as above, for series2 
    XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, 
      "Series2"); 

    // Create a formatter to use for drawing a series using LineAndPointRenderer: 
    LineAndPointFormatter series1Format = new LineAndPointFormatter(
      Color.rgb(0, 200, 0),     // line color 
      Color.rgb(0, 100, 0),     // point color 
      Color.rgb(150, 190, 150));    // fill color (optional) 

    // Add series1 to the xyplot: 
    mySimpleXYPlot.addSeries(series1, series1Format); 

    // Same as above, with series2: 
    mySimpleXYPlot.addSeries(series2, new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), 
      Color.rgb(150, 150, 190))); 


    // Reduce the number of range labels 
    mySimpleXYPlot.setTicksPerRangeLabel(3); 

    // By default, AndroidPlot displays developer guides to aid in laying out your plot. 
    // To get rid of them call disableAllMarkup(): 
    mySimpleXYPlot.disableAllMarkup(); 
} 
} 
+1

당신이 안드로이드 개발을 위해 가지고 있어야하는 유틸리티 중에는 "adb.exe"라는 파일과 심지어 어떤 줄까지 문제의 어떤 종류의 예외를 정확하게 제공 할 로그를 보려면 "adb.exe logcat"을 실행하십시오 입니다! –

+0

일반적으로 디버그 정보 (예 : LogCat의 디버그 정보)에는 예외가 발생한 소스 파일의 행 번호가 들어 있습니다. 그 라인을 알지 못하면 문제를 찾기가 어렵습니다. stacktrace를 찾아 여기에 게시하십시오. –

+0

답장을 보내 주셔서 감사합니다. 아무 것도 없지만 LogCat을 확인했지만 DDMS에보고 된 오류가 있습니다 : - logcat을 시작하는 동안 예기치 않은 오류가 발생했습니다. 장치를 다시 선택하십시오] 장치는 com.android.ddmlib.AdbCommandRejectedException를 찾을 수 없습니다. 장치가 \t com.android.ddmlib.AdbHelper에서 com.android.ddmlib.AdbHelper.setDevice (AdbHelper.java:752)에서 \t를 찾을 수 없음 .executeRemoteCommand (AdbHelper.java:373) com.android.ddmlib.Device.executeShellCommand (Device.java:397)에서 \t com.android.ddmuilib.logcat.LogCatReceiver $ 1.run에서 \t (LogCatReceiver.java:102) \t at java.lang.Thread.run (Thread.java:636) –

답변

0

는 전화 (에뮬레이터 또는 그 자체가 실제 장치에서 실행되는 안드로이드 응용 프로그램) 따라서이 파일의 뜻을 실행 대부분 찾을 수 없습니다 :

File file = new File("/home/hanrui/workspace/table.csv");

당신의 시도 - 캐치 문 후, series1Numbers가 null 동일 있는지 확인합니다.

편집 :

Number[] series1Numbers = null; : 뭔가를 발견

, 당신은 결코 숫자의 배열을 초기화하지 있습니다.

자바가 PHP가 아니기 때문에 PHP에서는 배열이 직접 생성되지만 Java에서는 그렇지 않습니다. series1Numbers = new Number[10];으로 전화해야합니다. 여기서 10은 어레이 크기입니다. ArrayList를 대신 사용하는 것이 좋습니다. 동적 인 크기를 가질 수 있기 때문입니다.

+0

대단히 감사합니다 !!! 이게 문제 야! 답장을 보내 주셔서 감사합니다. =) –

+0

도움을 주시면 투표를하고 응답으로 동의하는 것을 잊지 마십시오. –

+0

수락되었지만 투표에 대한 평판이 충분하지 않았습니다 .. –

관련 문제