Calendar.DAY_OF_WEEK 不能正常工作 - ANDROID
Calendar.DAY_OF_WEEK dosn't work fine - ANDROID
我正在开发一个应用程序,它需要获取当前星期几和当前时间以根据日期和日期更改整数。
我做了这个,但我遇到的问题很少:
周二中午结冰。
它给了我这个::
Unexpected constant;
expected one of: Calendar.FRIDAY, Calendar.MONDAY, Calendar.SATURDAY, Calendar.SUNDAY, Calendar.THURSDAY, Calendar.TUESDAY, Calendar.WEDNESDAY less...
This check warns if a switch statement does not explicitly include all the
values declared by the typedef @IntDef declaration.
而且我不知道如何修复它。
这是我的代码:
当我写这篇文章时,除了星期二外它都有效:
int countuser = 0;
int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
int timeOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
switch (day) {
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
break;
}
但我想根据日期对 countuser 进行排序,所以我做了这个,但它冻结了我的应用程序:
switch (day) {
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
}
同样,当我尝试对 "case Calendar.MONDAY":
进行排序时
switch (day) {
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
}
那么我该如何获取当前星期几和时间来更改我的 Integer 的值?我尝试了很多方法,但它要么死机,要么一整天都不起作用...
非常感谢。
编辑:
这是我的进口清单:
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
我没有足够的代表发表评论,但是你可以 post 你的进口吗?并尝试将其放入 try-catch 块中。
编辑:
try-catch 块将 try 到 catch 您的代码可能抛出的异常。
try {
switch (day) {
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
break;
}
} catch(Exception e){
e.printStackTrace();
}
我正在开发一个应用程序,它需要获取当前星期几和当前时间以根据日期和日期更改整数。
我做了这个,但我遇到的问题很少: 周二中午结冰。 它给了我这个::
Unexpected constant;
expected one of: Calendar.FRIDAY, Calendar.MONDAY, Calendar.SATURDAY, Calendar.SUNDAY, Calendar.THURSDAY, Calendar.TUESDAY, Calendar.WEDNESDAY less...
This check warns if a switch statement does not explicitly include all the
values declared by the typedef @IntDef declaration.
而且我不知道如何修复它。
这是我的代码: 当我写这篇文章时,除了星期二外它都有效:
int countuser = 0;
int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
int timeOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
switch (day) {
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
break;
}
但我想根据日期对 countuser 进行排序,所以我做了这个,但它冻结了我的应用程序:
switch (day) {
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
}
同样,当我尝试对 "case Calendar.MONDAY":
进行排序时 switch (day) {
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
}
那么我该如何获取当前星期几和时间来更改我的 Integer 的值?我尝试了很多方法,但它要么死机,要么一整天都不起作用...
非常感谢。
编辑:
这是我的进口清单:
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
我没有足够的代表发表评论,但是你可以 post 你的进口吗?并尝试将其放入 try-catch 块中。
编辑:
try-catch 块将 try 到 catch 您的代码可能抛出的异常。
try {
switch (day) {
case Calendar.FRIDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 0;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 1;
}
break;
case Calendar.MONDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 2;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 3;
}
break;
case Calendar.SATURDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 4;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 5;
}
break;
case Calendar.SUNDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 6;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 7;
}
break;
case Calendar.THURSDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 8;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 9;
}
break;
case Calendar.TUESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 10;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 11;
}
break;
case Calendar.WEDNESDAY:
if (timeOfDay > 22 || timeOfDay < 16) {
countuser = 12;
} else if (timeOfDay >= 16 || timeOfDay <= 22) {
countuser = 13;
}
break;
}
} catch(Exception e){
e.printStackTrace();
}