我试图在Java中使用Parse.com REST。我已经看过了这里给出的4种解决方案,库并选择了Parse4J。将源代码导入Netbeans之后,以及导入以下库( Netbeans告诉我我需要这些库):
org.slf4j:slf4j-api:jar:1.6.1
org.apache.httpcomponents:httpclient:jar:4.3.2
org.apache.httpcomponents:httpcore:jar:4.3.1
org.json:json:jar:20131018
commons-codec:commons-codec:jar:1.9
junit:junit:jar:4.11
ch.qos.logback:logback-classic:jar:0.9.28
ch.qos.logback:logback-core:jar:0.9.28我从https://github.com/thiagolocatelli/parse4j运行了示例代码
Parse.initialize(APP_ID, APP_REST_API_ID); // I replaced these with mine
ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.save();我知道它缺少org.apache.commons.logging,所以我下载并导入了它。然后我又运行了一次代码
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:120)
at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:122)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:131)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:193)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.parse4j.command.ParseCommand.perform(ParseCommand.java:44)
at org.parse4j.ParseObject.save(ParseObject.java:450)我可能可以用另一个导入来修复这个问题,但我想会有其他的东西出现。我尝试了其他类库的类似结果,错过了一堆库。是否有人在Java中成功地使用了Parse.com REST?如果是这样的话,如果您能分享您所使用的库/库以及成功运行所需的其他任何东西,我将不胜感激。
请不要建议任何你没有尝试过的东西。这可能会让我再次绕圈。
我在使用Netbeans。
谢谢。
发布于 2014-06-01 22:47:13
您可能混淆了解析文档。您的标题是"Rest“。但是,您的代码来自解析ANDROID!
从android _快速修改的示例代码在纯java上接近兼容:
//runnable inside the httpclient's implementation of 'exec'
public void run() {
int httprc = 999;
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(YourConnectionMgr.getInstance())
.addInterceptorLast(new HttpRequestInterceptor() {
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException, IOException {
if(request.getRequestLine().getMethod() == "GET"){
request.addHeader("X-Parse-Application-Id", ParseApplication.key_appId);
request.addHeader("X-Parse-REST-API-Key", ParseApplication.key_rest);
request.addHeader("X-Parse-Session-Token",prefs.getString("default_parse_user_token", ""));
}
}
})
.build();
try {
HttpResponse response = null;
switch (method) {
case GET:
HttpGet httpGet = new HttpGet(url);
httpGet.setProtocolVersion(new ProtocolVersion("HTTP", 1,1));
httpGet.setConfig(this.config);
response = httpClient.execute(httpGet, context);
break; }
} catch (Exception e) {
handler.sendMessage(Message.obtain(handler,
HttpConnection.DID_ERROR, e));
} https://stackoverflow.com/questions/23966074
复制相似问题