Hello Everyone
I'm trying to create an android application that would connect on a server to get and post information about Events and the Users that can create the events.
I implemented a function on the server that finds all the users in the database, and that sends them with webservices. But when I try to get back that information on my Android application, the application crashes.
Because I work with lists, I tried to work with DTO, but the result is still the same.
I'll put some code to show you how I work
That's some code from my User class (I work with Hibernate)Code:@XmlRootElement(name="user") @Entity @Table(name = "SA_USER") public class User extends BaseEntity implements Serializable { private static final long serialVersionUID = -8386881380312242149L; @Column(name = "FIRST_NAME", nullable = false, length = 32) @Index(name = "INDEX_SA_USER_NAME", columnNames = {"FIRST_NAME", "LAST_NAME"}) private String firstName; @Column(name = "LAST_NAME", nullable = false, length = 32) private String lastName; @Column(name = "USER_NAME", nullable = false, unique = true, length = 64) @IndexColumn(name = "INDEX_SA_USER_USER_NAME") private String userName; @Column(name = "PASSWORD", length = 64) private String password; @Column(name = "EMAIL", nullable = false, unique = true, length = 128) private String email; @Column(name = "PHONE_NUMBER", nullable = true, length = 20) private String phoneNumber; @Column(name = "MOBILE", nullable = true, length = 20) private String mobile; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "GRADE_ID", nullable = false) private Grade grade;
I am able to insert and retrieve correctly information in my Database.
When I want to pass several Users to a client via REST, I use this method :
The UserList code is the following :Code:@RequestMapping(value="/user/all", method = RequestMethod.GET, headers="Accept=application/xml, application/json") public @ResponseBody UserList getAllUsers() { LOGGER.debug("findAllUsers!!"); UserList list = new UserList(); list.setUsers(this.teacherService.findAllUsers()); return list; }
Code:@XmlRootElement(name="userList") public class UserList { private List<User> users; public List<User> getUsers() { return users; } public void setUsers(List<User> users) { this.users = users; } }
That's for the server side.
I tried to get the userlist with the following code on the client (Android) side :
my UserList on client side looks like this :Code:try { userList = restTemplate.getForObject(URL, UserList.class); } catch (RestClientException e) { Toast.makeText(getApplicationContext(), "La connexion a �chou�e!", Toast.LENGTH_LONG).show(); }
my User class on the client side looks like this :Code:@Root(name = "userList") public class UserList { @ElementList(inline = true) private List<User> users; public List<User> getUsers() { return users; } public void setUsers(List<User> users) { this.users = users; } }
to implement all this, I used the spring documentation.Code:@Root public class User { @Element private Long id; @Element private Long version; @Element private String firstName; @Element private String lastName; @Element private String userName; @Element private String password; @Element private String email; @Element private String phoneNumber; @Element private String mobile; @Element private Grade grade;
But, when I try to get the users, The app crashes. I tried to connect to the server using this FireFox add-on ( https://addons.mozilla.org/en-US/fir...on/restclient/ ) and with that add-on, I'm able to get all my users correctly
I hope what I wrote is somewhat understandable
If someone has an idea, it would be very great!
Thank you in advance!



Reply With Quote
