GWT RPC无法编译项目

时间:2012-02-03 00:47:48

标签: gwt gwt-rpc twitter4j

这个问题是前一个问题的延伸。 GWT Cannot compile the project

请看一看并告诉我它有什么问题。

客户端。

Twitter.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
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;

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


private final TwitterServiceAsync searchService = GWT.create(TwitterService.class);

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);

    searchService.search("love", new AsyncCallback<ArrayList<Tweet>>() {

        @Override
        public void onFailure(Throwable caught) {
            //Not yet completed.

        }

        @Override
        public void onSuccess(ArrayList<Tweet> result) {
            for (int i=0 ; i <result.size() ; i++) {
                Tweet tweet = result.get(i);
                String user = tweet.getFromUser();
                String status = tweet.getText();
                addRow(flexTable, user);
                addRow(flexTable, status);

        }


    }});


    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);
    }

}
}

TwitterService.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("search")
 public interface TwitterService extends RemoteService {
ArrayList<Tweet> search(String searchTerm) throws IllegalArgumentException;
}

TwitterServiceAsync.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface TwitterServiceAsync {

void search(String searchTerm, AsyncCallback<ArrayList<Tweet>> callback) throws llegalArgumentException;
}

服务器端

package in.isuru.twitter.server;

import java.util.ArrayList;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Tweet;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import in.isuru.twitter.client.TwitterService;

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

public class TwitterServiceImpl extends RemoteServiceServlet implements TwitterService {

/**
 * 
 */
private static final long serialVersionUID = 1L;

ArrayList<Tweet> tweets = new ArrayList<Tweet>();

@Override
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) {
        e.printStackTrace();
    }
    for (Tweet tweet : result.getTweets()) {
        //System.out.println(tweet.getFromUser() + ":" + tweet.getText());
        tweets.add(tweet);

    }

    return tweets;
}

 }

Twitter.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='twitter'>
 <!-- Inherit the core Web Toolkit stuff.                        -->
 <inherits name='com.google.gwt.user.User'/>

 <!-- Inherit the default GWT style sheet.  You can change       -->
 <!-- the theme of your GWT application by uncommenting          -->
 <!-- any one of the following lines.                            -->
 <inherits name='com.google.gwt.user.theme.clean.Clean'/>
 <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
 <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
 <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->


 <!-- Other module inherits                                      -->

 <!-- Specify the app entry point class.                         -->
 <entry-point class='in.isuru.twitter.client.Twitter'/>

 <!-- Specify the paths for translatable code                    -->
 <source path='client'/>
<source path='shared'/>

</module>

错误是

  

[DEBUG] [twitter] - 验证新编译的单位[TRACE] [twitter]
   - 查找入口点类[错误] [twitter] - &#39;文件中的错误:/ E:/workspace/Twitter/src/in/isuru/twitter/client/Twitter.java'
        [错误] [twitter] - 第43行:类型
没有源代码可用   twitter4j.Tweet;你忘了继承一个必需的模块吗? [ERROR]
  [twitter] - 中的错误   &#39;文件:/ E:/workspace/Twitter/src/in/isuru/twitter/client/TwitterServiceAsync.java'
        [错误] [twitter] - 第11行:类型
没有源代码可用   twitter4j.Tweet;你忘了继承一个必需的模块吗? [ERROR]
  [twitter] - 无法找到类型&#39; in.isuru.twitter.client.Twitter&#39;
        [错误] [twitter] - 提示:以前的编译器错误可能已经发生了   此类型不可用[错误] [推特] - 提示:检查
  来自模块的继承链;它可能不会继承一个   所需模块或模块可能没有添加其源路径条目
  正确[错误] [推特] - 无法加载模块&#39; twitter&#39;来自用户
  代理&#39; Mozilla / 5.0(Windows NT 6.1)AppleWebKit / 535.7(KHTML,如

  Gecko)Chrome / 16.0.912.77 Safari / 535.7&#39;在127.0.0.1:7901

1 个答案:

答案 0 :(得分:0)

twitter4j.Tweet不能在客户端代码中使用,因为它不包含在任何继承的GWT模块中。您需要创建自己的传输对象类,例如TweetDTOclient包中的shared。只应在接口TwitterServiceAsyncTwitterService中使用此对象。然后在您的servlet中,创建TweetDTOTweetTweetDTO复制所需的值,然后返回TweetDTO列表。