0

良い一日!Androidでグラフを描画するためにaChartEngineを実装していますが、問題が発生しました。addViewメソッドを使用して作成したグラフビューをレイアウトに追加しようとするとNullPointerExceptionが発生します。

chart_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/charts_relative_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout
        android:name="@+id/price_chart"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
// other elements
</RelativeLayout>

Charts.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chart_layout);
     //other code
}


protected void onResume() {
    super.onResume();

    if (chart_price == null) { 
    LinearLayout layout = (LinearLayout) findViewById(R.id.price_chart);
    chart_price = ChartFactory.getLineChartView(this, buildDataset(getTitles(), dateArray, priceArray), getRenderrer(paramList.get(0).length, paramList.get(1).length, maxPrice));          
    layout.addView(chart_price);    // THIS LINE CAUSES NULLPOINTEREXCEPTION
    }
    else {
      chart_price.repaint();
    }
 }

何かアイデアはありますか、このエラーの理由は何ですか?

4

2 に答える 2

3

問題はxmlファイルにあります。

    android:name="@+id/price_chart"

する必要があります

    android:id="@+id/price_chart"
于 2011-06-12T05:56:23.660 に答える
0

XML ファイルに変更を加えてから、保存して再度実行します。今夜の初めに同様の問題が発生したときに、私のために働きました。

于 2011-06-12T02:44:15.090 に答える