InflateException我有一个错误的膨胀类

时间:2014-10-21 11:02:38

标签: android xml view inflate inflate-exception

我有更多的活动,我没有任何问题,但是当我开始这项活动(Segunda)时,它会打破 在本活动中,我尝试使用customView进行缩放和绘制,我无法找到问题所在

这是活动

public class Segunda extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_segunda);
        //setContentView(new Panel(this));
        setContentView(R.layout.activity_segunda);      
    }
}

这是xml布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.andres.sun4all.Panel 
    android:id="@+id/Panelillo"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<LinearLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal"
 android:layout_weight = "2">

</LinearLayout>

logcat的:

10-21 12:43:58.191: E/AndroidRuntime(27794): FATAL EXCEPTION: main
10-21 12:43:58.191: E/AndroidRuntime(27794): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andres.sun4all/com.andres.sun4all.Segunda}: android.view.InflateException: Binary XML file line #7: Error inflating class com.andres.sun4all.Panel
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.os.Looper.loop(Looper.java:137)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.ActivityThread.main(ActivityThread.java:4898)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at java.lang.reflect.Method.invokeNative(Native Method)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at java.lang.reflect.Method.invoke(Method.java:511)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at dalvik.system.NativeStart.main(Native Method)
10-21 12:43:58.191: E/AndroidRuntime(27794): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.andres.sun4all.Panel
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.view.LayoutInflater.createView(LayoutInflater.java:596)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.Activity.setContentView(Activity.java:1924)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at com.andres.sun4all.Segunda.onCreate(Segunda.java:13)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.Activity.performCreate(Activity.java:5206)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
10-21 12:43:58.191: E/AndroidRuntime(27794):    ... 11 more
10-21 12:43:58.191: E/AndroidRuntime(27794): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
10-21 12:43:58.191: E/AndroidRuntime(27794):    at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at java.lang.Class.getConstructor(Class.java:431)
10-21 12:43:58.191: E/AndroidRuntime(27794):    at android.view.LayoutInflater.createView(LayoutInflater.java:561)
10-21 12:43:58.191: E/AndroidRuntime(27794):    ... 22 more

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]

这意味着您的自定义视图Panel缺少具有上下文和属性集的构造函数:

  public void Panel(Context context, AttributeSet att) {
       super(context,att)    
  }
自定义视图从xml

中膨胀时使用的