【问题标题】:java azure storage error "enumerating the result"java azure存储错误“枚举结果”
【发布时间】:2015-10-13 05:06:50
【问题描述】:

我正在使用以下代码使用 android azure storage API:

try
{
    // Retrieve storage account from connection-string.
    CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

    // Create the blob client.
    CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

    // Retrieve reference to a previously created container.
    CloudBlobContainer container = blobClient.getContainerReference("appstar");

    // Loop over blobs within the container and output the URI to each of them.
    for (ListBlobItem blobItem : container.listBlobs()) {
        System.out.println(blobItem.getUri());
    }

    // hide dat loader
    progress.dismiss();
}
catch (Exception e)
{
    System.out.println("There was a problem");

    // Output the stack trace.
    e.printStackTrace();

    // hide dat loader
    progress.dismiss();
}

但是当我进入 for 循环时,我收到以下错误:

07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details.
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113)
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at com.k.azurestorage.ConnectionSettingsForm.btn_onCreateSubmitted(ConnectionSettingsForm.java:127)
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at android.view.View$1.onClick(View.java:4015)
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at android.view.View.performClick(View.java:4780)
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at android.view.View$PerformClick.run(View.java:19866)
07-23 12:30:46.371    2362-2362/com.k.azurestorage W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5257)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ Caused by: com.microsoft.azure.storage.StorageException: Network operations may not be performed on the main thread.
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:224)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:109)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ ... 14 more
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ Caused by: android.os.NetworkOnMainThreadException
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:215)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.HostResolver$1.getAllByName(HostResolver.java:29)
07-23 12:30:46.372    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
07-23 12:30:46.382    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
07-23 12:30:46.393    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
07-23 12:30:46.393    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
07-23 12:30:46.393    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
07-23 12:30:46.393    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
07-23 12:30:46.393    2362-2362/com.k.azurestorage W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
07-23 12:30:46.393    2362-2362/com.k.azurestorage W/System.err﹕ at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:125)
07-23 12:30:46.393    2362-2362/com.k.azurestorage W/System.err﹕ ... 15 more

知道这是什么意思吗?

【问题讨论】:

    标签: java android azure-storage


    【解决方案1】:

    首先,让我们检查一下容易导致奇怪错误的基础知识。 :)

    1. 能否确认您使用的是Android library 而不是Java library
    2. 能否确认您在 Android 清单中拥有互联网权限?有关示例,请参阅我们的 samples

    如果这些都不是您的问题,那么您可以执行以下操作吗?

    1. 发布完整的异常跟踪。可迭代 API 要求我们返回 NoSuchElementException,因此我们将异常实际发生的原因包装到其中。完整的堆栈跟踪应该为我们提供进一步调试所需的内容。
    2. 发布您正在使用的 Android 库版本以及您正在运行的 Android 版本。根据changelog,我们过去曾遇到过一些与迭代相关的 Android 错误,这将让我们确认您没有遇到这些错误。

    将调试步骤留给其他人,但这里完整的堆栈跟踪给出了答案。在完整的 strack 跟踪中,您可以看到带有消息“网络操作可能无法在主线程上执行”的 NetworkOnMainThreadException。由于网络操作可能很慢,Android 默认阻止它们在主线程上进行。如果您搜索此错误,您会发现各种有关如何在不阻塞 UI 线程的情况下使用网络操作的示例。

    【讨论】:

    • #1:我正在使用 android lib,#2 我还没有完成。但现在我已经添加并重新运行,并产生了同样的错误。我已经用上面的完整堆栈跟踪替换了缩短的错误。我正在使用azure-storage-android-0.5.1
    • ....但是,我所遵循的实际代码示例来自 azure java 教程...这可能是一个问题。 :) azure.microsoft.com/en-us/documentation/articles/…
    • 更新答案,完整的堆栈跟踪为您提供关键线索。 :)
    • @EmilyGerner 我使用 Java 使用代理从 Blob Azure 存储中读取数据,即使我面临同样的问题。这个问题的解决方法是什么,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 2018-10-28
    • 2020-01-13
    相关资源
    最近更新 更多