Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Testing and Deployment

Reply
Highlighted
Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry
Accepted Solution

Error!: Duplicate definition for 'org.kxml2.io.KXmlParser'

Hi all,

 

 I below attached my code using KSoap2.

The following error throws when i run the project.

"..\lib\kxml2-min-2.3.0.jar(org/kxml2/io/KXmlParser.class): Error!: Duplicate definition for 'org.kxml2.io.KXmlParser' found in: org.kxml2.io.KXmlParser"

 

I searched in BB forums but i cant solve this issue... 

Please tell me hoe to fix this problem

 

package mypackage;


import java.io.InputStream;
import java.io.OutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;


import net.rim.device.api.compress.GZIPOutputStream;
import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.WLANInfo;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
    public MyScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("MyTitle");
        ButtonField bf = new ButtonField();
        add(bf);
        BenoListener benoListener = new BenoListener();
        bf.setChangeListener(benoListener);
    }
    
    public class BenoListener implements FieldChangeListener {
		public void fieldChanged(Field field, int context) {
			try {
				String serviceNamespace = "http://www.google.com/Services/google/";
				String soapAction = "http://www.google.com/Services/google/Login";
				String methodName= "Login";
				String result = "";  
				String begin = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
						+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
						+ "<soap:Body>";
				String end = "</soap:Body>" + "</soap:Envelope>";
				String soapBody =begin;
				soapBody += "<crbn:Login xmlns:crbn=\"http://www.google.com/Services/google\">";
				soapBody += "<UserName>";
				soapBody += "naresh@gmail.com";
				soapBody += "</UserName>";
				soapBody += "<Password>";
				soapBody += "12345678";
				soapBody += "</Password>";
				soapBody += "</crbn:Login>";
				soapBody += end;
		        SoapObject rpc = new SoapObject(serviceNamespace, methodName);
		        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		        envelope.encodingStyle = SoapSerializationEnvelope.ENC;
		        HttpConnection connection = (HttpConnection) Connector.open("https://services.google.com:8443/axis2/services/api/V1.0/GoogleServices"+ getConnectionParameter(),Connector.READ_WRITE);
		        connection.setRequestProperty("SOAPAction", soapAction);
		        connection.setRequestProperty("Content-Type", "application/x-gzip");
		        connection.setRequestProperty("Content-Encoding", "gzip");
		        connection.setRequestProperty("Accept-Encoding", "gzip");
		        connection.setRequestProperty("Content-Length","" + soapBody.getBytes().length);
		        connection.setRequestProperty("User-Agent", "kSOAP/2.0");
		        connection.setRequestMethod(HttpConnection.POST);
		        OutputStream os = connection.openOutputStream();
		        
		        zipRequest(os, soapBody);
//		        os.write(soapBody.getBytes(), 0, soapBody.getBytes().length);
//		        os.close();
		        soapBody = null;
		        InputStream is = connection.openInputStream();
		        XmlPullParser xp = new KXmlParser();
		        xp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
		        xp.setInput (is, null);
		        envelope.parse(xp);
		        result = (envelope.getResponse()).toString();
		        Dialog.alert("Result---"+result);
			} catch (Exception ex) {
			}
			
		}

		private String getConnectionParameter() {
			String connectionParameter = "";
			if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
				connectionParameter = ";interface=wifi";
			} else {
				int coverageStatus = CoverageInfo.getCoverageStatus();
				if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
					connectionParameter = ";deviceside=false";
				} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
					connectionParameter = ";deviceside=true";
				}
			}
			return connectionParameter;
		}

		
	
			public void zipRequest(OutputStream io, String data) throws Exception{	
				try{
					GZIPOutputStream gz = new GZIPOutputStream(io);
					byte[] bytes = data.getBytes("UTF-8");
					gz.write(bytes, 0, bytes.length);
					gz.close();
				}
				catch(Exception ex){
				}
		}
	
}
}

 

Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry

Re: Error!: Duplicate definition for 'org.kxml2.io.KXmlParser'

I solved this problem to "Preverify the jar".