gpt4 book ai didi

java - 从 Parse 下载文件抛出 NullPointerException

转载 作者:行者123 更新时间:2023-12-01 11:09:31 25 4
gpt4 key购买 nike

在我的应用程序中,我可以成功地将文件上传到 parse.com。但是当我尝试下载它时,它给出了空指针异常。这是我下载文件的代码。

ParseObject downloadData = new ParseObject("DownloadData");
ParseFile downloadFile = (ParseFile) downloadData.get("File");
downloadFile.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] bytes, ParseException e) {
if (e == null) {
String x= new String(bytes);
new AlertDialog.Builder(MainActivity2.this)
.setTitle("Downloaded File")
.setMessage(x)
.setPositiveButton("Ok", null)
.show();
} else {
new AlertDialog.Builder(MainActivity2.this)
.setTitle("Download File")
.setMessage("An Error Occurred")
.setPositiveButton("Ok", null)
.show();
}
}
});

官方文档很困惑。谁能告诉我解决这个问题的方法。

最佳答案

您不能对这样创建的 ParseObject 调用 get() 。首先,您需要在 Parse 类上调用 parseQuery 并从该查询结果中获取此 ParseObject。现在在此 ParseObject 上调用 get()。

ParseQuery<ParseObject> query = ParseQuery.getQuery("DownloadData");
query.getInBackground("parse_object_id", new GetCallback<ParseObject>() {
public void done(ParseObject downloadData, ParseException e) {
if (e == null) {
// This object will contain your file
ParseFile downloadFile = (ParseFile) downloadData.get("File");
downloadFile.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] bytes, ParseException e) {
if (e == null) {
String x= new String(bytes);
new AlertDialog.Builder(MainActivity2.this)
.setTitle("Downloaded File")
.setMessage(x)
.setPositiveButton("Ok", null)
.show();
} else {
new AlertDialog.Builder(MainActivity2.this)
.setTitle("Download File")
.setMessage("An Error Occurred")
.setPositiveButton("Ok", null)
.show();
}
}
});
} else {
// something went wrong
}

});

关于java - 从 Parse 下载文件抛出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32542798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com