我是新來vaadin我編2碼之一是越來越例子vaadin錯誤
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
@SuppressWarnings("serial")
public class HelloWorld extends com.vaadin.Application {
/**
* Init is invoked on application load (when a user accesses the application
* for the first time).
*/
@Override
public void init() {
// Main window is the primary browser window
final Window main = new Window("Hello window");
setMainWindow(main);
// "Hello world" text is added to window as a Label component
main.addComponent(new Label("Hello World!"));
}
}
它編譯和工作正常,另一個是
import com.vaadin.terminal.ExternalResource;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
public class MenuApplication extends VerticalLayout {
private MenuBar menubar = new MenuBar();
public MenuApplication() {
// Save reference to individual items so we can add sub-menu items to
// them
final MenuBar.MenuItem file = menubar.addItem("File", null);
final MenuBar.MenuItem newItem = file.addItem("New", null);
file.addItem("Open file...", menuCommand);
file.addSeparator();
newItem.addItem("File", menuCommand);
newItem.addItem("Folder", menuCommand);
newItem.addItem("Project...", menuCommand);
file.addItem("Close", menuCommand);
file.addItem("Close All", menuCommand);
file.addSeparator();
file.addItem("Save", menuCommand);
file.addItem("Save As...", menuCommand);
file.addItem("Save All", menuCommand);
final MenuBar.MenuItem edit = menubar.addItem("Edit", null);
edit.addItem("Undo", menuCommand);
edit.addItem("Redo", menuCommand).setEnabled(false);
edit.addSeparator();
edit.addItem("Cut", menuCommand);
edit.addItem("Copy", menuCommand);
edit.addItem("Paste", menuCommand);
edit.addSeparator();
final MenuBar.MenuItem find = edit.addItem("Find/Replace", menuCommand);
// Actions can be added inline as well, of course
find.addItem("Google Search", new Command() {
public void menuSelected(MenuItem selectedItem) {
getWindow().open(new ExternalResource("http://www.google.com"));
}
});
find.addSeparator();
find.addItem("Find/Replace...", menuCommand);
find.addItem("Find Next", menuCommand);
find.addItem("Find Previous", menuCommand);
final MenuBar.MenuItem view = menubar.addItem("View", null);
view.addItem("Show/Hide Status Bar", menuCommand);
view.addItem("Customize Toolbar...", menuCommand);
view.addSeparator();
view.addItem("Actual Size", menuCommand);
view.addItem("Zoom In", menuCommand);
view.addItem("Zoom Out", menuCommand);
addComponent(menubar);
}
private Command menuCommand = new Command() {
public void menuSelected(MenuItem selectedItem) {
getWindow().showNotification("Action " + selectedItem.getText());
}
};
它獲得誤差
javax.servlet.ServletException: java.lang.ClassCastException: com.example.menu.MenuApplication cannot be cast to com.vaadin.Application
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.handleServiceException(AbstractApplicationServlet.java:966)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:523)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.ClassCastException: com.example.menu.MenuApplication cannot be cast to com.vaadin.Application
com.vaadin.terminal.gwt.server.ApplicationServlet.getNewApplication(ApplicationServlet.java:82)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.createApplication(AbstractApplicationServlet.java:940)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.findApplicationInstance(AbstractApplicationServlet.java:768)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:431)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
我正在使用tomcat和eclipse進行我的開發......任何人都可以告訴我yi cam得到這個錯誤
'com.example.menu.MenuApplication不能轉換爲com.vaadin.Application' - 看起來您正在嘗試執行非法類型轉換。 – 2010-10-20 16:37:07