当前位置: 动力学知识库 > 问答 > 编程问答 >

Android force close after sending data to server via php

问题描述:

I have a program to read data from SQL Server using php file. When I running my program and click the button search my program always close. In my logcat no one error message

My code android like this

Toolbar toolbar;

// Progress Dialog

private ProgressDialog pDialog;

JSONParser jsonParser = new JSONParser();

EditText inputign;

TextView registerErrorMsg;

Button searchign;

// url to create news

private static String url_create_idgm = "http://192.168.1.111/add/csp_ign.php";

// JSON Node names

private static final String TAG_SUCCESS = "success";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_cps_ign);

toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

TypedValue typedValueColorPrimaryDark = new TypedValue();

CSPviaIGN.this.getTheme().resolveAttribute(R.attr.colorPrimary, typedValueColorPrimaryDark, true);

final int colorPrimaryDark = typedValueColorPrimaryDark.data;

if (Build.VERSION.SDK_INT >= 21) {

getWindow().setStatusBarColor(colorPrimaryDark);

}

// Edit Text

inputign = (EditText) findViewById(R.id.inputign);

registerErrorMsg = (TextView) findViewById(R.id.error);

// Create button

searchign = (Button) findViewById(R.id.btnign);

// button click event

searchign.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// creating new product in background thread

new NetCheck().execute();

}

});

}

/**

* Background Async Task to Create new product

* */

class NetCheck extends AsyncTask<String, String, String> {

/**

* Before starting background thread Show Progress Dialog

* */

@Override

protected void onPreExecute() {

super.onPreExecute();

pDialog = new ProgressDialog(CSPviaIGN.this);

pDialog.setMessage("Creating ID Game Master..");

pDialog.setIndeterminate(false);

pDialog.setCancelable(true);

pDialog.show();

}

/**

* Creating product

* */

protected String doInBackground(String... args) {

String name = inputign.getText().toString();

// Building Parameters

List<NameValuePair> params = new ArrayList<NameValuePair>();

params.add(new BasicNameValuePair("ign", name));

// getting JSON Object

// Note that create product url accepts POST method

JSONObject obj = jsonParser.makeHttpRequest(url_create_idgm,

"POST", params);

// check log cat fro response

Log.d("Create Response", obj.toString());

// check for success tag

try {

int success = obj.getInt(TAG_SUCCESS);

if (success == 1) {

// successfully created product

//Toast.makeText(CreateIDGM.this, "Success Create ID Game Master ", Toast.LENGTH_SHORT).show();

//JSONObject obj = jParser.makeHttpRequest(url_create_idgm, "GET", params);

JSONArray account = obj.getJSONArray("detail");

JSONObject firstOnlineObject = account.getJSONObject(0);

String accountign = firstOnlineObject.getString("Account");

JSONArray ign = obj.getJSONArray("detail");

JSONObject secondOnlineObject = ign.getJSONObject(0);

String Name = secondOnlineObject.getString("Name");

JSONArray race = obj.getJSONArray("detail");

JSONObject thirdOnlineObject = race.getJSONObject(0);

String bangsa = thirdOnlineObject.getString("Race");

JSONArray classign = obj.getJSONArray("detail");

JSONObject forthOnlineObject = classign.getJSONObject(0);

String job = forthOnlineObject.getString("Class");

JSONArray map = obj.getJSONArray("detail");

JSONObject fifthOnlineObject = map.getJSONObject(0);

String location = fifthOnlineObject.getString("Map");

JSONArray level = obj.getJSONArray("detail");

JSONObject sixthOnlineObject = level.getJSONObject(0);

String Lv = sixthOnlineObject.getString("Level");

JSONArray dalant = obj.getJSONArray("detail");

JSONObject seventhOnlineObject = dalant.getJSONObject(0);

String money = seventhOnlineObject.getString("Dalant");

JSONArray gold = obj.getJSONArray("detail");

JSONObject eighthOnlineObject = gold.getJSONObject(0);

String emas = eighthOnlineObject.getString("Gold");

JSONArray pvp = obj.getJSONArray("detail");

JSONObject ninthOnlineObject = pvp.getJSONObject(0);

String pvppoint = ninthOnlineObject.getString("PVP Point");

JSONArray cpt = obj.getJSONArray("detail");

JSONObject tenOnlineObject = cpt.getJSONObject(0);

String cptpoint = tenOnlineObject.getString("CPT Point");

JSONArray cc = obj.getJSONArray("detail");

JSONObject ccOnlineObject = cc.getJSONObject(0);

String cashcoin = ccOnlineObject.getString("Cash Coin");

JSONArray ps = obj.getJSONArray("detail");

JSONObject psOnlineObject = ps.getJSONObject(0);

String premi = psOnlineObject.getString("Premium Service");

// TextView data

TextView id = (TextView)findViewById(R.id.accountplayer);

id.setText(accountign); // id

TextView ignname = (TextView)findViewById(R.id.ignPlayer);

ignname.setText(Name); // ign

TextView raceign = (TextView)findViewById(R.id.serialplayer);

raceign.setText(bangsa); // race

TextView jobign = (TextView)findViewById(R.id.raceplayer);

jobign.setText(job); // job

TextView mapign = (TextView)findViewById(R.id.classplayer);

mapign.setText(location); // map

TextView lvign = (TextView)findViewById(R.id.lvlplayer);

lvign.setText(Lv); //level

TextView dalantign = (TextView)findViewById(R.id.dalantplayer);

dalantign.setText(money); // dalant

TextView goldign = (TextView)findViewById(R.id.goldplayer);

goldign.setText(emas); // gold

TextView pvpign = (TextView)findViewById(R.id.pvpplayer);

pvpign.setText(pvppoint); // pvp

TextView cptign = (TextView)findViewById(R.id.cptplayer);

cptign.setText(cptpoint); //cpt

TextView cashign = (TextView)findViewById(R.id.cc);

cashign.setText(cashcoin); // cash

TextView premiign = (TextView)findViewById(R.id.premi);

premiign.setText(premi); // premi

// closing this screen

finish();

} else {

// failed to create product

}

} catch (JSONException e) {

e.printStackTrace();

}

return null;

}

protected void onPostExecute(String file_url) {

// dismiss the dialog once done

pDialog.dismiss();

Intent i = new Intent(getApplicationContext(), CSPviaIGN.class);

//i.putExtra("key",inputign.getText().toString());

startActivity(i);

}

}

