Java &引用;此行有多个标记”;

Java &引用;此行有多个标记”;,java,gwt,Java,Gwt,我正在学习教程 当我试着运行它时,我得到了这个错误?:“这一行有多个标记”(我在下面那一行添加了一条注释) Javi您的错误列表没有多少沟通。它只是说“(挂起(StockWatcher中第67行的断点)),这就是手动停止进程。让if失败并粘贴它 在任何情况下,我看不出具体行中存在任何问题。有一件事可能会使编译器陷入混乱,那就是额外的(或{),否则,请尝试清理项目,擦除GWT生成的代码并重新生成。多个标记不算什么,但如果代码行有多个错误” 主要问题是,您试图将多个语句直接插入到类、构造函数、方法等

我正在学习教程

当我试着运行它时,我得到了这个错误?:“这一行有多个标记”(我在下面那一行添加了一条注释)


Javi

您的错误列表没有多少沟通。它只是说“(挂起(StockWatcher中第67行的断点)),这就是手动停止进程。让if失败并粘贴它


在任何情况下,我看不出具体行中存在任何问题。有一件事可能会使编译器陷入混乱,那就是额外的
{
),否则,请尝试清理项目,擦除GWT生成的代码并重新生成。

多个标记不算什么,但如果代码行有多个错误”


主要问题是,您试图将多个语句直接插入到类、构造函数、方法等中。

您使用的是Eclipse吗?如果是这样,“多个标记…”是Eclipse告诉您该行有多个错误的方式。请尝试刷新项目文件夹并进行构建-可能就是Eclipseing special。@mcfinnigan,是的,我正在使用Eclipse。我选择了项目,然后刷新了它,但错误是一样的……我想按照你说的那样构建它,但我找不到那个动作,我不确定这是否能解决我的问题,因为到目前为止,我还没有看到任何与构建Stockwatcher应用程序相关的想法…@mcfinnigan,我找到了build选项,但即使我从资源管理器中选择项目,它也不会处于活动状态"已激活。^B通常是Eclipse生成命令-否则,请在确保选中Project/build自动后选择Project/Clean。此外,打开窗口/Show View/Problems,您应该会在工作区中获得当前编译错误的列表。@mcfinnigan,我在“我的问题”窗口中没有看到任何内容。我的错误是显示的在显示视图/开发模式下进行编辑。
package com.google.gwt.sample.stockwatcher.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import java.util.ArrayList;

public class StockWatcher implements EntryPoint {

  private static final int REFRESH_INTERVAL = 5000;
  private VerticalPanel mainPanel = new VerticalPanel();
  private FlexTable stocksFlexTable = new FlexTable();
  private HorizontalPanel addPanel = new HorizontalPanel();
  private TextBox newSymbolTextBox = new TextBox();
  private Button addStockButton = new Button("Add");
  private Label lastUpdatedLabel = new Label();
  private ArrayList<String> stocks = new ArrayList<String>();

  /**
   * Entry point method.
   */
  public void onModuleLoad() {

    // Create table for stock data.
    stocksFlexTable.setText(0, 0, "Symbol");
    stocksFlexTable.setText(0, 1, "Price");
    stocksFlexTable.setText(0, 2, "Change");
    stocksFlexTable.setText(0, 3, "Remove");  

    // Assemble Add Stock panel.
    addPanel.add(newSymbolTextBox);
    addPanel.add(addStockButton);

    // Assemble Main panel.
    mainPanel.add(stocksFlexTable);
    mainPanel.add(addPanel);
    mainPanel.add(lastUpdatedLabel);

    // Associate the Main panel with the HTML host page.
    RootPanel.get("stockList").add(mainPanel);    

    // Move cursor focus to the input box.
    newSymbolTextBox.setFocus(true);

    // Setup timer to refresh list automatically.
    Timer refreshTimer = new Timer() {
      @Override
      public void run() {
        refreshWatchList();
      }

    };
    refreshTimer.scheduleRepeating(REFRESH_INTERVAL); //THIS IS THE LINE OF THE 

    // Listen for mouse events on the Add button.
    addStockButton.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        addStock();
      }
    });

    // Listen for keyboard events in the input box.
    newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
      public void onKeyPress(KeyPressEvent event) {
          System.out.println("foo=" + KeyCodes.KEY_ENTER);
          System.out.println("bar=" + (int)event.getCharCode());
        if (event.getCharCode() == KeyCodes.KEY_ENTER) {


          addStock();
        }
      }
    });

  }

  /**
   * Add stock to FlexTable. Executed when the user clicks the addStockButton or
   * presses enter in the newSymbolTextBox.
   */
  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-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;

    // Add the stock to the table.
    int row = stocksFlexTable.getRowCount();
    stocks.add(symbol);
    stocksFlexTable.setText(row, 0, symbol);

    // Add a button to remove this stock from the table.
    Button removeStockButton = new Button("x");
    removeStockButton.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        int removedIndex = stocks.indexOf(symbol);
        stocks.remove(removedIndex);        stocksFlexTable.removeRow(removedIndex + 1);
      }
    });
    stocksFlexTable.setWidget(row, 3, removeStockButton);

    // Get the stock price.
    refreshWatchList();

  }

  private void refreshWatchList() {
    final double MAX_PRICE = 100.0; // $100.00
    final double MAX_PRICE_CHANGE = 0.02; // +/- 2%

    StockPrice[] prices = new StockPrice[stocks.size()];
    for (int i = 0; i < stocks.size(); i++) {
      double price = Random.nextDouble() * MAX_PRICE;
      double change = price * MAX_PRICE_CHANGE
          * (Random.nextDouble() * 2.0 - 1.0);

      prices[i] = new StockPrice(stocks.get(i), price, change);
    }

    updateTable(prices);

  }

  /**
   * Update the Price and Change fields all the rows in the stock table.
   *
   * @param prices Stock data for all rows.
   */
  private void updateTable(StockPrice[] prices) {
    for (int i = 0; i < prices.length; i++) {
        updateTable(prices[i]);
      }
  }

  /**
   * Update a single row in the stock table.
   *
   * @param price Stock data for a single row.
   */
  private void updateTable(StockPrice price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
      return;
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(
        price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText
        + "%)");
  }

}
StockWatcher [Web Application]  
    com.google.gwt.dev.DevMode at localhost:56938   
        Thread [main] (Running) 
        Thread [Thread-1] (Running) 
        Daemon Thread [Thread-2] (Running)  
        Daemon Thread [UnitWriteThread] (Running)   
        Daemon Thread [Timer-0] (Running)   
        Daemon Thread [Code server listener] (Running)  
        Daemon Thread [com.google.gwt.thirdparty.guava.common.base.internal.Finalizer] (Running)    
        Thread [2048426764@qtp-774727454-1 - Acceptor0 SelectChannelConnector@0.0.0.0:8888] (Running)   
        Thread [2108438076@qtp-774727454-0] (Running)   
        Daemon Thread [Timer-1] (Running)   
        Daemon Thread [Code server for stockwatcher from Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 on http://127.0.0.1:8888/StockWatcher.html?gwt.codesvr=127.0.0.1:9997 @ 1hS?FL4(4E4"'T^J] (Suspended (breakpoint at line 67 in StockWatcher))   
            StockWatcher.onModuleLoad() line: 67    
            NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
            NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57  
            DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43  
            Method.invoke(Object, Object...) line: 601  
            ModuleSpaceOOPHM(ModuleSpace).onLoad(TreeLogger) line: 396  
            OophmSessionHandler.loadModule(BrowserChannelServer, String, String, String, String, String, byte[]) line: 200  
            BrowserChannelServer.processConnection() line: 525  
            BrowserChannelServer.run() line: 363    
            Thread.run() line: 722  
    /usr/lib/jdk1.7.0_01/bin/java (Nov 22, 2011 12:45:50 PM)