我試圖在Android中運行this API java。由於Android中沒有終端,因此System.out.println
和e.printStackTrace
未編譯,我試圖在CartoDBClient
和SecuredCartoDBClient
類中找到它們。然而,即使這樣做,應用程序意外關閉與在logcat的在Android中使用Java API
下面的代碼這些錯誤
SecuredCartoDBClient:
@Override
public String executeQuery(String sqlQuery){
String json = null;
if(oAuthService == null){
//System.out.println("Error : uninitialized " + getClass().getName());
Log.e(TAG, "Error : uninitialized " + getClass().getName(), null);
return null;
}
OAuthRequest request = new OAuthRequest(Verb.POST, securedApiUrl);
request.addBodyParameter("q", sqlQuery);
oAuthService.signRequest(accessToken, request);
Response response = request.send();
if(!response.isSuccessful()){
//System.out.println("The query " + sqlQuery + " failed.");
Log.w(TAG, "The query " + sqlQuery + " failed.", null);
//System.out.println("Response code : " + response.getCode());
Log.i(TAG, "Response code : " + response.getCode(), null);
}
json = response.getBody();
return json;
}
CartoDBClient.java ..
@Override
public String executeQuery(String sqlQuery){
String json = null;
if(apiURL == null){
//System.out.println("Error : uninitialized " + getClass().getName());
Log.e(sqlQuery, "Error : uninitialized " + getClass().getName());
return null;
}
try {
sqlQuery = URLEncoder.encode(sqlQuery,ENCODING);
json = IOUtils.toString(new URL(apiURL+sqlQuery), ENCODING);
} catch (MalformedURLException e) {
//System.out.println("Could not get URL " + apiURL+sqlQuery);
Log.w(TAG, "Could not get URL " + apiURL+sqlQuery);
Log.e(TAG, Log.getStackTraceString(e));
//e.printStackTrace();
} catch (UnsupportedEncodingException e) {
Log.e(TAG, Log.getStackTraceString(e));
//e.printStackTrace();
}catch (IOException e) {
//System.out.println("Could not execute " + sqlQuery+ " on CartoDB : ");
Log.w(TAG, "Could not execute " + sqlQuery+ " on CartoDB : ");
Log.e(TAG, Log.getStackTraceString(e));
//e.printStackTrace();
}
return json;
}
這裏的錯誤出現在logcat
05-04 19:58:39.128: E/AndroidRuntime(372): FATAL EXCEPTION: main
05-04 19:58:39.128: E/AndroidRuntime(372): java.lang.NoClassDefFoundError: org.apache.commons.io.IOUtils
05-04 19:58:39.128: E/AndroidRuntime(372): at com.geocap.impl.CartoDBClient.executeQuery(CartoDBClient.java:84)
05-04 19:58:39.128: E/AndroidRuntime(372): at com.geocap.Geocap.onCreate(Geocap.java:25)
05-04 19:58:39.128: E/AndroidRuntime(372): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
05-04 19:58:39.128: E/AndroidRuntime(372): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
05-04 19:58:39.128: E/AndroidRuntime(372): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
05-04 19:58:39.128: E/AndroidRuntime(372): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
05-04 19:58:39.128: E/AndroidRuntime(372): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
05-04 19:58:39.128: E/AndroidRuntime(372): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 19:58:39.128: E/AndroidRuntime(372): at android.os.Looper.loop(Looper.java:126)
05-04 19:58:39.128: E/AndroidRuntime(372): at
android.app.ActivityThread.main(ActivityThread.java:3997)
05-04 19:58:39.128: E/AndroidRuntime(372): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 19:58:39.128: E/AndroidRuntime(372): at java.lang.reflect.Method.invoke(Method.java:491)
05-04 19:58:39.128: E/AndroidRuntime(372): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-04 19:58:39.128: E/AndroidRuntime(372): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-04 19:58:39.128: E/AndroidRuntime(372): at dalvik.system.NativeStart.main(Native Method)
感謝您在這件事情上的幫助。
你的代碼中哪行是84行? –
printStackTrace絕對支持。 –
你解決了這個問題嗎?我有一個類似的。 – Hong