我正在使用Parse.com作为我的后端。我试图在背景中加载一个工作正常的对象,但这些对象有一个指向图像的指针。问题是,为了查询图像类中的图像,我传递一个ParseObject,以便得到图像所指向的对象:
ParseObject advertToGetImageFrom = ParseObject.createWithoutData("Advert", advertList.get(j).getObjectId());
但是,我的日志显示了此结果
D / app:DT34J9zFKI
D / app:dAqVrnZ1rf
D / app:bNtIfOCqeE
D / app:已加载图片:1
D / app:已加载图片:1
D / app:已加载图片:1
这是合理的,因为加载是异步的。但是,所有返回的图像都一样吗?为什么会这样?这是整个电话:
for (int j = 0; j < titleMap.size(); j++){
ParseQuery<ParseObject> query2 = ParseQuery.getQuery("Image");
ParseObject advertToGetImageFrom = ParseObject.createWithoutData("Advert", objectList.get(j).getObjectId());
Log.d("app", advertToGetImageFrom.getObjectId());
query2.whereEqualTo("advertId", advertToGetImageFrom);
query2.findInBackground(new FindCallback<ParseObject>() {
public void done(final List<ParseObject> imageList, ParseException e) {
// commentList now has the comments for myPost
Log.d("app", "Images loaded: " + imageList.size());
if (imageList != null) {
ParseFile pFile = (ParseFile) imageList.get(0).get("image");
pFile.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = decodeFile(data);
ParseObject advertID = imageList.get(0).getParseObject("advertId");
imageMap.put(advertID.getObjectId(), bmp);
if (imageMap.size() == titleMap.size())
updateCardView();
} else {
Log.d("test", "There was a problem downloading the data.");
}
}
});
}
}
});
}
答案 0 :(得分:0)
不熟悉parse.com,但我可以冒险猜测。
我怀疑你的问题在于:
ParseObject advertID = imageList.get(0).getParseObject("advertId");
您正在访问imageList
调用done
回调的findInBackground
。问题是您现在处于done
getDataInBackground
调用的imageList
回调中,尽管final
为advertID
但不会使其成为不可变的并且可能在原始版本后发生了变化调用
乍一看似乎并不是一件可怕的事情,因为这只会影响 pFile.getDataInBackground(new GetDataCallback() {
// **** Grab the ParseObject befor it gets changed.
ParseObject theParseObject = imageList.get(0);
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = decodeFile(data);
// **** Refer to the grabbed ParseObject not the changing outer one.
ParseObject advertID = theParseObject.getParseObject("advertId");
,但会进一步思考,你可能会发现问题。
我认为解决方案可能来获取可能会更改的数据的本地副本。类似的东西:
' Constants (taken from WinReg.h)
'
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
' Chose computer name, registry tree and key path
'
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
ObjExcel.Cells (1,1) = "Application Name"
ObjExcel.Cells (1,4) = "Application Vendor"
ObjExcel.Cells (1,2) = "Application Version"
ObjExcel.Cells (1,3) = "DRM Build"
strComputer = InputBox("Enter the Machine name. To run on the current machine, press ENTER", "Machine Name", "")
If strComputer = "" Then
strComputer = "."
End If
Msgbox "Script is Running and may take couple of minutes to complete. Click on OK to continue",0, "Information"
hDefKey = HKEY_LOCAL_MACHINE
' Connect to registry provider on target machine with current user
Set oReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
'{impersonationLevel=impersonate}!
' Enum the subkeys of the key path we've chosen
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
row = 2
getRegistryEntries hDefKey, strKeyPath, ObjExcel, oReg, row
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
getRegistryEntries hDefKey, strKeyPath, ObjExcel, oReg, row
fileName = Year(now) & month(now) & day(now) & hour(now) & minute(now) & second(now)
ObjExcel.ActiveWorkbook.SaveAs "C:\" & fileName & ".xlsx"
ObjExcel.Quit
Set ObjExcel = Nothing
msgbox "Work Done, file saved in C Drive with the name: " & fileName
Function getRegistryEntries(hDefKey, strKeyPath, byRef objExcel, byRef oReg, byRef row)
oReg.EnumKey hDefKey, strKeyPath, arrSubKeys
Set objShell = CreateObject("WScript.Shell")
For Each strSubkey In arrSubKeys
' Show the subkey
'
furtherKeys = False
strDisName = "HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & strSubkey & "\DisplayName"
On Error Resume Next
present = False
disName = objShell.RegRead(strDisName)
If disName <> "" Then
present = True
End If
disVersionPresent = false
disVer = ""
If present = true Then
strDisVer = "HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & strSubkey & "\DisplayVersion"
strDisVendor = "HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & strSubkey & "\Publisher"
strDRMBuild = "HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & strSubkey & "\DRMBUILD"
disVer = objShell.RegRead(strDisVer)
If err.number = 0 Then
disVersionPresent = True
End If
If disVersionPresent Then
ObjExcel.Cells (row,1) = disName
ObjExcel.Cells (row,2) = "'" & disVer
furtherKeys = True
disVendor = objShell.RegRead(strDisVendor)
If err.number = 0 Then
ObjExcel.Cells (row,4) = disVendor
End If
DRMBuild = objShell.RegRead(strDRMBuild)
If err.number = 0 Then
ObjExcel.Cells (row,3) = "'" & DRMBuild
End If
End If
End If
If furtherKeys Then
row = row + 1
End If
Next
End Function
如果这不能解决您的问题,那么我确信它会是这样的。