私はAndroidが初めてで、Androidタブまたは電話でECG WAVESをプロットする必要があり、achartengineライブラリを使用してlineGrapでデータを取得しようとしましたが、NullPointerExceptionを取得しています。助けてください!!!
これが私のGraphActivity.javaです
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class GraphActivity extends Activity {
/** Called when the activity is first created. */
@Override
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 = line.getIntent(getApplicationContext());
startActivity(lineIntent);
}
});
}
ここに私のlineGraph.Javaがあります
public class lineGraph {
static BufferedReader reader ;
static DataInputStream data_in;
static int[] x = new int[6000]; // x values
static int[] y1= new int[6000]; // y1 values
static int[] y2= new int[6000]; // y2 values
static int[] y3= new int[6000]; // y3 values
static int[] y4= new int[6000]; // y4 values
static int[] y5= new int[6000]; // y5 values
static int[] y6= new int[6000]; // y6 values
static int[] y7= new int[6000]; // y7 values
static int[] y8= new int[6000]; // y8 values
static int ch =0;
public Intent getIntent(Context context){
try {
data_in = new DataInputStream(
new BufferedInputStream(
new FileInputStream(new File("src/data.txt"))));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
while(ch<6000){
Byte LSB = data_in.readByte();
Byte MSB = data_in.readByte();
int current= ((MSB<<8)| (LSB & 0xFF));
y1[ch]= current;
ch++;
}
while(ch>=6000 && ch<12000){
Byte LSB = data_in.readByte();
Byte MSB = data_in.readByte();
int current= ((MSB<<8)| (LSB & 0xFF));
y2[ch-6000]= current;
ch++;
}
}
catch(EOFException eof) {
System.out.println ("End of File read");
// break;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
data_in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// }
for(int i=0;i<6000;i++){
x[i]=i;
}
TimeSeries series1 = new TimeSeries("line1");
for(int i=0;i<x.length;i++){
series1.add(x[i], y1[i]);
}
TimeSeries series2 = new TimeSeries("line2");
for(int i=0;i<x.length;i++){
series1.add(x[i], y2[i]);
}
TimeSeries series3 = new TimeSeries("line3");
for(int i=0;i<x.length;i++){
series1.add(x[i], y3[i]);
}
TimeSeries series4 = new TimeSeries("line4");
for(int i=0;i<x.length;i++){
series1.add(x[i], y4[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series1);
dataset.addSeries(series2);
dataset.addSeries(series3);
dataset.addSeries(series4);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer= new XYSeriesRenderer();
renderer.setColor(Color.GREEN);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
mRenderer.addSeriesRenderer(renderer);
Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph");
return intent;
}
}
これが私のAndroidマニフェストです
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.praktikum.graph"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".GraphActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="org.achartengine.GraphicalActivity"/>
</application>
</manifest>
そして私のLogCat
05-24 13:03:41.309: E/AndroidRuntime(21551): FATAL EXCEPTION: main
05-24 13:03:41.309: E/AndroidRuntime(21551): java.lang.NullPointerException
05-24 13:03:41.309: E/AndroidRuntime(21551): at com.praktikum.graph.lineGraph.getIntent(lineGraph.java:58)
05-24 13:03:41.309: E/AndroidRuntime(21551): at com.praktikum.graph.GraphActivity$1.onClick(GraphActivity.java:22)
05-24 13:03:41.309: E/AndroidRuntime(21551): at android.view.View.performClick(View.java:3127)
05-24 13:03:41.309: E/AndroidRuntime(21551): at android.view.View$PerformClick.run(View.java:12025)
05-24 13:03:41.309: E/AndroidRuntime(21551): at android.os.Handler.handleCallback(Handler.java:587)
05-24 13:03:41.309: E/AndroidRuntime(21551): at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 13:03:41.309: E/AndroidRuntime(21551): at android.os.Looper.loop(Looper.java:132)
05-24 13:03:41.309: E/AndroidRuntime(21551): at android.app.ActivityThread.main(ActivityThread.java:4126)
05-24 13:03:41.309: E/AndroidRuntime(21551): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 13:03:41.309: E/AndroidRuntime(21551): at java.lang.reflect.Method.invoke(Method.java:491)
05-24 13:03:41.309: E/AndroidRuntime(21551): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
05-24 13:03:41.309: E/AndroidRuntime(21551): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
05-24 13:03:41.309: E/AndroidRuntime(21551): at dalvik.system.NativeStart.main(Native Method)
05-24 13:03:43.319: I/dalvikvm(21551): threadid=4: reacting to signal 3
05-24 13:03:43.319: I/dalvikvm(21551): Wrote stack traces to '/data/anr/traces.txt'
よろしくお願いいたします。