我正在尝试使用名为weight_log的csv文件中的数据绘制图形。我正在使用achartengine库来绘制图形。我已经在主要活动中创建了一个onclick按钮。当我运行该应用程序时,它崩溃了,我不知道该怎么做,因为它既不显示公会构建失败也不显示任何特定的错误。
import android.os.Bundle;
import android.util.Log;
import android.widget.RelativeLayout;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Chart extends MainActivity {
ArrayList<Integer> weightList = new ArrayList<Integer>();
private GraphicalView mChart;
private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
private XYSeriesRenderer renderer = new XYSeriesRenderer();
private XYSeries mCurrentSeries;
private XYSeriesRenderer mCurrentRenderer;
InputStream inputStream;
String[] data;
@Override
protected void onCreate(Bundle savedInstances) {
super.onCreate(savedInstances);
setContentView(R.layout.chart);
readWeightLog();
String data = "";
final StringBuffer sbuffer = new StringBuffer();
InputStream is = this.getResources().openRawResource(R.raw.weight_log);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is != null) {
try {
while ((data = reader.readLine()) != null) {
sbuffer.append((data + "\n" + "\t"));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void initChart() {
mCurrentSeries = new XYSeries("Weight Log");
mDataset.addSeries(mCurrentSeries);
mCurrentRenderer = new XYSeriesRenderer();
mRenderer.addSeriesRenderer(mCurrentRenderer);
mRenderer.setXTitle("Time(s)");
mRenderer.setYTitle("Power(Kw/hr)");
}
private void addWeightData() {
Integer x = 10;
for (Integer weight : weightList) {
mCurrentSeries.add(x += 10, weight);
}
}
@Override
protected void onResume() {
super.onResume();
RelativeLayout layout = (RelativeLayout) findViewById(R.id.chart);
if (mChart == null) {
initChart();
addWeightData();
mChart = ChartFactory.getCubeLineChartView(this, mDataset, mRenderer, 0.3f);
layout.addView(mChart);
} else {
}
}
public void readWeightLog() {
String FILENAME = "weight_log.csv";
FileInputStream inputStream = null;
String temp;
String a[];
try {
inputStream = openFileInput(FILENAME);
byte[] reader = new byte[inputStream.available()];
while (inputStream.read(reader) != -1) {
}
Scanner s = new Scanner(new String(reader));
s.useDelimiter("\\n");
while (s.hasNext()) {
temp = s.next();
a = temp.split(",");
weightList.add(Integer.parseInt(a[2]));
}
s.close();
} catch (Exception e) {
Log.e("Chart", e.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e) {
Log.e("Chart", e.getMessage());
}
}
}
}
}
Logcat
07-18 19:59:37.736 7482-7482/? E/libprocessgroup: failed to make and
chown /acct/uid_10060: Read-only file system
07-18 19:59:38.348 7482-7482/com.example.muzeefa.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.muzeefa.myapplication, PID: 7482
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.muzeefa.myapplication/com.example.muzeefa.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class org.achartengine.GraphicalView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class org.achartengine.GraphicalView
at android.view.LayoutInflater.createView(LayoutInflater.java:616)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.muzeefa.myapplication.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getConstructor(Class.java:495)
at android.view.LayoutInflater.createView(LayoutInflater.java:580)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.muzeefa.myapplication.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)