开发者

Unable to find RestTemplate Class in Maven dependencies [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have faced a very big problem the past two months in that I am using Spring Android in Eclipse with Maven dependencies, but there is an error,

NoClassDefFound: org.springframework.web.client.RestTemplate.

But I can't find the source of this error. What is it?

Error:

06-03 12:46:44.102: ERROR/AndroidRuntime(1265): FATAL EXCEPTION: main
06-03 12:46:44.102: ERROR/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org.springframework.web.client.RestTemplate
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at com.ex.newRest.newRest.onCreate(newRest.java:20)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.os.Looper.loop(Looper.java:123)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at java.lang.reflect.Method.invokeNative(Native Method)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at java.lang.reflect.Method.invoke(Method.java:507)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-03 12:46:44.102: ERROR/AndroidRuntime(1265):     at dalvik.system.NativeStart.main(Native Method)

Code:

package com.ex.newRest;
import org.springframework.web.client.RestTemplate;

import android.app.Activity;
import android.os.Bundle;

public class newRest extends Activity {
    /** Called when the activity is first created. */

    String postalCode;
    String countryCode;
    String radius;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        RestTemplate restTemplate = new RestTemplate();
   开发者_运维百科         // The HttpComponentsClientHttpRequestFactory uses the
            // org.apache.http package to make network requests.

            // restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());

            // The URL for making the GET request.
            final String url = "http://ws.geonames.org/findNearbyPostalCodesJSON?postalcode={postalCode}&country={countryCode}&radius={radius}";

            String result = restTemplate.getForObject(url, String.class);
            System.out.println("Response->"+result);
            // Initiate the HTTP GET request, expecting an array of State
            // objects in response.
            //PostalCodes result = restTemplate.getForObject(
            //                        url, PostalCodes.class, this.postalCode, this.countryCode,
            //this.radius);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