我正在开发一个Android应用程序,我在其中将图像转换为字节数组并使用ksoap2发送它。当我尝试它时,我得到一个例外,应用程序正在崩溃。我在下面给我的代码和堆栈跟踪..如果有人可以帮助我...请帮助。
登录
java.lang.NoClassDefFoundError:org.kobjects.base64.Base64
在 org.ksoap2.serialization.MarshalBase64.writeInstance(MarshalBase64.java:39) 在 org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:653) 在 org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:645) 在 org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:614) 在 org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:598) 在 org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:655) 在 org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:579) 在org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192)
在org.ksoap2.transport.Transport.createRequestData(Transport.java:82) 在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:79) 在 com.example.manappuram.punching_maceinn.MainActivity.GetConfirm(MainActivity.java:420) 在 com.example.manappuram.punching_maceinn.MainActivity $ 10.onPictureTaken(MainActivity.java:797) 在android.hardware.Camera $ EventHandler.handleMessage(Camera.java:823) 在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
在java.lang.reflect.Method.invoke(Method.java:511)
在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1027) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
在dalvik.system.NativeStart.main(本地方法)
MainActivity
public void GetConfirm() {
String SOAP_ACTION = "http://tempuri.org/cccc";
String METHOD_NAME = "ccccc";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://zxxxx.xx.xx.xx/my_services/ccc.asmx";
try {
//Code added by Jocheved on 31/03/2017
String photoPath = Environment.getExternalStorageDirectory()+"/JCG Camera/img.jpg";
File imagefile = new File(photoPath);
FileInputStream fis = null;
try {
fis = new FileInputStream(imagefile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bm = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] b = baos.toByteArray();
String encImage = Base64.encodeToString(b, Base64.DEFAULT);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
pi1 = new PropertyInfo();
pi1.setName("xcode");
int x = Integer.parseInt(empId.getText().toString().trim());
pi1.setValue(x);
pi1.setType(Integer.class);
Request.addProperty(pi1);
pi2 = new PropertyInfo();
pi2.setName("in_time");
pi2.setValue(shiftTime.getText().toString().trim());
pi2.setType(String.class);
Request.addProperty(pi2);
pi3 = new PropertyInfo();
pi3.setName("em_id");
pi3.setValue(3531);
pi3.setType(Integer.class);
Request.addProperty(pi3);
pi4 = new PropertyInfo();
pi4.setName("photo_rel");
System.out.println("image convertion string is " + img);
pi4.setValue(b);
Request.addProperty(pi4);
pi5 = new PropertyInfo();
pi5.setName("ipd");
pi5.setValue("10.29.245.85~DT-3501-56070");
pi5.setType(String.class);
Request.addProperty(pi5);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
new MarshalBase64().register(soapEnvelope);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE transport = new HttpTransportSE(URL);
transport.debug = true;
transport.call(SOAP_ACTION, soapEnvelope);
System.out.println("Cannot serialize 1");
try{
SoapObject result=(SoapObject)soapEnvelope.getResponse();
Toast.makeText(MainActivity.this, "Successs", Toast.LENGTH_LONG).show();
if(result!= null){
System.out.println("Resp in confirm click is " + result.toString());
Toast.makeText(MainActivity.this, "Successs", Toast.LENGTH_LONG).show();
的build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/ksoap2-android-2.5.2.jar')
compile files('libs/org-apache-commons-codec.jar')
}
答案 0 :(得分:0)
好像你没有正确添加ksoup库。这就是为什么gradle无法找到它。
请查看此link
<强>编辑:强>
不要从lib添加库。尝试将以下行复制并粘贴到build.gradle文件中。
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'