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 8446337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:54:17+00:00 2026-06-10T09:54:17+00:00

I’m playing around with this Google Web toolkit/GSON example that gets data from twitter.

  • 0

I’m playing around with this Google Web toolkit/GSON example that gets data from twitter.

Everything is compiling just fine, but when I debug as Web Application, everything loads just fine, but when I click the "search" button I get the following error:

>SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List com.google.gwt.twittersearch.client.TwitterService.searchTweets(java.lang.String) throws java.io.IOException,java.lang.IllegalArgumentException' threw an unexpected exception: java.lang.RuntimeException: Unable to invoke no-args constructor for class com.google.gwt.twittersearch.server.TwitterServiceImpl$SearchResponse. Register an InstanceCreator with Gson for this type may fix this problem.
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:370)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.RuntimeException: Unable to invoke no-args constructor for class com.google.gwt.twittersearch.server.TwitterServiceImpl$SearchResponse. Register an InstanceCreator with Gson for this type may fix this problem.
    at com.google.gson.internal.ConstructorConstructor$8.construct(ConstructorConstructor.java:167)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162)
    at com.google.gson.Gson.fromJson(Gson.java:795)
    at com.google.gson.Gson.fromJson(Gson.java:734)
    at com.google.gwt.twittersearch.server.TwitterServiceImpl.parseSearchResponse(TwitterServiceImpl.java:80)
    at com.google.gwt.twittersearch.server.TwitterServiceImpl.searchTweets(TwitterServiceImpl.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
    ... 34 more
Caused by: java.lang.UnsupportedOperationException: Cannot allocate class com.google.gwt.twittersearch.server.TwitterServiceImpl$SearchResponse
    at com.google.gson.internal.UnsafeAllocator$4.newInstance(UnsafeAllocator.java:100)
    at com.google.gson.internal.ConstructorConstructor$8.construct(ConstructorConstructor.java:164)
    ... 45 more

Here is the TwitterServiceImpl code:

package com.google.gwt.twittersearch.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.List;

import com.google.gwt.twittersearch.client.Tweet;
import com.google.gwt.twittersearch.client.TwitterService;
import com.google.gson.Gson;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial") 
public class TwitterServiceImpl extends RemoteServiceServlet implements
        TwitterService {

    @Override
    public List<Tweet> searchTweets(String query) throws IllegalArgumentException, IOException {
          query = query.trim();
          if (query.isEmpty()) {
            throw new IllegalArgumentException("No search query specified.");
          }
         
          // see: https://dev.twitter.com/docs/api/1/get/search
          String q = URLEncoder.encode(query, "UTF-8");
          URL url = new URL("http://search.twitter.com/search.json?q=" + q);
          HttpURLConnection connection = (HttpURLConnection) url.openConnection();
          InputStream response = null;
          try {
            response = connection.getInputStream();
            return parseSearchResponse(response);
          } finally {
            if (response != null) {
              response.close();
            }
          }
    }
    
    @Override
    public String getPrivacyPolicy() throws IOException {
        // see: https://dev.twitter.com/docs/api/1/get/legal/privacy
        URL url = new URL("https://api.twitter.com/1/legal/privacy.json");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        InputStream response = null;
        try {
            response = connection.getInputStream();
            return parsePolicyResponse(response);
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     * Parses the privacy policy response returned from the Twitter API.
     * @param response the response
     * @return the privacy policy
     * @throws IOException if there was a problem reading the response
     */
    private String parsePolicyResponse(InputStream response) throws IOException {
        Reader reader = new InputStreamReader(response);
        PrivacyPolicyResponse privacyPolicyResponse = new Gson().fromJson(reader, PrivacyPolicyResponse.class);
        return privacyPolicyResponse.privacy;
    }

    /**
     * Parses the search response returned from the Twitter API.
     * @param response the response
     * @return the search results
     * @throws IOException if there was a problem reading the response
     */

    private List<Tweet> parseSearchResponse(InputStream response) throws IOException {
          Reader reader = new InputStreamReader(response);
          SearchResponse searchResponse = new Gson().fromJson(reader, SearchResponse.class);
          return searchResponse.results;
        }
    
    private class PrivacyPolicyResponse {
    public String privacy;
    }

     
    private class SearchResponse {
      public List<Tweet> results;
    }
}

Here is the entry point code:

package com.google.gwt.twittersearch.client;

import java.util.List;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TwitterSearch implements EntryPoint {
  private Button privacyPolicyButton;
  private Button searchButton;
  private TextBox searchQueryTextBox;
  private Panel resultsPanel;
  private Label errorLabel;
  private Image loadingImage;
  private final TwitterServiceAsync service = GWT.create(TwitterService.class);

/**
 * This is the entry point method.
 */
public void onModuleLoad() {
    createWidgets();
    layoutWidgets();
    
}

private void createWidgets() {
    searchQueryTextBox = new TextBox();

    searchButton = new Button("Search");
    searchButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            setLoading(true);
            String query = searchQueryTextBox.getText();
            service.searchTweets(query, new AsyncCallback<List<Tweet>>() {
                @Override
                public void onFailure(Throwable caught) {
                    errorLabel.setText(caught.getMessage());
                    errorLabel.setVisible(true);
                    setLoading(false);
                }

                @Override
                public void onSuccess(List<Tweet> result) {
                    resultsPanel.clear();
                    for (Tweet tweet : result) {
                        SafeHtmlBuilder builder = new SafeHtmlBuilder();
                        builder.appendHtmlConstant("<b>User: </b>");
                        builder.appendEscaped(tweet.getFrom_user());
                        builder.appendHtmlConstant("<br /><b>Created: </b>");
                        builder.appendEscaped(tweet.getCreated_at());
                        builder.appendHtmlConstant("<br /><b>Tweet: </b>");
                        builder.appendEscaped(tweet.getText());
                        builder.appendHtmlConstant("<br /><br />");
                        resultsPanel.add(new HTML(builder.toSafeHtml()));
                    }
                    setLoading(false);
                }
            });
        }
    });

    privacyPolicyButton = new Button("Privacy Policy");
    privacyPolicyButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            setLoading(true);
            service.getPrivacyPolicy(new AsyncCallback<String>() {
                @Override
                public void onFailure(Throwable caught) {
                    errorLabel.setText(caught.getMessage());
                    errorLabel.setVisible(true);
                    setLoading(false);
                }

                @Override
                public void onSuccess(String result) {
                    resultsPanel.clear();

                    // convert newlines to <br />
                    SafeHtmlBuilder builder = new SafeHtmlBuilder();
                    builder.appendEscapedLines(result);

                    resultsPanel.add(new HTML(builder.toSafeHtml()));

                    setLoading(false);
                }
            });
        }
    });

    resultsPanel = new VerticalPanel();

    errorLabel = new Label();
    errorLabel.addStyleName("errorLabel");
    errorLabel.setVisible(false);

    //image from http://loadinfo.net/
    loadingImage = new Image("loading.gif");
    loadingImage.setVisible(false);
}

