我正在开发一个Android项目,尝试实现来自https://github.com/PhilJay/MPAndroidChart的MPAndroidChart库。我想在片段中实现它,但一直出错,我不知道为什么。
以下是我的活动。
以下是我的活动布局。
以下是我的Fragment类
以下是该片段的布局
以下是我的活动。
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment chartFragment = new ChartFragment();
transaction.replace(R.id.fragmentContainer, chartFragment);
transaction.commit();
}
}
以下是我的活动布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<FrameLayout android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
以下是我的Fragment类
public class ChartFragment extends Fragment
{
private LineChart mChart;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.graph, container, false);
return v;
}
}
以下是该片段的布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/lineChart1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
目前当我尝试在OnCreateView函数中填充视图时,应用程序会崩溃。
我收到的错误是:
java.lang.RuntimeException: 无法启动 activity ComponentInfo{com.MyCompany.ChartTest/com.MyCompany.ChartTest.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class com.github.mikephil.charting.charts.LineChart