Android 自定义SeekBar中的NoSuchMethodException

Android 自定义SeekBar中的NoSuchMethodException,android,android-logcat,Android,Android Logcat,我创建了SeekBar类的扩展: package com.simplemathgame; import android.content.Context; import android.widget.SeekBar; import android.widget.TextView; public class SeekBarPlus extends SeekBar { private TextView numberOfDrills; public SeekBarPlus(Cont

我创建了SeekBar类的扩展:

package com.simplemathgame;

import android.content.Context;
import android.widget.SeekBar;
import android.widget.TextView;

public class SeekBarPlus extends SeekBar {
    private TextView numberOfDrills;

    public SeekBarPlus(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    }

    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
        // TODO Auto-generated method stub
        numberOfDrills.setText(progress); 
    }

    public void setTextView(TextView textView){
        numberOfDrills = textView;
    }

}
下面是xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    android:background="#000044">
    <TableRow 
        android:layout_marginTop="10dp"
        android:gravity="center_vertical" >
        <TextView 
            android:textColor="#FFFFFFFF"
            android:textSize="16sp"
            android:textStyle="bold"
            android:text="Addition Drills:"/>
    </TableRow>
    <TableRow
        android:layout_marginTop="5dp"
         android:gravity="center_vertical" >

        <com.simplemathgame.SeekBarPlus
            android:id="@+id/add_seek_bar"
            android:layout_width="20dp"
            android:max="10" 
            android:layout_weight="0.8"/>
        <TextView 
            android:id="@+id/add_drills_number" 
            android:textColor="#FFFFFFFF"
            android:textSize="16sp"
            android:textStyle="bold"
            android:layout_weight="0.2"
            android:gravity="center_horizontal"
            android:text="0"/>
    </TableRow>
</TableLayout>

我看到扩展的SeekBarPlus类有问题,但不知道为什么。谢谢

您尚未在自定义视图类中指定完整的构造函数集。在您的特定情况下,
SeekBarPlus(Context,AttributeSet)
构造函数缺失

自定义视图类需要有以下3个构造函数:

public SeekBarPlus(Context context) {
    super(context);
}

public SeekBarPlus(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public SeekBarPlus(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

如果您不需要它们,只需调用
super()
,如上所示。

您还没有在自定义视图类中指定完整的构造函数集。在您的特定情况下,
SeekBarPlus(Context,AttributeSet)
构造函数缺失

自定义视图类需要有以下3个构造函数:

public SeekBarPlus(Context context) {
    super(context);
}

public SeekBarPlus(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public SeekBarPlus(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

如果您不需要它们,只需调用
super()
,如上所示。

您没有实现View提供的另外两个CUNstructor:

// Constructor that is called when inflating a view from XML.
View(Context context, AttributeSet attrs)

// Perform inflation from XML and apply a class-specific base style.
View(Context context, AttributeSet attrs, int defStyle)

您没有实现View提供的另外两个CUNstructor:

// Constructor that is called when inflating a view from XML.
View(Context context, AttributeSet attrs)

// Perform inflation from XML and apply a class-specific base style.
View(Context context, AttributeSet attrs, int defStyle)