좋은 하루! Android에서 차트를 그리기 위해 ChartEngine을 구현 중이며 문제가 발생했습니다. 생성 된 차트 뷰를 addView 메소드로 레이아웃에 추가하려고하면 NullPointerException이 발생합니다.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();
}
}
어떤 아이디어인가,이 오류의 이유가 될 수 있는지?
해야 하는가? – Noel
아래 코드를 사용하여 chart_price가 null이 아님을 표시했습니다. 내 추측, 오류 addView 메서드 또는 chart_layout.xml 설정이 발생합니다. ::::::::::::::::::: System.out.println ("ADDVIEW 이전"); \t \t System.out.println (chart_price == null); \t \t layout.addView (chart_price); – dimzul