prasad.gai
prasad.gai

Reputation: 2987

"the method is not applicable for the arguments" when building BlackBerry app

I am developing a sample application to call .Net web services. I have added ksoap2-j2me-core-prev-2.1.2.jar to the build path in Eclipse.

I am passing two values via addProperty: "number1" and 10 as integer, and also "number2" and 20. This causes a compiler error:

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

How can I resolve the error and how can I pass one string and one int value to addProperty? I have done this the same way in Android and it is working fine there.

    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;

Upvotes: 2

Views: 1983

Answers (1)

Michael Donohue
Michael Donohue

Reputation: 11876

You need to be aware that BlackBerry development is done with Java-ME, while Android development is done with Java-SE. In Java, primitives are not objects. Primitives are values like double, int, float, char.

You can't pass a primitive where an object is expected, even in Android. The reason your code works in Android is because of a feature added to Java-SE that isn't in Java-ME, called auto-boxing.

You can get primitives to be like objects by wrapping them. That is what the Double, Integer, Float and Character classes do. In Java SE, when the compiler sees a primitive being passed as an Object argument, it automatically converts to the wrapped, or "Boxed" version. This feature doesn't exist in Java-ME, so you have to do the boxing yourself. In this case, that means:

rpc.addProperty("number1", new Integer(10));
rpc.addProperty("number2", new Integer(20));

Upvotes: 3

Related Questions