Mistake
value br of type java.lang.string cannot be converted to JSONObject
loginActivity code
import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import com.qwinty.furtu.R; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class LoginActivity extends AppCompatActivity { EditText name, password; String Name, Password; Context ctx=this; String NAME=null, PASSWORD=null, EMAIL=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); name = (EditText) findViewById(R.id.main_name); password = (EditText) findViewById(R.id.main_password); } public void main_register(View v){ startActivity(new Intent(this,RegisterActivity.class)); } public void main_login(View v){ Name = name.getText().toString(); Password = password.getText().toString(); BackGround b = new BackGround(); b.execute(Name, Password); } class BackGround extends AsyncTask<String, String, String> { @Override protected String doInBackground(String... params) { String name = params[0]; String password = params[1]; String data=""; int tmp; try { URL url = new URL("http://*****.ru/login.php"); String urlParams = "name="+name+"&password="+password; HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setDoOutput(true); OutputStream os = httpURLConnection.getOutputStream(); os.write(urlParams.getBytes()); os.flush(); os.close(); InputStream is = httpURLConnection.getInputStream(); while((tmp=is.read())!=-1){ data+= (char)tmp; } is.close(); httpURLConnection.disconnect(); return data; } catch (MalformedURLException e) { e.printStackTrace(); return "Exception: "+e.getMessage(); } catch (IOException e) { e.printStackTrace(); return "Exception: "+e.getMessage(); } } @Override protected void onPostExecute(String s) { String err=null; try { JSONObject root = new JSONObject(s); JSONObject user_data = root.getJSONObject("user_data"); NAME = user_data.getString("name"); PASSWORD = user_data.getString("password"); EMAIL = user_data.getString("email"); } catch (JSONException e) { e.printStackTrace(); err = "Exception: "+e.getMessage(); } Intent i = new Intent(ctx, Home.class); i.putExtra("name", NAME); i.putExtra("password", PASSWORD); i.putExtra("email", EMAIL); i.putExtra("err", err); startActivity(i); } }
Here is a monitor error
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject org.json.JSON.typeMismatch(JSON.java:111) org.json.JSONObject.<init>(JSONObject.java:160) org.json.JSONObject.<init>(JSONObject.java:173)