2011-11-09 3 views
0

내 코드가 업데이트되었습니다.GWT + MySQL 웹 응용 프로그램 : 컴파일 오류

In recall, I'm making a GWT+MySQL web application. I tried to modified a code from internet. Wen I run my project as a Web application (Debug As mode), I'm having the following compilation errors: 

[ERROR] [deuxiemeapplicationgwt] - Unable to load module entry point class com.essai.client.DeuxiemeApplicationGwt (see associated exception for details) 

[ERROR] [deuxiemeapplicationgwt] - Failed to load module 'deuxiemeapplicationgwt' from user agent 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.23) Gecko/20110920 Firefox/3.6.23' at 127.0.0.1:60265 

    onModuleLoad() threw an exception 

    Exception while loading module com.essai.client.DeuxiemeApplicationGwt. See Development Mode for details. 
    java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:88) at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:97) at com.google.gwt.user.client.ui.Panel.add(Panel.java:71) at com.essai.client.DeuxiemeApplicationGwt.onModuleLoad(DeuxiemeApplicationGwt.java:28) ... 9 more 

또한 업데이트 된 HVE 파일의 코드는 여기에 있습니다 :

============================ ======================

package com.essai.client; 

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

import com.essai.client.User; 
import java.io.Serializable; 

public interface ConnexionBD extends RemoteService 
{ 
    public User authenticateUser(String user, String motDePasse); 
} 

================================================== 

package com.essai.client; 

import com.essai.client.User; 

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

public interface ConnexionBDAsync { 

    public void authenticateUser(String User, String motDePasse, 
      AsyncCallback<User> callback); 
} 

===================== =============================

//EntryPoint file 

package com.essai.client; 

import com.essai.client.User; 

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.rpc.ServiceDefTarget; 
import com.google.gwt.user.client.ui.*; 

public class DeuxiemeApplicationGwt implements EntryPoint, ClickListener, IsWidget { 
private ConnexionBDAsync rpc; 
private TextBox usernameBox; 
private TextBox passwordBox; 
private Button OK; 
public DeuxiemeApplicationGwt() { 
rpc = (ConnexionBDAsync) GWT.create(ConnexionBD.class); 
ServiceDefTarget target = (ServiceDefTarget) rpc; 
// The path 'MySQLConnection' is determined in ./public/LoginScreen.gwt.xml 
// This path directs Tomcat to listen for this context on the server side, 
// thus intercepting the rpc requests. 
String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection"; 
target.setServiceEntryPoint(moduleRelativeURL); 
initGUI(); 
} 
public void onModuleLoad() { 
RootPanel.get().add(this); 
} 

private void initGUI() { 
Grid g = new Grid(3, 2); 
usernameBox = new TextBox(); 
passwordBox = new TextBox(); 
OK = new Button("OK"); 
g.setWidget(0, 0, new Label("Username: ")); 
g.setWidget(0, 1, usernameBox); 
g.setWidget(1, 0, new Label("Password: ")); 
g.setWidget(1, 1, passwordBox); 
g.setWidget(2, 1, OK); 
} 
public void onClick(Widget sender) { 

if (sender.equals(OK)) { 
AsyncCallback<User> callback = new AuthenticationHandler<User>(); 
rpc.authenticateUser(usernameBox.getText(),passwordBox.getText(), 
callback); 
} 
} 
private class AuthenticationHandler<T> implements AsyncCallback<User> { 
public void onFailure(Throwable ex) { 
RootPanel.get().add(new HTML("RPC call failed. :-(")); 
} 
public void onSuccess(User result) { 
//do stuff on success with GUI, like load the next GUI element 
} 
} 
@Override 
public Widget asWidget() { 
    // TODO Auto-generated method stub 
    return null; 
} 
} 

============== ======================

//ConnexionMySQL.java 

package com.essai.server; 

import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.Vector; 

import com.google.gwt.user.server.rpc.RemoteServiceServlet; 
import com.essai.client.User; 
import com.essai.client.ConnexionBD; 

public class ConnexionMySQL extends RemoteServiceServlet implements ConnexionBD 
{ 
    private Connection conn = null; 
    private String status; 
    private String url = "jdbc:mysql://localhost/gestionpatients"; 
    private String utilisateurBD = "root"; 
    private String motDePasseBD = ""; 

    public ConnexionMySQL() 
    { 
    try 
    { 
     Class.forName("com.mysql.jdbc.Driver").newInstance(); 
     conn = DriverManager.getConnection(url, utilisateurBD, motDePasseBD); 
    } 
    catch (Exception e) 
    { 

    } 
} 

public User authenticateUser(String user, String motDePasse) 
{ 
    User utilisateur = null; 
    try 
    { 
     PreparedStatement ps = conn.prepareStatement(
       "select readonly * from docteurs where Noms = \"\" + user + \"\" AND " + "ID = \"\" + pass + \"\"" 
       ); 
     ResultSet result = ps.executeQuery(); 
     while (result.next()) 
     { 
      utilisateur = new User(result.getString(1), result.getString(2)); 
     } 
     result.close(); 
     ps.close(); 
     } 
     catch (SQLException sqle) 
     { 
      //Comportement en cas d'erreur 
     } 
     return utilisateur; 
    } 
} 

=========================================== =======

//User.java: user configuration 

package com.essai.client; 

import com.google.gwt.user.client.rpc.IsSerializable; 
//import java.io.Serializable; 

public class User implements IsSerializable 
{ 
    private String nomUtilisateur; 
    private String motDePasse; 
    @SuppressWarnings("unused") 
    private User() {} 

    public User(String user, String motDePasse) 
    { 
     this.nomUtilisateur = user; 
     this.motDePasse = motDePasse; 
    } 
} 

==================================== ==============

//XML file 

<?xml version="1.0" encoding="UTF-8"?> 
<module rename-to='deuxiemeapplicationgwt'> 
    <!-- 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="com.essai.client.DeuxiemeApplicationGwt"/> 

    <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"/> 

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

============================= =======================

프로젝트 구조는 여기에서 볼 수 있습니다 : http://tonguim.free.fr/divers/imgGWTtomcat.jpg

도움 주셔서 감사합니다.

+0

왜 XML 파일에'org.apache.catalina.User'에'inherit' 행이 없습니까? 당신은 다른 패키지를 사용하고 있습니다. – sarnold

+0

안녕하세요. org.apache.catalina.User에 대한 행을 추가했지만 아무 것도 변경하지 않았습니다. – cProg

답변

2

RootPanel.get().add(this)onModuleLoad()에 기입하고 asWidget()을 반환하는 것은 null입니다. 이는 RootPanel.get().add(null)과 동일합니다. 그것이 onModuleLoad에 던져지고있는 NullPointerException의 원인입니다. 아니면 정확히 child.removeFromParent();의 줄이 ComplexPanel.add(Widget, Element) 인 경우 예외가 발생합니다.

간략한 설명으로 asWidget()null이 아닌 다른 것을 반환합니다. 예를 들어, initGui()에 생성 한 눈금을 클래스 멤버로 만들어 반환하십시오. 현재 양식에서는 initGui이 어쨌든 GUI를 작성하지 않습니다.

EDIT 편집 코드가 보이지만 실제로 GWT를 이해하지 못하는 것 같습니다. 에 null을 추가하는 것 외에 Grid은 어디에도 첨부되어 있지 않습니다. 또한 ClickListener을 구현하지만 실제로는이 리스너를 연결하여 실제로 이벤트를 수신하지 않습니다. 이것이 전체 코드 (가독성을 위해 제거되지 않은 것) 인 경우 먼저 gwt docs을 먼저 읽는 것이 좋습니다.