构建失败的TransformException:java.util.zip.ZipException:重复条目:android / support / v4 / widget / ScrollerCompat.class

时间:2016-03-20 06:31:20

标签: java android json

我试图在android studio中创建客户端服务器登录应用程序..我已经包含了jar文件。但我收到构建错误错误:任务执行失败':app:transformClassesWithJarMergingForDebug'。

  

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:android / support / v4 / widget / ScrollerCompat.class

请帮助我,谢谢。:)

MainActivity.java

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;
import android.os.Bundle;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener
{

 EditText e1,e2,e3;
Button btn;
String subid;
ProgressDialog pDialog;


Spinner sp;
ArrayAdapter adp;
String str[]={"                            Male                          ","                           Female                         "};

Button l;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    e1=(EditText)this.findViewById(R.id.editText1);
    e2=(EditText)this.findViewById(R.id.editText2);
    e3=(EditText)this.findViewById(R.id.editText3);

    btn=(Button)this.findViewById(R.id.button1);
    btn.setOnClickListener(this);
    l=(Button)this.findViewById(R.id.button2);
    l.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    //getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
private class MyAsyncTask extends AsyncTask<String, Integer, Double>{
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(MainActivity.this);
        pDialog.setMessage("Please Wait..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected Double doInBackground(String... params) {
        // TODO Auto-generated method stub
        postData();
        return null;
    }

    protected void onPostExecute(Double result){
        pDialog.dismiss();
        Toast.makeText(getApplicationContext(), "Data Sent", Toast.LENGTH_SHORT).show();
        // Intent login=new Intent(getApplicationContext(),LoginActivity.class);
        //startActivity(login);
    }
    protected void onProgressUpdate(Integer... progress){
    }

    public void postData() {
        // Create a new HttpClient and Post Header
        //String url= "your website url";
        String url="http://10.0.2.2:8084/AcceptRequest/reg.jsp" ;
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("name",e1.getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("email",e2.getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("contact",e3.getText().toString()));



            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    }

}
@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    if(arg0.getId()==R.id.button1)
    {
        new MyAsyncTask().execute();
    }
    if(arg0.getId()==R.id.button2)
    {
        Intent i=new Intent(this,LoginActivity.class);
        startActivity(i);
    }
}

}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.l.serverconnectioncheck.MainActivity">
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Register" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView1"
    android:ems="10"
    android:hint="Enter the name ">

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText1"
    android:layout_alignRight="@+id/editText1"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="16dp"
    android:ems="10"
    android:hint="Enter the email" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText2"
    android:layout_alignRight="@+id/editText2"
    android:layout_below="@+id/editText2"
    android:layout_marginTop="24dp"
    android:ems="10"
    android:hint="Enter the password" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText3"
    android:layout_alignRight="@+id/editText3"
    android:layout_below="@+id/editText3"
    android:text="Register" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_alignRight="@+id/button1"
    android:layout_below="@+id/button1"
    android:layout_marginTop="24dp"
    android:text="Login" />

LoginActivity.java

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;







import org.apache.http.NameValuePair;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class LoginActivity extends Activity implements View.OnClickListener         {

ProgressDialog pDialog;
Button btn;
EditText utxtf,ptxtf;
JSONParser jsonParser = new JSONParser();
String feedback;
int a;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    btn=(Button)this.findViewById(R.id.lgnbtn);
    utxtf=(EditText)this.findViewById(R.id.usertext);
    ptxtf=(EditText)this.findViewById(R.id.passtext);
    btn.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    // getMenuInflater().inflate(R.menu.login, menu);
    return true;
}
private class MyAsyncTask extends AsyncTask<String, Integer, Double> {
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(LoginActivity.this);
        pDialog.setMessage("Please Wait..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();

    }

    @Override
    protected Double doInBackground(String... params) {
        // TODO Auto-generated method stub
        postData();
        return null;
    }

    protected void onPostExecute(Double result){
        pDialog.dismiss();
        if(a==1)
        {
            Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_SHORT).show();
        }
        if(a==2)
        {
            Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_SHORT).show();

        }
        if(a==0)
        {
            Toast.makeText(getApplicationContext(), "Login null", Toast.LENGTH_SHORT).show();
        }
        // Intent login=new Intent(getApplicationContext(),LoginActivity.class);
        //startActivity(login);
    }
    protected void onProgressUpdate(Integer... progress){
    }

    public void postData() {
        // Create a new HttpClient and Post Header
        //String url= "your website url";
        String url="http://10.0.2.2:8084/AcceptRequest/validate.jsp" ;
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("username", utxtf.getText().toString()));
        params.add(new BasicNameValuePair("password", ptxtf.getText().toString()));
        JSONObject json =  jsonParser.makeHttpRequest(url, "POST", params);
        if (json.equals(null)) {
            // Toast.makeText(getApplicationContext(),"null value",Toast.LENGTH_LONG).show();
            a=0;
        } else {
            try {
                String message=json.getString("msg");
                if(message.equals("yes"))
                {a=1;
//Toast.makeText(getApplicationContext(),"Login Success",Toast.LENGTH_LONG).show();
                }
                else
                {
                    //  Toast.makeText(getApplicationContext(),"Login Failed",Toast.LENGTH_LONG).show();
                    a=2;
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

}
@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    new MyAsyncTask().execute();
}

}

activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.l.serverconnectioncheck.LoginActivity">
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Welcome" />

<EditText
    android:id="@+id/usertext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="17dp"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/passtext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/usertext"
    android:layout_alignRight="@+id/usertext"
    android:layout_below="@+id/usertext"
    android:layout_marginTop="18dp"
    android:ems="10" />

<Button
    android:id="@+id/lgnbtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/passtext"
    android:layout_alignRight="@+id/passtext"
    android:layout_below="@+id/passtext"
    android:text="Login" />



</RelativeLayout>

JSONParser.java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;

public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

public JSONParser() {

}

public JSONObject makeHttpRequest(String url, String method,
                                  List<NameValuePair> params) {
    try {
        if (method == "POST") {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

        } else if (method == "GET") {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);
            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    return jObj;

}
}

的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.0"

defaultConfig {
    applicationId "com.example.l.serverconnectioncheck"
    minSdkVersion 17
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true


}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile files('libs/android-support-v4.jar')
compile files('libs/commons-codec-1.6.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/fluent-hc-4.2.1.jar')
compile files('libs/httpclient-4.2.3.jar')
compile files('libs/httpclient-cache-4.2.3.jar')
compile files('libs/httpcore.jar')
compile files('libs/httpmime-4.2.3.jar')
compile files('libs/java-json.jar')
compile files('libs/json-simple-1.1.1.jar')
}


Please help me with a solution.

0 个答案:

没有答案