插入图像获取异步错误

时间:2013-02-25 04:14:43

标签: android android-asynctask parse-platform

我正在尝试将图像插入Parse云但我收到错误 这是我的代码:

public void uploadImage() { 
File f = new File("/mnt/sdcard/test.jpg");  
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
ParseFile file = new ParseFile("test.jpg",bitmapToByteArray(bmp));
file.saveInBackground();
test = new ParseObject("Testing");
test.put("images", file);
test.saveInBackground();    
}

来自LogCat的错误代码:

02-25 12:08:53.259: E/AndroidRuntime(12444): FATAL EXCEPTION: AsyncTask #2
02-25 12:08:53.259: E/AndroidRuntime(12444): java.lang.RuntimeException: An error occured while executing doInBackground()
02-25 12:08:53.259: E/AndroidRuntime(12444):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.lang.Thread.run(Thread.java:1096)
02-25 12:08:53.259: E/AndroidRuntime(12444): Caused by: java.lang.RuntimeException: This query has an outstanding network connection. You have to wait until it's done.
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.ParseFile.assertNotRunning(ParseFile.java:126)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.ParseFile.save(ParseFile.java:264)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.ParseFile.save(ParseFile.java:258)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.ParseObject.deepSave(ParseObject.java:1527)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.ParseObject.save(ParseObject.java:924)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.ParseObject$5.run(ParseObject.java:957)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.ParseObject$5.run(ParseObject.java:954)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.BackgroundTask.doInBackground(BackgroundTask.java:39)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at com.parse.BackgroundTask.doInBackground(BackgroundTask.java:1)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
02-25 12:08:53.259: E/AndroidRuntime(12444):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-25 12:08:53.259: E/AndroidRuntime(12444):    ... 4 more

我不知道导致错误的原因,请帮助我并提前致谢

3 个答案:

答案 0 :(得分:1)

您正在尝试同时保存文件和包含它的对象 - 显然,您正在使用的框架不允许这样做。因此,要么不这样做,要么将后续调用作为第一次调用的成功/完全回调。

这是一些相关的链接(顺便说一下通过谷歌搜索异常找到它们):

Exception "This query has an outstanding network connection.." on Android 2.2

Why am I getting a "This object has an outstanding network connection" NSInternalInconsistencyException?

答案 1 :(得分:1)

摆脱对file.saveInBackground()的调用。保存对象将自动处理。

答案 2 :(得分:0)

我必须把它改成这个

public void uploadImage()  {
        test = new ParseObject("Testing");
        File f = new File("/mnt/sdcard/test.jpg");

        Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
        file = new ParseFile("test.jpg",bitmapToByteArray(bmp));
        file.saveInBackground(new SaveCallback() {

            @Override
            public void done(ParseException e) {
                // TODO Auto-generated method stub

                test.put("images", file);
                test.saveInBackground();
            }
        }); 
}