0

我正在尝试将图像插入 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

我不知道是什么导致了错误,请帮助我并提前感谢

4

3 回答 3

1

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

于 2013-02-25T17:13:58.437 回答
1

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

这是几个相关链接(顺便说一句,通过谷歌搜索异常找到了它们):

Android 2.2 上的异常“此查询具有出色的网络连接..”

为什么我会收到“此对象具有出色的网络连接”NSInternalInconsistencyException?

于 2013-02-25T06:54:24.317 回答
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();
            }
        }); 
}
于 2013-02-25T23:09:14.810 回答