GWT 无法编译项目

发布于 2025-01-02 15:56:49 字数 4000 浏览 1 评论 0原文

我正在使用 GWT+twitter4j 创建简单的 Twitter 应用程序。但我无法运行它或编译它。

这里的代码,请告诉我它有什么问题。

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

}

在客户端,

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

}
}

这是我编译时得到的错误代码。

在.isuru.twitter.Twitter 中编译模块 验证新编译的单元 在第一遍中忽略了 1 个有编译错误的单元。 使用 -strict 或 -logLevel 设置为 TRACE 或 DEBUG 进行编译以查看所有错误。 寻找入口点类 [错误]“文件:/E:/workspace/Twitter/src/in/isuru/twitter/client/Twitter.java”中的错误 [错误] 第 20 行:没有可用于 in.isuru.twitter.server.Twit 类型的源代码;您是否忘记继承所需的模块? [错误] 第 21 行:没有可用于 twitter4j.Tweet 类型的源代码;您是否忘记继承所需的模块? [错误] 无法找到类型“in.isuru.twitter.client.Twitter” [错误]提示:以前的编译器错误可能导致此类型不可用 [错误]提示:检查模块的继承链;它可能没有继承所需的模块,或者模块可能没有正确添加其源路径条目

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别低头,皇冠会掉 2025-01-09 15:56:49

[错误]第 20 行:没有可用于 in.isuru.twitter.server.Twit 类型的源代码;

这是你的问题 - 从包中,你已经声明 Twit 是一个服务器对象,因此 GWT 编译器尚未使其可在客户端上进行编译。

看起来您正在尝试直接调用服务器类 Twit,而不是异步调用它 - 再看一下 RPC 文档来创建远程服务,以及如何对其进行异步调用。 http://code.google.com/webtoolkit/doc/latest/tutorial /RPC.html

[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

帅气称霸 2025-01-09 15:56:49

您不能只使用 GWT 中的任何 Java 库。 GWT 不是 java,必须以特殊方式创建和配置库,这就是您收到此错误的原因。

我建议阅读官方文档

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文