我正在为健身房建立一个社交应用程序。此应用程序通过webmethods连接到C#Web应用程序。我正在尝试调用ksoap2-android-assembly-3.0.0-RC.2-jar-with-dependencies.jar
并经过大量调试后,我想出了这个Register类:
package com.aaa.ifitapp;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* Created by Ayman on 3/28/14.
*/
public class Register extends Activity {
EditText txtname,txtemail,txtbdate,txtadres,txtphone,txtmsg;
TextView txtg;
Button btnregister;
RadioGroup gendergrpbtn;
RadioButton mrbtn,frbtn;
private void Initialize(){
txtg =(EditText) findViewById(R.id.gtxt);
txtname =(EditText) findViewById(R.id.fullnametxt);
txtemail =(EditText) findViewById(R.id.remailtxt);
txtbdate =(EditText) findViewById(R.id.agetxt);
txtadres =(EditText) findViewById(R.id.addresstxt);
txtphone =(EditText) findViewById(R.id.phonetxt);
txtmsg =(EditText) findViewById(R.id.msgtxt);
btnregister =(Button) findViewById(R.id.signupbtn);
mrbtn =(RadioButton) findViewById(R.id.rdobtnm);
frbtn =(RadioButton) findViewById(R.id.rdobtnf);
gendergrpbtn = (RadioGroup) findViewById(R.id.genderrbtn);
btnregister.setOnClickListener(BtnRegist);
gendergrpbtn.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
if(frbtn.isChecked()){
txtg.setText("f");
}
else{
mrbtn.isChecked();
txtg.setText("m");
}
}});
}
View.OnClickListener BtnRegist=new View.OnClickListener() {
@Override
public void onClick(View view) {
StrictMode.ThreadPolicy policy=
new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
SoapObject request = new SoapObject("http://ifitness.com/adminservice","register");
request.addProperty("fullname",txtname.getText().toString());
request.addProperty("email",txtemail.getText().toString());
request.addProperty("address",txtadres.getText().toString());
request.addProperty("gender", txtg.getText().toString());;
request.addProperty("bdate",txtbdate.getText().toString());
request.addProperty("phone", txtname.getText().toString());
request.addProperty("image",txtname.getText().toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE transport=
new HttpTransportSE("http://10.0.2.2:1469/IFitService.asmx?WSDL");
try {
transport.call("http://ifitness.com/adminservice/register",envelope);
txtmsg.setText(envelope.getResponse().toString());
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Initialize();
}
}
我调整了build.gradle,如下所示:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
}
dependencies {
compile files('ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
}dependencies {
compile 'com.android.support:appcompat-v7:+'
}
但现在我收到了这个错误:
Gradle:评估项目':IFitApp'时出现问题。
无法在null对象上调用方法依赖项()
提前感谢您的任何帮助。
答案 0 :(得分:1)
您应该只有一个dependencies block
,或者至少在}
和后续dependencies {
之间换行。
如果您这样做会发生什么:
dependencies {
compile files('ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
compile 'com.android.support:appcompat-v7:+'
}