本文整理汇总了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();
}