2013-02-28 114 views
0

捕所以我有一個按鈕上按運行的方法,一切都來了完善的,除非我有一點內部的if/else if/else語句循環。我確信這是我失蹤的愚蠢,但我似乎無法看到它。的if/else裏面沒有方法按下按鈕

在下面的代碼我找到了尋找hourtype但即使我直接將其設置爲假的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; 
} 

回答

2

也許hourType = falsehourType == false,或者甚至更好!hourType

+0

謝謝你了。這是問題所在。我現在覺得自己像個白癡。 *微笑* – fauxfire76 2013-02-28 14:32:10

4

澄清:=用於指定用途例如int x = 10;,而==用於比較,例如, boolean isX10 = x==10;

if說法是錯誤的做到這一點:

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

OR

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. 
+0

正確。 '='表示分配,'=='進行比較。你應該在OP的答案中加入這個。 – Rawkode 2013-02-28 14:14:20

+1

當然,我也要加上:) – 2013-02-28 14:17:19

+0

嘎!看到?我告訴過你這很愚蠢。 > _ <謝謝! – fauxfire76 2013-02-28 14:25:10

0

if和else if都被檢查錯了相同的條件下信達X應該是這樣的

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; 
        }