Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:37:02+00:00 2026-06-12T16:37:02+00:00

I am developing a restlet server inside a Glassfish server that will receive petitions

  • 0

I am developing a restlet server inside a Glassfish server that will receive petitions from an Android client.

Based on the Hello World application and on the Object serialization tutorial

Here’s some code:


Server Side

MyUser.java

package com.server.common;

import java.io.Serializable;

public class MyUser implements Serializable {

private static final long serialVersionUID = 1L;
private String username;

public MyUser() {}

public MyUser(String username) {
    super();
    this.username = username;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}
}

UserResource.java

package com.server.common;

import org.restlet.resource.Get;

public interface UserResource {
@Get
public MyUser getUser();
}

UserServerResource.java

package com.server;

import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import com.server.common.MyUser;
import com.server.common.UserResource;

public class UserServerResource extends ServerResource implements UserResource {

@Get
public MyUser getUser() {
    MyUser u = new MyUser("Nickname from server");
    return u;
}
}

Client Side

  • The same UserResource.java and MyUser.java inside the package com.client.common

  • MainActivity.java extract

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ClientResource cr = new ClientResource(
            "http://MYSERVERIP:8080/FamilyWeb/username");
    resource = cr.wrap(UserResource.class);
    
    try {
        MyUser u = resource.getUser();
        Log.w("success",u.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    

LogCat

09-29 22:31:52.650: W/System.err(1409): java.lang.NullPointerException
09-29 22:31:52.650: W/System.err(1409):     at com.dimunoz.family.tablet.MainActivity.onCreate(MainActivity.java:33)
09-29 22:31:52.650: W/System.err(1409):     at android.app.Activity.performCreate(Activity.java:4465)
09-29 22:31:52.650: W/System.err(1409):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-29 22:31:52.660: W/System.err(1409):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-29 22:31:52.660: W/System.err(1409):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-29 22:31:52.660: W/System.err(1409):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-29 22:31:52.660: W/System.err(1409):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-29 22:31:52.660: W/System.err(1409):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 22:31:52.660: W/System.err(1409):     at android.os.Looper.loop(Looper.java:137)
09-29 22:31:52.660: W/System.err(1409):     at android.app.ActivityThread.main(ActivityThread.java:4424)
09-29 22:31:52.660: W/System.err(1409):     at java.lang.reflect.Method.invokeNative(Native Method)
09-29 22:31:52.660: W/System.err(1409):     at java.lang.reflect.Method.invoke(Method.java:511)
09-29 22:31:52.660: W/System.err(1409):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-29 22:31:52.660: W/System.err(1409):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-29 22:31:52.660: W/System.err(1409):     at dalvik.system.NativeStart.main(Native Method)

If I change the getUser() method to return a String object and make the respective changes, my Android client gets the response, but if I run the code shown above, I get a NullPointerException.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:37:04+00:00Added an answer on June 12, 2026 at 4:37 pm

    The problem was that the name of the common files packages was different in the server and the client, so the solution was to rename them to the same name.

    In the Restlet Mailing List one of the moderators, Thierry Boileau, answered me why they should have the same name:

    the common classes between the server and client parts (such as the classes
    for the bean objects that are serialized/deserialized) must be located in
    the same packages. The reason is that the serialization/deserialization
    process leverages conventions, in particular convention regarding the full
    path of the bean classes are referenced inside the JSON representation.
    All other classes such as ClientResource, annotated interfaces could be
    located in distinct packages between client/server projects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a product that will use extensively of Restlet for consume WCF Rest
Developing an application for Android, i want to record data that will be usefull
Developing a Sencha Touch MVC app that pulls data from json store (thats set
Im developing a webapp that is feeded via a server. Its index presents some
Developing for Android 2.3, I have a question regarding layouts. I use a vertival
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and
While developing an application using gwt in ecliplse crashed. Now the server is running
Developing an Android App integrated with Facebook. After registering my app on Facebook, getting
Developing a site that requires monthly subscriptions via PayPal. If a buyer has an
Developing a series of POCOs on my project, and just realized that some of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.