2014-02-18 4 views
0

은 내가 내 xml 파일에서 클래스를 부풀려 수없는이 오류를 수정하는 방법을 알아낼 수 없습니다 여기 http://androidplot.com/docs/quickstart/Androidplot 오류 팽창 클래스

androidplot이 튜토리얼을 따라하기 위해 노력하고있어. 프로그래밍 안드로이드 앱에 익숙하지 않으므로 명백한 오류 일 수 있습니다.

오류

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> 

답변

1

정말 XML이 그렇게 되야 만할까요? 다음을 시도하십시오 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <com.androidplot.xy.XYPlot 
     android:id="@+id/mySimpleXYPlot" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 

</LinearLayout> 
+0

을에서 그의 xml은 괜찮아 보이는 문서 : http://developer.android.com/guide/components/fragments.html, 본 적이 없지만 – pedromss

+0

@pedromss 여기에서 http://androidplot.com/docs/quickstart/ – nikis

2

android.app.Fragment $있는 InstantiationException을 : 인스턴스화 할 수 없습니다 조각 com.androidplot.xy.XYPlot을 : 확인 클래스 이름이 존재하게하는 것은, 공개하고, 빈 생성자가

그것은 조각을 기대하고 있지만 XYPlot이보기입니다

(그룹) sublcass

그래서 당신은

에서 변경해야
<View android:name="com.androidplot.xy.XYPlot" 
     android:id="@+id/mySimpleXYPlot" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 
0

다른 프로젝트의 코드를 붙여 넣는 것만을 공유하지 않으셨습니까? com.androidplot.xy라는 이름의 src 폴더와 내부에 사용자 정의 된 조각 XYPlot이라는 패키지가 있어야합니다.

0

는 그냥 libs와 폴더에 (이 이제까지 버전)을 androidplot 코어-0.6.1.jar를 복사

이 같은 활동의 XML에 타이틀을 추가해야
0

:

<com.androidplot.xy.XYPlot 
     android:id="@+id/plot" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     title="write a title"/> 
+1

오신 것을 환영합니다. 어쩌면 이것이 문제를 해결할 수있는 이유에 대한 문장을 추가 할 수도 있습니다. – Andrew

관련 문제