Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i solve this error in android ?
please help

What I have tried:

package com.example.connecttosql;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CalendarView;
import android.widget.EditText;


import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {

    EditText etResponse;
    static String LastLogin;


    private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in meter
    private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in milisecond
    private static final int R_per = 123;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        //news code
        Calendar c =Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");

        etResponse = (EditText)findViewById(R.id.txtNews);
        new HttpAsyncTask().execute("http://localhost:1844/AndroidWebService.asmx/WithJSON?LastLogin=");
        ////
        LastLogin =df.format(c.getTime());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LocationManager locationManage = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            if (!shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {

                requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, R_per);
            }
            return;
        }
        locationManage.requestLocationUpdates(locationManage.GPS_PROVIDER,
                MINIMUM_TIME_BETWEEN_UPDATES,
                MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener(this)
        );
    }


    private  class  HttpAsyncTask extends AsyncTask<String , String , String>{

        protected  String doInBackground(String... urls){
            InputStream inputStream = null;
            String result = "";
            try {
                String murl = urls[0] + LastLogin;

                HttpClient httpclient=new DefaultHttpClient();

                HttpResponse httpResponse = httpclient.execute(new HttpGet(murl));

                inputStream = httpResponse.getEntity().getContent();
                if (inputStream != null)
                    result = converInputStreamToString(inputStream);
                else
                    result = "did not work";
                Thread.sleep(1000);
                publishProgress(result);

            }catch (Exception e){
                //log.d ("InputStream",e.getLocalizedMessage());
            }
            return ("http://localhost:1844/AndroidWebService.asmx/WithJSON?LastLogin=");
        }
    }

    private  static  String converInputStreamToString(InputStream inputStream)throws IOException{
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line = "";
        String result = "";
        int lineNumber  = 0 ;
        while ((line = bufferedReader.readLine())!=null){
            if(lineNumber!= 0)
                result+= line;
            lineNumber++;
        }
        inputStream .close();
        result = result.substring(36,result.length());
        return result.substring(0,result.length()-9);
    }

    protected  void onProgressUpdate(String... text){
        try{
            JSONObject js = new JSONObject(text[0]);
            if(js.getString("NewNews").equals("1")) {
                JSONArray jsdateup = js.getJSONArray("DateUp");
                JSONArray jsname = js.getJSONArray("name");
                String data = "";
                for (int i = 0; i < jsdateup.length(); i++) {
                    data = data + "\n" + jsname.getString(i) + ":" + jsdateup.getString(i);
                }
                etResponse.setText(js.getString("NewNews") + data);
            }
            new HttpAsyncTask().execute("http://localhost:1844/AndroidWebService.asmx/WithJSON?LastLogin=");
        }
        catch (Exception ex){
            etResponse.setText(ex.getMessage().toString());
        }
    }



    public void addclick(View view) {

        final EditText txtname  = (EditText)findViewById(R.id.txtname);
        final EditText txtphone  = (EditText)findViewById(R.id.txtphone);

        Thread runt = new Thread(){
            public void run(){
                CallWebservice cweb  = new CallWebservice();
                cweb.OpenAccount(txtname.getText().toString() , txtphone.getText().toString());

            }
        };
        runt.start();
        try {
            runt.join();

        }
        catch (Exception ex){}
    }
}
Posted
Updated 16-Jun-19 2:14am
Comments
Mohibur Rashid 16-Jun-19 15:51pm    
It looks like dependency conflict

1 solution

Search engines are free to use:

"program type already present" at DuckDuckGo[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900