0

したがって、ボタンを押すと実行されるメソッドがあり、内部の if/else if/else ループが少しある場合を除いて、すべてが完璧になります。私が行方不明になっているのはばかげていると確信していますが、それを見ることができないようです。

以下のコードでは、hourtype を見つけていますが、直接 false に設定しても、if/else はトリガーされません。時間の int を問題なく取得できますが、本来のように 12 を減算することはできません。

ここで日付タイプを指定していないことはわかっています。以前に指定したからです。それはここでは問題ではありません。私が言ったように、私はそれをあまりにも長い間見つめていたので、私が見逃している愚かなものだと確信しています. メソッドは次のとおりです。

public String enterMood(View v) {
    try {
        int month = dPick.getMonth();
        int day = dPick.getDayOfMonth();
        int year = dPick.getYear();
        int minute = tPick.getCurrentMinute();
        String moodAntePost = "AM";
        hourType = tPick.is24HourView();
        moodHour = tPick.getCurrentHour();
        if (hourType = false) { // Not hitting this point for some reason I
                                // can't fathom.
            if (moodHour > 12) {
                moodHour = (moodHour - 12);
                moodAntePost = "PM";
            }
        } else if (hourType = false) {
            if (moodHour <= 0) {
                moodHour = 12;
            }
        } else {
        }
        String noteText = noteField.getText().toString();
        Mood = "Happiness," + happyValue + ",Energy," + energyValue
                + ",Anxiety," + anxietyValue + ",Pain," + painValue
                + ",Date," + month + "/" + day + "/" + year + ",Time,"
                + moodHour + ":" + minute + "," + moodAntePost + ",Note,"
                + noteText;
        System.out.println(Mood); //Just to print to the LogCat
    } catch (Exception buttonListenerException) {
        Log.e(TAG, "Exception received", buttonListenerException);
    }
    return Mood;
}
4

3 に答える 3

4

明確化:=目的を割り当てるためにint x = 10;使用されます==が、比較のために使用されます。boolean isX10 = x==10;

あなたのif発言は間違っています:

 if (hourType == false) { // Not hitting this point for some reason I
                            // can't fathom.

また

 if (!hourType) { // Not hitting this point for some reason I
                            // can't fathom.

それ以外の

 if (hourType = false) { // Not hitting this point for some reason I
                            // can't fathom.
于 2013-02-28T14:08:18.147 に答える
2

多分hourType = falseそうあるべきhourType == falseか、さらに良い!hourType

于 2013-02-28T14:08:08.393 に答える
0

if と else の両方が間違った構文で同じ条件をチェックしている場合、次のようになります

 if (hourType == false) { // Not hitting this point for some reason I
                                    // can't fathom.
                if (moodHour > 12) {
                    moodHour = (moodHour - 12);
                    moodAntePost = "PM";
                }
            } else if (hourType == true) {
                if (moodHour <= 0) {
                    moodHour = 12;
                }

また

 if (!hourType) { // Not hitting this point for some reason I
                                        // can't fathom.
                    if (moodHour > 12) {
                        moodHour = (moodHour - 12);
                        moodAntePost = "PM";
                    }
                } else if (hourType) {
                    if (moodHour <= 0) {
                        moodHour = 12;
                    }
于 2013-02-28T14:11:52.303 に答える