0
在我ScreenFragment
类:为什么我尝试创建一个返回null的图表?
Activity parentActivity;
public LineChart chart; // changing private to public didn't help
在其onCreate()
:
parentActivity = getActivity();
在其onCreateView()
:
chart = (LineChart) parentActivity.findViewById(R.id.chart_id);
这是返回null
。 ID在分段的XML中定义:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/fab_margin"
tools:context="io.aeroscope.aeroscope.ScreenFragment">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart_id"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
为什么null?为什么没有实例化图表?
什么是你的线型图类的代码?你有一个默认的无参数构造函数吗? – pat
LineChart类是MPAndroidChart包的一部分。这是我第一次尝试使用它。 –
第一次尝试的一切看起来都很棒,除了沿着图表底部的网格线未被绘制。任何想法为什么? –