درود دوستان
برای صفحه ورود به اپلیکیشن منیخوام از بانک اطلاعاتی mysql و pdo استفاده کنم ولی جواب نمیده خطا:
Error parsing data org.json.JSONException: Value Connected of type java.lang.String cannot be converted to JSONObject
ورود :
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginOstad extends Activity implements OnClickListener{
private EditText user, pass;
private Button mSubmit, mRegister;
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
"private static final String LOGIN_URL = "http://10.0.3.2/os/loginostad.php
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginostad_layout);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
user = (EditText)findViewById(R.id.editText1);
pass = (EditText)findViewById(R.id.editText2);
mSubmit = (Button)findViewById(R.id.button1);
mSubmit.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
new AttemptLogin().execute();
break;
default:
break;
}
}
class AttemptLogin extends AsyncTask<String, String, String> {
boolean failure = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LoginOstad.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
int success;
String username = user.getText().toString();
String password = pass.getText().toString();
try {
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
Log.d("request!", "starting");
Thread thread = new Thread() {
@Override
public void run() {
json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);
}
};
thread.start();
Log.d("Login attempt", json.toString());
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(LoginOstad.this);
SharedPreferences.Editor edit = sp.edit();
edit.putString("username",username);
edit.commit();
Intent i = new Intent(LoginOstad.this, MainProgram.class);
finish();
startActivity(i);
return json.getString(TAG_MESSAGE);
}else{
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
if (file_url != null){
Toast.makeText(LoginOstad.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
}