2011-10-28 2 views
2

.Net 웹 서비스를 호출하기위한 샘플 응용 프로그램을 개발 중입니다. Eclipse의 빌드 경로에 ksoap2-j2me-core-prev-2.1.2.jar를 추가했습니다."메서드는 인수에 적용되지 않습니다."BlackBerry 응용 프로그램을 만들 때

내가 addProperty를 통해 두 개의 값을 전달하고있다 :

The method addProperty(String, Object) in the type SoapObject is not applicable for the arguments (String, int)

내가 할 수있는 오류를 해결하는 방법과 어떻게 : "번호 1"과 정수 (10), 또한 "번호 2"와 (20)이 컴파일러 오류가 발생합니다 addProperty에 하나의 문자열과 하나의 int 값을 전달합니까? 나는 안드로이드에서 같은 방식으로이 작업을 수행했으며 잘 작동한다.

String serviceUrl = "URL to webservice"; 
    String serviceNameSpace = "namespace of web service"; 
    String soapAction = "URL to method name"; 
    String methodName = "Name of method"; 
    SoapObject rpc = new SoapObject(serviceNameSpace, methodName); 

    //compiler error here 
    rpc.addProperty("number1", 10); 
    rpc.addProperty("number2", 20); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.bodyOut = rpc; 
    envelope.dotNet = true;//IF you are accessing .net based web service this should be true 
    envelope.encodingStyle = SoapSerializationEnvelope.ENC; 
    HttpTransport ht = new HttpTransport(serviceUrl); 
    ht.debug = true; 
    ht.setXmlVersionTag(""); 
    String result = null; 
    try 
    { 
    ht.call(soapAction, envelope); 
    result = (String) (envelope.getResult()); 
    } 
    catch(org.xmlpull.v1.XmlPullParserException ex2){ 
    } 
    catch(Exception ex){ 
    String bah = ex.toString(); 
    } 
    return result; 

답변

3

Android 개발이 Java-SE로 수행되는 동안 BlackBerry 개발은 Java-ME로 수행된다는 점에 유의해야합니다. Java에서 원시는 객체가 아닙니다. 프리미티브는 double, int, float, char 같은 값입니다.

Android에서도 오브젝트가 예상되는 프리미티브를 전달할 수 없습니다. 안드로이드에서 코드가 작동하는 이유는 Java-ME에 추가되지 않은 Java-SE에 추가 ​​된 기능인 auto-boxing 때문입니다.

기본 객체를 래핑하여 객체와 같은 객체를 얻을 수 있습니다. 이것이 Double, Integer, Float 및 Character 클래스의 기능입니다. Java SE에서는 컴파일러가 Object 인수로 전달되는 프리미티브를 확인하면 자동으로 래핑 된 "Boxed"버전으로 변환됩니다. 이 기능은 Java ME에는 존재하지 않으므로 직접 복싱을해야합니다. 이 경우 그 의미는 다음과 같습니다.

rpc.addProperty("number1", new Integer(10)); 
rpc.addProperty("number2", new Integer(20)); 
관련 문제