java - 官方Windows Azure SDK导致的Android捕获错误

标签 java android azure error-handling

我想捕获此错误,以便我自己处理它,而不显示给用户。我该怎么做???

我使用的是适用于Windows Azure的Android官方SDK。

可能只有2-3%的时间出现此错误。其他所有时间都很好。

另外,如果我尝试联系azure的 Activity 不再存在,那么上下文就不再存在,并且它会尝试在不存在的上下文中显示消息,这将使应用程序崩溃。

这段代码基本上来自Windows Azure的todolist示例。

谢谢,

安东尼·G。

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

最佳答案

好吧,我是个白痴。在refreshItemsFromTable()中,正在调用实际的“execute”语句(我没有在问题中发帖)。执行是当它实际与Azure联系时。该函数检查异常是否为null而不是使用try-catch。所以显示的是CreateAndShowDialog(exception,string)。

也许这会帮助别人。

/**
 * 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());
            }
        }
    });

关于java - 官方Windows Azure SDK导致的Android捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18512599/

相关文章:

java - MapReduce Apache Hadoop 技术

java - 简单的KTable构造

java - 从本地网络连接到 Red5 服务器

java - 使用静态类或抽象类创建对象

android - 如何备份 Android 数据库 - 启用 WAL

java - 带有 Jetty 的 SPDY "Hello server"

Android加速度计移动球

php - 在 Ubuntu 上从 PHP 连接到 SQL Azure

c# - 在 Azure 云服务项目中发布内容文件

node.js - 如何使Azure Functions按顺序连续消费/处理Azure Service Bus Queue消息?