Java 官方Windows Azure SDK导致Android捕获错误
我想捕捉这个错误,这样我就可以自己处理它,而不是向用户显示它。我该怎么做 我正在使用适用于Windows Azure的Android官方SDK 此错误可能只出现2-3%的时间。所有其他时间,它连接良好 此外,如果我尝试联系azure的活动不再存在,则上下文不再存在,并且它尝试在不存在的上下文上显示消息,这将导致应用程序崩溃 这段代码基本上直接来自WindowsAzure的todolist示例 谢谢 安东尼GJava 官方Windows Azure SDK导致Android捕获错误,java,android,azure,error-handling,Java,Android,Azure,Error Handling,我想捕捉这个错误,这样我就可以自己处理它,而不是向用户显示它。我该怎么做 我正在使用适用于Windows Azure的Android官方SDK 此错误可能只出现2-3%的时间。所有其他时间,它连接良好 此外,如果我尝试联系azure的活动不再存在,则上下文不再存在,并且它尝试在不存在的上下文上显示消息,这将导致应用程序崩溃 这段代码基本上直接来自WindowsAzure的todolist示例 谢谢 安东尼G try { // Create the Mobi
try {
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
"XXXXXXX",
"YYYYYYYYY", this)
.withFilter(new ProgressFilter());
createTable();
} catch (MalformedURLException e) {
createAndShowDialog(
new Exception(
"There was an error creating the Mobile Service. Verify the URL"),
"Error");
} catch (Exception e) {
Log.d(TAG, "Exepction caught" + e.toString());
}
这里是表格创建部分
try {
Log.d(TAG, "Create table called and started. ");
// Get the Mobile Service Table instance to use
// Don't use the default, because the table on Azure has a different name than the class, instead use this call.
mToDoTable = mClient.getTable("MY_TABLE",
MY_TABLE_SPECIAL_CLASS.class);
// Create an adapter to bind the items with the view
mAdapter = new DownloadedMapsListAdapter(this, R.layout.row_list_show_maps_to_download);
ListView listViewToDo = (ListView) findViewById(R.id.listview_data_fromAzure);
//listViewToDo.setOnItemClickListener(mMessageClickedHandler);
listViewToDo.setAdapter(mAdapter);
// Load the items from the Mobile Service
refreshItemsFromTable();
} catch (Exception e) {
Log.d(TAG, "Exepction caught" + e.toString());
}
好的,我是一个idoit。在refreshItemsFromTable()中,调用了实际的“execute”语句(我没有在问题中发布它)。执行是指它实际联系Azure的时间。该函数检查异常是否为null,而不是使用try-catch。所以显示的是CreateAndShowDialog(异常,字符串) 也许这会帮助其他人
/**
* Refresh the list with the items in the Mobile Service Table
*/
private void refreshItemsFromTable() {
// Get the items that weren't marked as completed and add them in the
// adapter
Log.d(TAG, "refreshItemsFromTable");
mToDoTable.execute(new TableQueryCallback<MapObjects_FromAzure>() {
public void onCompleted(List<MapObjects_FromAzure> result, int count,
Exception exception, ServiceFilterResponse response) {
if (exception == null) {
Log.d(TAG,
"refreshItemsFromTable on complete, with no exception thrown so far. ");
mAdapter.clear();
for (MapObjects_FromAzure item : result) {
mAdapter.add(item);
}
} else {
createAndShowDialog(exception,
"Error" + exception.toString());
}
}
});
/**
*使用移动服务表中的项目刷新列表
*/
私有void refreshItemsFromTable(){
//获取未标记为已完成的项目,并将其添加到
//适配器
Log.d(标记“refreshItemsFromTable”);
执行(新的TableQueryCallback(){
未完成公共无效(列表结果、整数计数、,
异常(ServiceFilterResponse响应异常){
if(异常==null){
Log.d(标签,
“refreshItemsFromTable已完成,到目前为止没有引发异常。”);
mAdapter.clear();
对于(MapObjects\u FromAzure项:结果){
mAdapter.添加(项目);
}
}否则{
createAndShowDialog(异常,
“Error”+异常.toString());
}
}
});