My code php like this

<?php

//$_POST['ign'] = "CaptainJugger";

// array for JSON response

$response = array();

// check for required fields

if (isset($_POST['ign'])) {

$ign = $_POST['ign'];

/* All database connection variables */

define('DB_USER', ""); // db user

define('DB_PASSWORD', ""); // db password

define('DB_DATABASE', "RF_World"); // database name

define('DB_SERVER', "127.0.0.1"); // db server

class DB_CONNECT {

// constructor

function __construct() {

// connecting to database

$this->connect();

}

// destructor

function __destruct() {

// closing db connection

$this->close();

}

/** Function to connect with database **/

function connect() {

// Connecting to mssql database

$con = mssql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mssql_error());

// Selecing database

$db = mssql_select_db(DB_DATABASE) or die(mssql_error()) or die(mssql_error());

// returing connection cursor

return $con;

}

/** Function to close db connection **/

function close() {

// closing db connection

mssql_close();

}

}

// connecting to db

$db = new DB_CONNECT();

// mssql inserting a new row

$result = mssql_query("SELECT Account, Name, Race, Class, Map, Lv, Dalant, Gold, c.PvpPoint, PvpCash, Cash, d.Status FROM tbl_base a

INNER JOIN tbl_general b ON b.Serial = a.Serial

INNER JOIN tbl_pvporderview c ON c.serial = a.Serial

INNER JOIN [BILLING].[dbo].tbl_UserStatus d ON d.id = a.Account

WHERE Name= '$ign';");

// status premium service

if ($res['Status'] == 1){

$status = 'Deactive';

} else {

$status = 'Active';

}

// status race

if ($res['Race'] == 0){

$race = 'Bellato';

} elseif ($res['Race'] == 1){

$race = 'Bellato';

} elseif ($res['Race'] == 2){

$race = 'Cora';

} elseif ($res['Race'] == 3){

$race = 'Cora';

} else {

$race = 'Accretia';

}

// check if row inserted or not

if (mssql_num_rows($result) > 0) {

// looping through all results

// products node

$response["detail"] = array();

while ($row = mssql_fetch_array($result)) {

// temp user array

$product = array();

$product["Account"] = $row["Account"];

$product["Name"] = $row["Name"];

$product["Race"] = $row["Race"];

$product["Class"] = $row["Class"];

$product["Map"] = $row["Map"];

$product["Level"] = $row["Lv"];

$product["Dalant"] = $row["Dalant"];

$product["Gold"] = $row["Gold"];

$product["PVP Point"] = $row["PvpCash"];

$product["CPT Point"] = $row["PvpPoint"];

$product["Cash Coin"] = $row["Cash"];

$product["Premium Service"] = $row["Status"];

// push single product into final response array

array_push($response["detail"], $product);

}

// success

$response["success"] = 1;

// echoing JSON response

echo json_encode($response);

} else {

// no products found

$response["success"] = 0;

$response["message"] = "No News DZoneConnect Now";

}

}

else {

// required field is missing

$response["success"] = 0;

$response["message"] = "Required field(s) is missing";

// echoing JSON response

echo json_encode($response);

}

?>

My code php when I run in browser like this http://prntscr.com/bfjl5a and http://prntscr.com/bfjlf3

Anyone can help me to solve my problem?

分享给朋友:
您可能感兴趣的文章:
随机阅读: