我想按照這個教程androidplot這裏http://androidplot.com/docs/quickstart/Androidplot錯誤充氣類
我無法弄清楚如何解決這個錯誤,它無法從我的XML文件充氣類。我是編程android應用程序的新手,所以這可能是一個明顯的錯誤。
錯誤
02-18 05:11:40.187: E/AndroidRuntime(14925): FATAL EXCEPTION: main 02-18 05:11:40.187: E/AndroidRuntime(14925):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.simplexyplotactivity/com.example.simplexyplotactivity.MainActivity}:
android.view.InflateException: Binary XML file line #5: Error
inflating class fragment 02-18 05:11:40.187: E/AndroidRuntime(14925):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2174)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
android.app.ActivityThread.access$700(ActivityThread.java:141) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1267)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
android.os.Handler.dispatchMessage(Handler.java:99) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.os.Looper.loop(Looper.java:137) 02-18 05:11:40.187:
E/AndroidRuntime(14925): at
android.app.ActivityThread.main(ActivityThread.java:5059) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
java.lang.reflect.Method.invokeNative(Native Method) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
java.lang.reflect.Method.invoke(Method.java:511) 02-18 05:11:40.187:
E/AndroidRuntime(14925): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
dalvik.system.NativeStart.main(Native Method) 02-18 05:11:40.187:
E/AndroidRuntime(14925): Caused by: android.view.InflateException:
Binary XML file line #5: Error inflating class fragment 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.view.LayoutInflater.inflate(LayoutInflater.java:489) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.view.LayoutInflater.inflate(LayoutInflater.java:396) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.view.LayoutInflater.inflate(LayoutInflater.java:352) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:260)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
android.app.Activity.setContentView(Activity.java:1893) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
com.example.simplexyplotactivity.MainActivity.onCreate(MainActivity.java:28)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
android.app.Activity.performCreate(Activity.java:5058) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
02-18 05:11:40.187: E/AndroidRuntime(14925): ... 11 more 02-18
05:11:40.187: E/AndroidRuntime(14925): Caused by:
android.app.Fragment$InstantiationException: Unable to instantiate
fragment com.androidplot.xy.XYPlot: make sure class name exists, is
public, and has an empty constructor that is public 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.app.Fragment.instantiate(Fragment.java:584) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.app.Fragment.instantiate(Fragment.java:552) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.app.Activity.onCreateView(Activity.java:4706) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
02-18 05:11:40.187: E/AndroidRuntime(14925): ... 21 more 02-18
05:11:40.187: E/AndroidRuntime(14925): Caused by:
java.lang.ClassNotFoundException: Didn't find class
"com.androidplot.xy.XYPlot" on path:
/data/app/com.example.simplexyplotactivity-1.apk 02-18 05:11:40.187:
E/AndroidRuntime(14925): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
02-18 05:11:40.187: E/AndroidRuntime(14925): at
java.lang.ClassLoader.loadClass(ClassLoader.java:501) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
java.lang.ClassLoader.loadClass(ClassLoader.java:461) 02-18
05:11:40.187: E/AndroidRuntime(14925): at
android.app.Fragment.instantiate(Fragment.java:574) 02-18
05:11:40.187: E/AndroidRuntime(14925): ... 24 more
MainActivity.java
package com.example.simplexyplotactivity;
import java.util.Arrays;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.WindowManager;
import com.androidplot.xy.*;
/**
* A straightforward example of using AndroidPlot to plot some data.
*/
public class MainActivity extends FragmentActivity
{
private XYPlot plot;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// fun little snippet that prevents users from taking screenshots
// on ICS+ devices :-)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.simple_xy_plot_example);
setContentView(R.layout.simple_xy_plot_example);
//initialize out XYPlot reference:
plot = (XYPlot)findViewById(R.id.mySimpleXYPlot);
//create a couple arrays of y-values to plot:
Number[] series1Numbers = {1,8,5,2,7,4};
Number[] series2Numbers = {4,6,3,8,3,10};
//turn the above arrays into XYSeries':
XYSeries series1=new SimpleXYSeries(
Arrays.asList(series1Numbers), //SimpleXYSeries takes a List so turn our array into a List
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, //Y_VALS_ONLY means use the element index as the x value
"Series1"); //Set the display title of the series
//same as above
XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");
//creates a formatter to use for drawing a series using LineAndPointRenderer
//and configure it from xml:
LineAndPointFormatter series1Format = new LineAndPointFormatter();
series1Format.setPointLabelFormatter(new PointLabelFormatter());
series1Format.configure(getApplicationContext(), R.layout.line_point_formatter_with_plf1);
//ass a new series' to the xyplot:
plot.addSeries(series1, series1Format);
//same as above:
LineAndPointFormatter series2Format = new LineAndPointFormatter();
series2Format.setPointLabelFormatter(new PointLabelFormatter());
series2Format.configure(getApplicationContext(), R.layout.line_point_formatter_with_plf2);
plot.addSeries(series2, series2Format);
//reduce the number of range labels
plot.setTicksPerRangeLabel(3);
plot.getGraphWidget().setDomainLabelOrientation(-45);
}
}
simple_xy_plot_example.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.androidplot.xy.XYPlot"
android:id="@+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
從他的xml文檔看起來不錯:http://developer.android.com/guide/components/fragments.html,但你從未見過 – pedromss
@pedromss從這裏http://androidplot.com/docs/quickstart/ – nikis