2017-09-14 70 views
-1

我有一個錯誤在編譯如下代碼:我想這有一個具有String沒有構造爲XmlRpcClientXmlRpcClient着分配URL地址

import java.util.*; 
import org.apache.xmlrpc.client.*; 
import org.apache.xmlrpc.common.*; 
import org.apache.xmlrpc.*; 
public class pms { 
    public static void main (String [] args) { 
     String UserName = "123"; 
     String Password = "123"; 
     String pKey  = "123"; 
     XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2"); //("http://localhost/RPC2"); 
     Vector params = new Vector(); 
     try { 
     params.addElement(new Integer(17)); 
     params.addElement(new Integer(13)); 
     Object result = server.execute("acquire_token",params); 
     int sum = ((Integer) result).intValue(); 
     System.out.println("The sum is: "+ sum); 
     } catch (Exception exception) { 
     System.err.println("JavaClient: " + exception); 
     } 
     System.out.println("Hello World"); 
    } 

} 
+1

能否請你在職位說明中添加錯誤堆棧跟蹤? – tmarwen

回答

0

的編譯錯誤應該聲明,如下東西:

XmlRpcClient()中XmlRpcClient不能被應用到(java.lang.String中)

實際上,XmlRpcClient類僅聲明瞭一個默認無參數構造函數,您應該使用它來創建新實例。

服務器URL配置可以利用XmlRpcClientConfigImpl創建:

import java.util.*; 
import org.apache.xmlrpc.client.*; 
import org.apache.xmlrpc.common.*; 
import org.apache.xmlrpc.*; 

public class pms { 
    public static void main (String [] args) { 
     String UserName = "123"; 
     String Password = "123"; 
     String pKey  = "123"; 

     // create a configuration instance with the requested URL 
     XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); 
config.setServerURL(new URL("http://localhost/RPC2")); 

     // create the client and configure it with instantiated configuration 
     XmlRpcClient server = new XmlRpcClient(); 
     server.setConfig(config); 

     Vector params = new Vector(); 
     try { 
     params.addElement(new Integer(17)); 
     params.addElement(new Integer(13)); 
     Object result = server.execute("acquire_token",params); 
     int sum = ((Integer) result).intValue(); 
     System.out.println("The sum is: "+ sum); 
     } catch (Exception exception) { 
     System.err.println("JavaClient: " + exception); 
     } 
     System.out.println("Hello World"); 
    } 

} 
0

錯誤再次

pms.java:22: error: cannot find symbol 
       server.setconfig(config); 
        ^
    symbol: method setconfig(XmlRpcClientConfigImpl) 
    location: variable server of type XmlRpcClient 
Note: pms.java uses unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details.