I am working on an Android project and am trying to implement a library called MPAndroidChart at https://github.com/PhilJay/MPAndroidChart .
I try to implement it in a fragment, but I get an error message and cannot understand why.
Below is my activity.
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(); } }
Below is a layout of my activity
<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>
Below is my class 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; } }
And below is the layout for the fragment
<?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>
Currently crashing while trying to increase the view in my OnCreateView function.
I get an error:
java.lang.RuntimeException: Unable to trigger ComponentInfo action {com.MyCompany.ChartTest / com.MyCompany.ChartTest.MainActivity}: android.view.InflateException: line of binary XML file # 5: inflation of class com.github.mikephil.charting inflated. charts.LineChart
source share