扩充二进制XML文件时出错

时间:2015-08-09 13:46:01

标签: java android

我试图在xml中对自定义类(scrollView)进行充气然后此错误显示有人可以解释我的代码会发生什么吗?

我尝试在特定的滚动点禁用滚动,然后再次启用它。

  partnerScrollView = (LockableScrollView) findViewById(R.id.partnerScrollView);


  <com.mibag.utils.LockableScrollView
        android:id="@+id/partnerScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >

    </com.mibag.utils.LockableScrollView>



 08-09 15:38:03.270: E/AndroidRuntime(22013): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mibag/com.mibag.PartnerListDetail_Activity}: android.view.InflateException: Binary XML file line #9: Error inflating class com.mibag.utils.LockableScrollView
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.ActivityThread.access$800(ActivityThread.java:149)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.os.Handler.dispatchMessage(Handler.java:102)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.os.Looper.loop(Looper.java:211)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.ActivityThread.main(ActivityThread.java:5317)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at java.lang.reflect.Method.invoke(Native Method)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at java.lang.reflect.Method.invoke(Method.java:372)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
    08-09 15:38:03.270: E/AndroidRuntime(22013): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.mibag.utils.LockableScrollView
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.view.LayoutInflater.createView(LayoutInflater.java:616)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:381)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.Activity.setContentView(Activity.java:2144)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at com.mibag.PartnerListDetail_Activity.onCreate(PartnerListDetail_Activity.java:201)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.Activity.performCreate(Activity.java:5933)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    ... 10 more
    08-09 15:38:03.270: E/AndroidRuntime(22013): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at java.lang.Class.getConstructor(Class.java:531)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at java.lang.Class.getConstructor(Class.java:495)
    08-09 15:38:03.270: E/AndroidRuntime(22013):    at android.view.LayoutInflater.createView(LayoutInflater.java:580)

1 个答案:

答案 0 :(得分:0)

我确实解决了这个问题:  08-09 15:38:03.270:E / AndroidRuntime(22013):引起:java.lang.NoSuchMethodException:[class android.content.Context,interface android.util.AttributeSet] 我必须在自定义类中添加此构造函数。

public LockableScrollView(Context context, AttributeSet attrs,
        int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    // TODO Auto-generated constructor stub
}