1

我正在尝试在 Android中运行这个 API java 。因为Android中没有终端,System.out.printlne.printStackTrace没有编译,我试图在我找到它们的CartoDBClient和类中替换它。SecuredCartoDBClient但是,即使这样做,应用程序也会因 LogCat 中的这些错误而意外关闭

这里的代码

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)

感谢您在这件事上的帮助。

4

1 回答 1

0

我猜您还没有将 org.apache.commons lib 添加到您的项目或类路径中。

在这里您可以找到必要的组件并将其添加到您的项目中: http ://commons.apache.org/components.html

您可能缺少 IO 组件。不要忘记将它添加到您的类路径中!

于 2012-05-04T20:25:36.347 回答