0

私のアプリでは、ファイルに文字列値を追加する必要があります(重要な場合は.propertyファイル)。ユーザーはこの値を gwt GUI に入力します。重要な部分は次のとおりです。

final Button submit = new Button("Submit");
        addButton(submit);
        submit.addSelectionListener(new SelectionListener<ButtonEvent>() {
            @Override
            public void componentSelected(ButtonEvent ce) {
                keyWord.selectAll();
                regexp.selectAll();
                if (keyWord.getValue() != null){
                    setKeyWord(customerId, keyWord.getValue());
                    keyWord.setValue("");
                }
                if (regexp.getValue() != null){
                    setRegExp(customerId, regexp.getValue());
                    regexp.setValue("");
                }

            }
        });
    }

    private void setKeyWord(final String customerId, final String keyword){

        final AsyncCallback<String> callbackItems = new AsyncCallback<String>() {
            public void onFailure(final Throwable caught) {
                Window.alert("unable to add " + caught.toString());
            }

            public void onSuccess(final String x) {
                Window.alert(x);
            }
        };
        serverManagementSvc.setKeyWords(customerId, keyword, callbackItems);
    }

    private void setRegExp(final String customerId, final String regexp){

        final AsyncCallback<String> calbackItems = new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable throwable) {
                Window.alert("unable to add " + throwable.toString());
            }

            @Override
            public void onSuccess(String s) {
                Window.alert(s);
            }
        };
        serverManagementSvc.setRegExp(customerId, regexp, calbackItems);
    }

したがって、「サーバー部分」にあるメソッドを呼び出すには、Asunccallback を使用する必要があります。これらの方法は次のとおりです。

//adds a new keyword to customers properties
    public String setKeyWords(String customer, String word){
        try{
                PropertiesConfiguration props = new PropertiesConfiguration("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties");
                String newKeyWord = new String(props.getString("users." + customer + ".keywords" + "," + word));
                props.setProperty("users." + customer + ".keywords", newKeyWord);
                props.save();
        }catch (ConfigurationException e){
            e.printStackTrace();
        }
        return "keyword " + word + " added";
    }

    // adds a new regexp to customer properties
    public String setRegExp(String customer, String regexp){
        try {
                PropertiesConfiguration props = new PropertiesConfiguration("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties");
                String newRegValue = new String(props.getString("users." + customer + ".regexps" + "," + regexp));
                props.setProperty("users." + customer + ".regexps", newRegValue);
                props.save();
        } catch (ConfigurationException e){
            e.printStackTrace();
        }
        return "regexp " + regexp + " added to " + customer + "'s config";
    }

すべてのインターフェイスが存在します。コードを実行してGUIで「送信」ボタンを押すと、両方のasynccallbackが失敗したことがわかります(ご覧のとおり、メソッドに送信する値がnullではないという事実にもかかわらず、Window.alertは「nullポインタ例外」を示しています) . なぜそれができるのですか?私に何か提案できますか?

ここでのUPDは、firebug によって表示されるエラーです。

uncaught exception: java.lang.ClassCastException    
function W8(){try{null.a()}catch(a){return a}} 
4

2 に答える 2