0

私はこの問題を何時間も解決しようとしてきましたが、明白な解決策をすべて使い果たしました。findViewById を使用して取得しようとしない限り、正常に機能するカスタム トグル ボタンがあります。

関連するコードは次のとおりです。

public class WeekButton extends ToggleButton {

    private static int mWidth;

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

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

これがレイアウトです..

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:gravity="center"
    android:orientation="horizontal"
    android:padding="5dp">

    <org.myname.projetname.reminders.WeekButton.WeekButton
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mondayToggleButton"
        style="@style/RecurrenceDayOfWeekStyle"
        android:textOff="  Mon"
        android:textOn="  Mon" />
</LinearLayout>

ここで例外が発生します..

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_reminder_activity);
        //This causes null pointer
        WeekButton weekButton = (WeekButton)findViewById(R.id.mondayToggleButton));
}

ご協力いただきありがとうございます。

解決策: WeekButtons を追加していたリストをインスタンス化するのを忘れていたため、find id の呼び出しが機能しているように見えましたが、機能していました。あなたが助けようとしたすべての人に感謝します。

4

2 に答える 2

0

週ボタンを追加するリストをインスタンス化するのを忘れていました。

于 2013-09-20T00:29:02.917 に答える