I’m trying to build an application in Android using some codes from Objective-C (IPhone app).I’m trying to understand what exactly is doing a piece of code and translate it into Java code,but I think I need a little help here.So first, here is the Obj-C code :
(BOOL)processSqlInjectQueries:(NSArray *)injectQueries error:(NSError**)error {
//some code
for(NSDictionary * q in injectQueries)
{
if (![q isKindOfClass:[NSDictionary class]]) continue;
StPacketInjectQueryPackage qType = (StPacketInjectQueryPackage)[[q objectForKey:@"type"] intValue];
NSString * query = [q objectForKey:@"query"];
}
//some code
}
In Java, I’m trying to do something like this :
// in some other method :
JSONObject jsonData= new JSONObject();
String authHash = jsonData.getJSONObject("client_auth_hash").toString();
List<Map<String,String>> injectQueries= new ArrayList<Map<String,String>>();
injectQueries.add(new HashMap<String, String>());
//injectQueries.add(authHash);
public boolean processSqlInjectQueries(List<Map<String,String>> injectQueries, Exception error){
if(injectQueries==null || injectQueries.size()==0){
boolean injectsProcessed = this.processSqlInjectQueries(injectQueries,error);
if(!injectsProcessed){
return false;
}
}
Log.i("Info","Processing INJECT Queries...");
boolean res = true;
/*[_dbAdapter beginTransaction];
[_user.userDbAdapter beginTransaction];*/
for(Map<String,String> b : injectQueries){
if(b.getClass().getName()!=injectQueries.getClass().getName()){
continue;
}
//RPCPacketInjectQueryPackage qType = (RPCPacketInjectQueryPackage)
}
return true;
}
But my problem is that is that I get this error : Type mismatch: cannot convert from element type Object to ArrayList.
Any suggestion how to fix that error?
And second question : Can I use Exception error in declaraion of processSqlInjectQueries instead of NSError *error in Obj-C?
The objective C code is passing through an NSArray containing NSDictionaries through to the method, so the following is probably closer to what you want to do…
To handle the error code, you probably want to think about throwing an exception rather than trying to pass through an “Error” object, so something like the following:
You’ll want to tailor the exact Exception that’s thrown so it matches whatever your code is trying to do.
In response to comment: perhaps this is closer to what you’re trying to do?
And you could call it with: