2010-09-03 58 views
1

我有以下代碼GWT實現

package org.david.client; 
import com.google.gwt.core.client.EntryPoint; 
import com.google.gwt.event.logical.shared.BeforeSelectionEvent; 
import com.google.gwt.event.logical.shared.BeforeSelectionHandler; 
import com.google.gwt.event.logical.shared.SelectionEvent; 
import com.google.gwt.event.logical.shared.SelectionHandler; 
import com.google.gwt.user.client.Window; 
import com.google.gwt.user.client.ui.TabBar; 
public class TabBar1 implements EntryPoint{ 
    @Override 
    public void onModuleLoad(){ 
     TabBar bar=new TabBar(); 
     bar.addTab("foo"); 
     bar.addTab("bar"); 
     bar.addTab("baz"); 
     bar.addSelectionHandler(new SelectionHandler(){ 

      public void onSelection(SelectionEvent event){ 
       //let user know what you just did 
       Window.alert("you clicked tab"+event.getSelectedItem()); 
      } 

     }); 
     // Just for fun, let's disallow selection of 'bar'. 
     bar.addBeforeSelectionHandler(new BeforeSelectionHandler() { 
      public void onBeforeSelection(BeforeSelectionEvent event) { 
     if (event.getItem().intValue() == 1) { 
      event.cancel(); 
       } 
      } 


     }); 

    } 
} 

,但我有以下錯誤

ompiling 1 source file to C:\XAMPP\xampp\htdocs\TabBar1\build\web\WEB-INF\classes 
C:\XAMPP\xampp\htdocs\TabBar1\src\java\org\david\client\TabBar1.java:28: cannot find symbol 
symbol : method intValue() 
location: class java.lang.Object 
     if (event.getItem().intValue() == 1) { 
Note: C:\XAMPP\xampp\htdocs\TabBar1\src\java\org\david\client\TabBar1.java uses unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details. 
1 error 
C:\XAMPP\xampp\htdocs\TabBar1\nbproject\build-impl.xml:518: The following error occurred while executing this line: 
C:\XAMPP\xampp\htdocs\TabBar1\nbproject\build-impl.xml:248: Compile failed; see the compiler error output for details. 
BUILD FAILED (total time: 0 seconds) 

請幫助

+0

這是一個Java錯誤,告訴你它找不到方法intValue(),也許你忘了做一個演員? – pathed 2010-09-03 14:24:28

回答

4

BeforeSelectionEvent應該BeforeSelectionEvent<Integer>使getItem()返回Integer,而不是一個Object

Object沒有intValue()方法,Integer沒有。

您應該在編譯時也看到一個未經檢查的轉換警告,並說明了這種情況。