private void layoutWidgets() {
    Panel panel = new VerticalPanel();

    panel.add(errorLabel);

    Panel horizPanel = new HorizontalPanel();
    horizPanel.add(searchQueryTextBox);
    horizPanel.add(searchButton);
    horizPanel.add(privacyPolicyButton);
    horizPanel.add(loadingImage);
    panel.add(horizPanel);

    panel.add(resultsPanel);

    RootPanel.get().add(panel);
}

/**
 * Updates the UI for when a RPC call is made.
 * @param loading true if an RPC call is being sent, false if not
 */
private void setLoading(boolean loading) {
    if (loading) {
        errorLabel.setVisible(false);
    }
    searchQueryTextBox.setEnabled(!loading);
    searchButton.setEnabled(!loading);
    privacyPolicyButton.setEnabled(!loading);
    loadingImage.setVisible(loading);
}
}

Here is the tweet code:

package com.google.gwt.twittersearch.client;

import java.io.Serializable;

@SuppressWarnings("serial")
public class Tweet implements Serializable{
private String id;
  private String from_user;
  private String created_at;
  private String text;
 
  public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFrom_user() {
        return from_user;
    }

    public void setFrom_user(String from_user) {
        this.from_user = from_user;
    }

    public String getCreated_at() {
        return created_at;
    }

    public void setCreated_at(String created_at) {
        this.created_at = created_at;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }


}

Any insight into this error or where I might go from here would be greatly appreciated!

  • 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-10T09:54:19+00:00Added an answer on June 10, 2026 at 9:54 am

    You need to add a no-args constructor such as:

    public class Tweet implements Serializable{
    
      public Tweet(){
      }
    
    }
    

    EDIT

    You will also need one here too

    private class SearchResponse {
    
      public SearchResponse(){
      }
      public List<Tweet> results;
    }
    

    to deal with your error java.lang.RuntimeException: Unable to invoke no-args constructor for class

    A user defined class is serializable if:

    1. the class is assignable to IsSerializable or java.io.Serializable, either because it implements one of these interfaces, or because it is derived from a superclass that implements one of these interfaces.

    2. all the class’s non-final, non-transient instance fields are serializable

    3. the class has a public default (zero argument) constructor

    above is from this tutorial

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.