我正在使用 maven 和 spring resttemplate 开发 android 应用程序。
这是我的 pom.xml
<properties>
<platform.version> 2.3.3</platform.version>
<spring.version>1.0.0.RELEASE</spring.version>
<simple-version>2.4.1</simple-version>
</properties>
<dependencies>
<!-- Spring Android Core -->
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Rest Android -->
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-rest-template</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Using Jackson for JSON marshaling -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.7.1</version>
</dependency>
<!-- Using Simple for XML marshaling -->
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>${simple-version}</version>
<exclusions>
<exclusion>
<artifactId>stax</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<platform>10</platform>
</sdk>
<emulator>
<avd>10</avd>
</emulator>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
在主活动中,我将此代码放入按钮中:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String email = "user@xxxx.com";
String passwd = "123456";
restTemplate = new RestTemplate();
try {
Users user = restTemplate.getForObject(URL + "/{email}/{password}",
Users.class, email, passwd);
if (user != null) {
System.out.println("Mi nombre es: " + user);
}
} catch (ResourceAccessException ex) {
System.out.println("OFF");
} catch (RestClientException ex) {
System.out.println("Error");
}
}
});
当我在设备中运行我的应用程序时,这是 logCat 中显示的错误:
java.lang-IllegalArgumentException: 'messageConverters' must not be empty
谢谢!!!!