android - Gradle 错误 Cannot invoke method dependencies() on null object

标签 android gradle dependencies ksoap2 invoke

我正在为健身房开发一款社交应用。此应用程序通过 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”时出现问题。

Cannot invoke method dependencies() on null object

在此先感谢您的帮助。

最佳答案

您应该只有一个 dependencies block ,或者至少在 和后续的 dependencies { 之间换行。

如果你这样做会发生什么:

    dependencies {
        compile files('ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
        compile 'com.android.support:appcompat-v7:+'
    }

关于android - Gradle 错误 Cannot invoke method dependencies() on null object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23376268/

相关文章:

java - Android:HttpGet 不发布到数据库

android - 如何填充 SQLite 数据库并在 phonegap 中使用该数据库?

gradle - 找不到 guice-4.2.1-no_aop.jar

java - 补丁依赖工具

android - Google Play - 封闭/内部测试 : How to remove/disable App on Tester's Device?

android - AdMob 横幅广告未展示

android - 网络用户目录的设置gradle

android - 如何用IDEA+Gradle+Android运行单元测试

python - 如何打包 python 应用程序以使其可 pip 安装?

node.js - 在 Heroku review-app 部署后步骤中使用 NodeJS 开发依赖项