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

  • Home
  • SEARCH
  • 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 234423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:11:01+00:00 2026-05-11T20:11:01+00:00

I’ve run through the Google Web Toolkit StockWatcher Tutorial using Eclipse and the Google

  • 0

I’ve run through the Google Web Toolkit StockWatcher Tutorial using Eclipse and the Google Plugin, and I’m attempting to make some basic changes to it so I can better understand the RPC framework.

I’ve modified the “getStocks” method on the StockServiceImpl server-side class so that it returns an array of Stock objects instead of String objects. The application compiles perfectly, but the Google Web Toolkit is returning the following error:

“No source code is available for type com.google.gwt.sample.stockwatcher.server.Stock; did you forget to inherit a required module?”

Google Web Toolkit Hosted Mode

It seems that the client-side classes can’t find an implementation of the Stock object, even though the class has been imported. For reference, here is a screenshot of my package hierarchy:

Eclipse Package Hierarchy

I suspect that I’m missing something in web.xml, but I have no idea what it is. Can anyone point me in the right direction?

EDIT: Forgot to mention that the Stock class is persistable, so it needs to stay on the server-side.

  • 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-05-11T20:11:01+00:00Added an answer on May 11, 2026 at 8:11 pm

    After much trial and error, I managed to find a way to do this. It might not be the best way, but it works. Hopefully this post can save someone else a lot of time and effort.

    These instructions assume that you have completed both the basic StockWatcher tutorial and the Google App Engine StockWatcher modifications.

    Create a Client-Side Implementation of the Stock Class

    There are a couple of things to keep in mind about GWT:

    1. Server-side classes can import client-side classes, but not vice-versa (usually).
    2. The client-side can’t import any Google App Engine libraries (i.e. com.google.appengine.api.users.User)

    Due to both items above, the client can never implement the Stock class that we created in com.google.gwt.sample.stockwatcher.server. Instead, we’ll create a new client-side Stock class called StockClient.

    StockClient.java:

    package com.google.gwt.sample.stockwatcher.client;
    
    import java.io.Serializable;
    import java.util.Date;
    
    public class StockClient implements Serializable {
    
      private Long id;
      private String symbol;
      private Date createDate;
    
      public StockClient() {
        this.createDate = new Date();
      }
    
      public StockClient(String symbol) {
        this.symbol = symbol;
        this.createDate = new Date();
      }
    
      public StockClient(Long id, String symbol, Date createDate) {
        this();
        this.id = id;
        this.symbol = symbol;
        this.createDate = createDate;
      }
    
      public Long getId() {
          return this.id;
      }
    
      public String getSymbol() {
          return this.symbol;
      }
    
      public Date getCreateDate() {
          return this.createDate;
      }
    
      public void setId(Long id) {
        this.id = id;
      }
    
      public void setSymbol(String symbol) {
          this.symbol = symbol;
      }
    }
    

    Modify Client Classes to Use StockClient[] instead of String[]

    Now we make some simple modifications to the client classes so that they know that the RPC call returns StockClient[] instead of String[].

    StockService.java:

    package com.google.gwt.sample.stockwatcher.client;
    
    import com.google.gwt.sample.stockwatcher.client.NotLoggedInException;
    import com.google.gwt.user.client.rpc.RemoteService;
    import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
    
    @RemoteServiceRelativePath("stock")
    public interface StockService extends RemoteService {
      public Long addStock(String symbol) throws NotLoggedInException;
      public void removeStock(String symbol) throws NotLoggedInException;
      public StockClient[] getStocks() throws NotLoggedInException;
    }
    

    StockServiceAsync.java:

    package com.google.gwt.sample.stockwatcher.client;
    
    import com.google.gwt.sample.stockwatcher.client.StockClient;
    import com.google.gwt.user.client.rpc.AsyncCallback;
    
    public interface StockServiceAsync {
      public void addStock(String symbol, AsyncCallback<Long> async);
      public void removeStock(String symbol, AsyncCallback<Void> async);
      public void getStocks(AsyncCallback<StockClient[]> async);
    }
    

    StockWatcher.java:

    Add one import:

    import com.google.gwt.sample.stockwatcher.client.StockClient;
    

    All other code stays the same, except addStock, loadStocks, and displayStocks:

    private void loadStocks() {
        stockService = GWT.create(StockService.class);
        stockService.getStocks(new AsyncCallback<String[]>() {
            public void onFailure(Throwable error) {
                handleError(error);
            }
    
            public void onSuccess(String[] symbols) {
                displayStocks(symbols);
            }
        });
    }
    
    private void displayStocks(String[] symbols) {
        for (String symbol : symbols) {
            displayStock(symbol);
        }
    }
    
    private void addStock() {
        final String symbol = newSymbolTextBox.getText().toUpperCase().trim();
        newSymbolTextBox.setFocus(true);
    
        // Stock code must be between 1 and 10 chars that are numbers, letters,
        // or dots.
        if (!symbol.matches("^[0-9a-zA-Z\\.]{1,10}$")) {
            Window.alert("'" + symbol + "' is not a valid symbol.");
            newSymbolTextBox.selectAll();
            return;
        }
    
        newSymbolTextBox.setText("");
    
        // Don't add the stock if it's already in the table.
        if (stocks.contains(symbol))
            return;
    
        addStock(new StockClient(symbol));
    }
    
    private void addStock(final StockClient stock) {
        stockService.addStock(stock.getSymbol(), new AsyncCallback<Long>() {
            public void onFailure(Throwable error) {
                handleError(error);
            }
    
            public void onSuccess(Long id) {
                stock.setId(id);
                displayStock(stock.getSymbol());
            }
        });
    }
    

    Modify the StockServiceImpl Class to Return StockClient[]

    Finally, we modify the getStocks method of the StockServiceImpl class so that it translates the server-side Stock classes into client-side StockClient classes before returning the array.

    StockServiceImpl.java

    import com.google.gwt.sample.stockwatcher.client.StockClient;
    

    We need to change the addStock method slightly so that the generated ID is returned:

    public Long addStock(String symbol) throws NotLoggedInException {
      Stock stock = new Stock(getUser(), symbol);
      checkLoggedIn();
      PersistenceManager pm = getPersistenceManager();
      try {
        pm.makePersistent(stock);
      } finally {
        pm.close();
      }
      return stock.getId();
    }
    

    All other methods stay the same, except getStocks:

    public StockClient[] getStocks() throws NotLoggedInException {
      checkLoggedIn();
      PersistenceManager pm = getPersistenceManager();
      List<StockClient> stockclients = new ArrayList<StockClient>();
      try {
        Query q = pm.newQuery(Stock.class, "user == u");
        q.declareParameters("com.google.appengine.api.users.User u");
        q.setOrdering("createDate");
        List<Stock> stocks = (List<Stock>) q.execute(getUser());
        for (Stock stock : stocks)
        {
           stockclients.add(new StockClient(stock.getId(), stock.getSymbol(), stock.getCreateDate()));
        }
      } finally {
        pm.close();
      }
      return (StockClient[]) stockclients.toArray(new StockClient[0]);
    }
    

    Summary

    The code above works perfectly for me when deployed to Google App Engine, but triggers an error in Google Web Toolkit Hosted Mode:

    SEVERE: [1244408678890000] javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
    com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract com.google.gwt.sample.stockwatcher.client.StockClient[] com.google.gwt.sample.stockwatcher.client.StockService.getStocks() throws com.google.gwt.sample.stockwatcher.client.NotLoggedInException' threw an unexpected exception: java.lang.NullPointerException: Name is null
    

    Let me know if you encounter the same problem or not. The fact that it works in Google App Engine seems to indicate a bug in Hosted Mode.

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

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why don't you set the cache directory to something a… May 12, 2026 at 8:21 pm
  • Editorial Team
    Editorial Team added an answer Find smallest and largest element in the list. The difference… May 12, 2026 at 8:21 pm
  • Editorial Team
    Editorial Team added an answer I use an alternative solution. MyView implements an interface IMyView… May 12, 2026 at 8:21 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.