GWT Cannot compile the project

泪湿孤枕 提交于 2019-12-12 02:55:24

问题


I am creating simple twitter application with GWT+twitter4j. But I can't run this or compile it.

Here codes and please tell me what is wrong with it.

package in.isuru.twitter.server;

import java.util.ArrayList;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Tweet;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

public class Twit extends RemoteServiceServlet{

ArrayList<Tweet> tweets = new ArrayList<Tweet>();
//ArrayList<String> status = new ArrayList<String>();

public ArrayList<Tweet> search(String searchTerm){
    // The factory instance is re-useable and thread safe.
    Twitter twitter = new TwitterFactory().getInstance();
    Query query = new Query(searchTerm);
    QueryResult result = null;
    try {
        result = twitter.search(query);
    } catch (TwitterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    for (Tweet tweet : result.getTweets()) {
        //System.out.println(tweet.getFromUser() + ":" + tweet.getText());
        tweets.add(tweet);

    }

    return tweets;
}

}

And client side,

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.RootPanel;

import in.isuru.twitter.server.*;

/**
  * Entry point classes define <code>onModuleLoad()</code>.
 */
 public class Twitter implements EntryPoint {

Twit twit = new Twit();
ArrayList<Tweet> allStatus;

public void onModuleLoad() {

     // Create a Flex Table
    final FlexTable flexTable = new FlexTable();
    FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
    flexTable.addStyleName("cw-FlexTable");
    flexTable.setWidth("32em");
    flexTable.setCellSpacing(5);
    flexTable.setCellPadding(3);

    // Add some text
    cellFormatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
    cellFormatter.setColSpan(0, 0, 2);

    //search in twitter
    allStatus = twit.search("sex");
    for (int i=0 ; i <allStatus.size() ; i++) {
        //System.out.println(tweet.getFromUser() + ":" + tweet.getText());
        Tweet tweet = allStatus.get(i);
        String user = tweet.getFromUser();
        String status = tweet.getText();
        addRow(flexTable, user);
        addRow(flexTable, status);

    }

    // Add two rows to start
    // addRow(flexTable, "This is testing status update");
    // addRow(flexTable, "This is testing status update");

    // Return the panel
    flexTable.ensureDebugId("cwFlexTable");
    RootPanel.get().add(flexTable);
  }

  /**
   * Add a row to the flex table.
   */
  private void addRow(FlexTable flexTable, String status) {
    int numRows = flexTable.getRowCount();
    flexTable.setText(numRows, 0, status);
    flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
  }

  /**
   * Remove a row from the flex table.
   */
  private void removeRow(FlexTable flexTable) {
    int numRows = flexTable.getRowCount();
    if (numRows > 1) {
      flexTable.removeRow(numRows - 1);
      flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows - 1);
    }

}
}

And here is the error code which i get when i compile it.

Compiling module in.isuru.twitter.Twitter Validating newly compiled units Ignored 1 unit with compilation errors in first pass. Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors. Finding entry point classes [ERROR] Errors in 'file:/E:/workspace/Twitter/src/in/isuru/twitter/client/Twitter.java' [ERROR] Line 20: No source code is available for type in.isuru.twitter.server.Twit; did you forget to inherit a required module? [ERROR] Line 21: No source code is available for type twitter4j.Tweet; did you forget to inherit a required module? [ERROR] Unable to find type 'in.isuru.twitter.client.Twitter' [ERROR] Hint: Previous compiler errors may have made this type unavailable [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

Thanks in advance!


回答1:


[ERROR] Line 20: No source code is available for type in.isuru.twitter.server.Twit;

That is your problem - from the package, you have declared that Twit is a server object, and so the GWT compiler has not made it available to be compiled on the client.

It looks like you are attempting to directly call the server class Twit instead of calling it asynchronously - take another look at the RPC documentation to create the remote service, and how to make async calls to it. http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html




回答2:


You can't use just any java library in GWT. GWT is not java, and libraries have to be created and configured in special way, that's why you are getting this error.

I recommend to read official documentation



来源:https://stackoverflow.com/questions/9117072/gwt-cannot-compile-the-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!