本文整理匯總了Java中android.net.ParseException類的典型用法代碼示例。如果您正苦於以下問題:Java ParseException類的具體用法?Java ParseException怎麽用?Java ParseException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParseException類屬於android.net包,在下文中一共展示了ParseException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleResponseError
import android.net.ParseException; //導入依賴的package包/類
@Override
public void handleResponseError(Context context, Throwable t) {
Timber.tag("Catch-Error").w(t.getMessage());
//這裏不光是隻能打印錯誤,還可以根據不同的錯誤作出不同的邏輯處理
String msg = "未知錯誤";
if (t instanceof UnknownHostException) {
msg = "網絡不可用";
} else if (t instanceof SocketTimeoutException) {
msg = "請求網絡超時";
} else if (t instanceof HttpException) {
HttpException httpException = (HttpException) t;
msg = convertStatusCode(httpException);
} else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
msg = "數據解析錯誤";
}
ArmsUtils.snackbarText(msg);
}
示例2: stringToDate
import android.net.ParseException; //導入依賴的package包/類
public static Date stringToDate(String strTime)
throws ParseException
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try
{
date = formatter.parse(strTime);
}
catch (java.text.ParseException e)
{
e.printStackTrace();
}
return date;
}
示例3: handleResponseError
import android.net.ParseException; //導入依賴的package包/類
@Override
public void handleResponseError(Context context, Throwable t) {
//Used to provide a monitor for handling all errors
//rxjava need to use ErrorHandleSubscriber (the default implementation of Subscriber's onError method), this monitor to take effect
Timber.tag("Catch-Error").w(t.getMessage());
//Here is not only print errors, but also according to different errors to make different logical processing
String msg = "Unknown";
if (t instanceof UnknownHostException) {
msg = "The network is not available";
} else if (t instanceof SocketTimeoutException) {
msg = "Network timeout";
} else if (t instanceof HttpException) {
HttpException httpException = (HttpException) t;
msg = convertStatusCode(httpException);
} else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
msg = "Data parsing error";
}
UiUtils.snackbarText(msg);
}
示例4: handleResponseError
import android.net.ParseException; //導入依賴的package包/類
@Override
public void handleResponseError(Context context, Throwable t) {
//用來提供處理所有錯誤的監聽
//rxjava必要要使用ErrorHandleSubscriber(默認實現Subscriber的onError方法),此監聽才生效
Timber.tag("Catch-Error").w(t.getMessage());
//這裏不光是隻能打印錯誤,還可以根據不同的錯誤作出不同的邏輯處理
String msg = "未知錯誤";
if (t instanceof UnknownHostException) {
msg = "網絡不可用";
} else if (t instanceof SocketTimeoutException) {
msg = "請求網絡超時";
} else if (t instanceof HttpException) {
HttpException httpException = (HttpException) t;
msg = convertStatusCode(httpException);
} else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException) {
msg = "數據解析錯誤";
}
UiUtils.snackbarText(msg);
}
示例5: getReferrerCompatible
import android.net.ParseException; //導入依賴的package包/類
/** Returns the referrer on devices running SDK versions lower than 22. */
private Uri getReferrerCompatible(Activity activity) {
Intent intent = activity.getIntent();
Uri referrerUri = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
if (referrerUri != null) {
return referrerUri;
}
String referrer = intent.getStringExtra(REFERRER_NAME);
if (referrer != null) {
// Try parsing the referrer URL; if it's invalid, return null
try {
return Uri.parse(referrer);
} catch (ParseException e) {
return null;
}
}
return null;
}
示例6: onError
import android.net.ParseException; //導入依賴的package包/類
@Override
public void onError(Throwable e) {
if (baseView != null) {
baseView.hideLoading();
}
if (e instanceof BusinessException) {
} else if (e instanceof ConnectException
|| e instanceof SocketTimeoutException) {// 超時
baseView.onError("網絡不暢,請稍後再試!");
} else if (e instanceof HttpException) {// server 異常
httpExceptionHandling(e);
} else if (e instanceof JSONException
|| e instanceof ParseException) {
baseView.onError("數據解析異常");
} else {
// baseView.onError("出了點小問題");
onOtherError(e);
}
e.printStackTrace();
}
示例7: gofordate
import android.net.ParseException; //導入依賴的package包/類
static String gofordate(String s) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = format.parse(s);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
String[] weekDays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
System.out.println("date" + date + " weekDays " + weekDays[w]);
return weekDays[w];
}
示例8: buildObject
import android.net.ParseException; //導入依賴的package包/類
public static SynergykitObject buildObject(int statusCode,BufferedReader data,Type type){
// Param check
if(data == null || statusCode!= HttpStatus.SC_OK)
return null;
// Build object
try {
return (SynergykitObject) GsonWrapper.getGson().fromJson(data, type);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例9: buildObjects
import android.net.ParseException; //導入依賴的package包/類
public static SynergykitObject[] buildObjects(int statusCode, BufferedReader data, Type type){
SynergykitObject[] baseObjects;
// Param check
if(data == null || statusCode!=HttpStatus.SC_OK)
return null;
// Build objects
try {
baseObjects = (SynergykitObject[]) GsonWrapper.getGson().fromJson(data, type);
return baseObjects;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例10: buildError
import android.net.ParseException; //導入依賴的package包/類
public static SynergykitError buildError(int statusCode, BufferedReader data){
SynergykitError errorObject;
// Param check
if(data == null)
return null;
// Build error
try {
errorObject = (SynergykitError) GsonWrapper.getGson().fromJson(data, SynergykitError.class);
errorObject.setStatusCode(statusCode);
return errorObject;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例11: handleException
import android.net.ParseException; //導入依賴的package包/類
private void handleException(String authtoken, Exception e,
SyncResult syncResult) {
if (e instanceof AuthenticatorException) {
syncResult.stats.numParseExceptions++;
Log.e("SyncAdapter", "AuthenticatorException", e);
} else if (e instanceof OperationCanceledException) {
Log.e("SyncAdapter", "OperationCanceledExcepion", e);
} else if (e instanceof IOException) {
Log.e("SyncAdapter", "IOException", e);
syncResult.stats.numIoExceptions++;
} else if (e instanceof AuthenticationException) {
accountManager.invalidateAuthToken(Authenticator.ACCOUNT_TYPE, authtoken);
syncResult.stats.numIoExceptions++;
if (authtoken != null)
Log.e("SyncAdapter", "Auth failed, invalidating token: " + authtoken);
Log.e("SyncAdapter", "AuthenticationException", e);
} else if (e instanceof ParseException) {
syncResult.stats.numParseExceptions++;
Log.e("SyncAdapter", "ParseException", e);
} else if (e instanceof JsonParseException) {
syncResult.stats.numParseExceptions++;
Log.e("SyncAdapter", "JSONException", e);
} else if (e instanceof ServerUrlPreferenceNotSetException) {
Log.e("SyncAdapter", "ServerUrlPreferenceNotSetException", e);
}
}
示例12: getAnswerContentValues
import android.net.ParseException; //導入依賴的package包/類
private ContentValues getAnswerContentValues(JSONObject answer) throws AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException
{
ContentValues values = new ContentValues();
values.put(AnswersEntry.COLUMN_TIMESTAMP, answer.optString("LastChangedTime"));
values.put(AnswersEntry.COLUMN_ANSWER, answer.optString("Content"));
values.put(AnswersEntry.COLUMN_DATE, SyncHelper.getUnixMillisecondsFromJsonDate(answer.optString("Date")));
values.put(AnswersEntry.COLUMN_ANSWERSTATE, getAnswerStateForId(answer.optInt("answerState")).toString());//TODO
String backendid = answer.optString("Id");
if (backendid != null)
{
values.put(AnswersEntry.COLUMN_BACKEND_ID, SyncHelper.getIdFromURI(backendid));
}
String answerer = answer.optString("Answerer");
if (answerer != null && !answerer.equals("null") && answerer.length() > 0)
{
values.put(AnswersEntry.COLUMN_ANSWERER_ID, SyncHelper.getRealIdForObjectURI(answerer, context));
}
return values;
}
示例13: getExceptionMessage
import android.net.ParseException; //導入依賴的package包/類
public static String getExceptionMessage(Throwable throwable) {
String message;
if (throwable instanceof ApiException) {
message = throwable.getMessage();
} else if (throwable instanceof SocketTimeoutException) {
message = "網絡連接超時,請稍後再試";
} else if (throwable instanceof ConnectException) {
message = "網絡連接失敗,請稍後再試";
} else if (throwable instanceof HttpException||throwable instanceof retrofit2.HttpException) {
message = "網絡出錯,請稍後再試";
} else if (throwable instanceof UnknownHostException || throwable instanceof NetNotConnectedException) {
message = "當前無網絡,請檢查網絡設置";
} else if (throwable instanceof SecurityException) {
message = "係統權限不足";
} else if (throwable instanceof JsonParseException
|| throwable instanceof JSONException
|| throwable instanceof ParseException) {
message = "數據解析錯誤";
} else if (throwable instanceof javax.net.ssl.SSLHandshakeException) {
message = "網絡證書驗證失敗";
} else {
message = throwable.getMessage();
if (message==null||message.length() <= 40) {
message = "出錯了 ≥﹏≤ ,請稍後再試";
}
}
return message;
}
示例14: onError
import android.net.ParseException; //導入依賴的package包/類
@Override
public void onError(Throwable throwable) {
if (throwable instanceof IOException) {
if (throwable instanceof UnknownHostException) {
//服務器異常
handleError(INTERRUPTED_IOEXCEPTION, "網絡異常,請稍後重試");
} else if (throwable instanceof InterruptedIOException) {
//超時異常
handleError(INTERRUPTED_IOEXCEPTION, "網絡異常,請稍後重試");
} else {
handleError(OTHER_IOEXCEPTION, "網絡異常,請稍後重試");
}
} else if (throwable instanceof HttpException) {
//retrofit請求木有返回
handleError(HTTP_EXCEPTION, "網絡異常,請稍後重試");
} else if (throwable instanceof JsonParseException
|| throwable instanceof JSONException
|| throwable instanceof ParseException) {
//解釋數據錯誤
handleError(EXCHANGE_DATA_ERROR, "解釋數據錯誤");
} else if (throwable instanceof DlException) {
DlException dlException = (DlException) throwable;
handleError(dlException.getErrorCode(), dlException.getErrorMessage());
} else {
handleError(UNKONW_EXCEPTION, "網絡異常,請稍後重試");
}
}
示例15: gzipToString
import android.net.ParseException; //導入依賴的package包/類
public static String gzipToString(final HttpEntity entity, final String defaultCharset) throws IOException, ParseException {
if (entity == null) {
throw new IllegalArgumentException("HTTP entity may not be null");
}
InputStream instream = entity.getContent();
if (instream == null) {
return "";
}
// gzip logic start
if (entity.getContentEncoding().getValue().contains("gzip")) {
instream = new GZIPInputStream(instream);
}
// gzip logic end
if (entity.getContentLength() > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
}
int i = (int)entity.getContentLength();
if (i < 0) {
i = 4096;
}
String charset = EntityUtils.getContentCharSet(entity);
if (charset == null) {
charset = defaultCharset;
}
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
Reader reader = new InputStreamReader(instream, charset);
CharArrayBuffer buffer = new CharArrayBuffer(i);
try {
char[] tmp = new char[1024];
int l;
while((l = reader.read(tmp)) != -1) {
buffer.append(tmp, 0, l);
}
} finally {
reader.close();
}
return buffer.toString();
}