0
私はPHPスクリプトからデータを読み込むプログラムを持っています。成功= 1のときは私のプログラムは失敗しますが、成功= 0のときはプログラムは強制終了します。 logcat成功時のAndroidクローズ=
でNOリストエラーませんこの
<?php
/* 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();
}
}
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// connecting to db
$db = new DB_CONNECT();
$keyword=$_GET["keyword"];
// get all news update dzc
$result = mssql_query("SELECT item_code, Name, item_code, nItemCode_U, dtGiveDate FROM tbl_ItemCharge a
INNER JOIN tbl_code_item ON nItemCode_K = item_ks
INNER JOIN tbl_base b ON a.nAvatorSerial = b.Serial
WHERE Name = '$keyword' ORDER BY dtGiveDate DESC") or die(mssql_error());
// check for empty result
if (mssql_num_rows($result) > 0) {
// looping through all results
// products node
$response["inputitemlog"] = array();
while ($row = mssql_fetch_array($result)) {
// temp user array
$product = array();
$product["Item Logo"] = substr($row["item_code"], 0, 2);
$product["Name"] = $row["Name"];
$product["Item Code"] = $row["item_code"];
$product["Item Upgrade"] = dechex($row["nItemCode_U"]);
$product["Item Date"] = $row["dtGiveDate"];
// push single product into final response array
array_push($response["inputitemlog"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No log item in $keyword";
// echo no users JSON
echo json_encode($response);
}
?>
のようなこの
Toolbar toolbar;
ImageView image;
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
private ListView listView;
ArrayList<HashMap<String, String>> productsList;
// url to get all products list
private static String url_all_products = "http://192.168.1.113/log_item_ign.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "inputitemlog";
private static final String TAG_LOGO = "Item Logo";
private static final String TAG_NAME = "Name";
private static final String TAG_CODEITEM = "Item Code";
private static final String TAG_UPGRADEITEM = "Item Upgrade";
private static final String TAG_DATEITEM = "Item Date";
// products JSONArray
JSONArray products = null;
public String searchkey1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logitem);
// ListView listView = (ListView) findViewById(android.R.id.list);
// Hashmap for ListView
Intent myIntent = getIntent();
searchkey1 = myIntent.getStringExtra("ign");
productsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
toolbar = (Toolbar) findViewById(R.id.toolbar);
image = (ImageView) findViewById(R.id.thumbnail);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//listView = (ListView) findViewById(R.id.lista);
TypedValue typedValueColorPrimaryDark = new TypedValue();
ListLogItemIGN.this.getTheme().resolveAttribute(R.attr.colorPrimary, typedValueColorPrimaryDark, true);
final int colorPrimaryDark = typedValueColorPrimaryDark.data;
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setStatusBarColor(colorPrimaryDark);
}
}
// Get listview
protected ListView getListView(){
if (listView == null) {
listView = (ListView) findViewById(R.id.logitem);
}
return listView;
}
// Response from Edit Product Activity
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
startActivity(intent);
}
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, Void, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ListLogItemIGN.this);
pDialog.setMessage("Loading. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("keyword", searchkey1));
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
//String logo = c.getString(TAG_LOGO);
String name = c.getString(TAG_NAME);
String codeitem = c.getString(TAG_CODEITEM);
String upgradeitem = c.getString(TAG_UPGRADEITEM);
String dateitem = c.getString(TAG_DATEITEM);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
//map.put(TAG_LOGO, logo);
map.put(TAG_NAME, name);
map.put(TAG_CODEITEM, codeitem);
map.put(TAG_UPGRADEITEM, upgradeitem);
map.put(TAG_DATEITEM, dateitem);
// adding HashList to ArrayList
productsList.add(map);
}
} else {
Toast.makeText(getApplicationContext(), "Doesn't have log item now", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
//runOnUiThread(new Runnable() {
// public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
ListLogItemIGN.this, productsList,
R.layout.list_inputitem, new String[]{
TAG_NAME, TAG_CODEITEM, TAG_UPGRADEITEM, TAG_DATEITEM},
new int[]{ R.id.title, R.id.rating, R.id.genre, R.id.releaseYear});
// updating listview
getListView().setAdapter(adapter);
//}
// });
}
}
私のコードをPHPのようなこのhttp://prntscr.com/bkw700 成功= 0
http://prntscr.com/bkw796このような私のコードのアンドロイドのような成功は= 1誰でも私のプログラムを解決するのを助けることができますか? おかげデータ
はまだ私のアプリケーション –
は、スタックトレースを投稿閉じる強制してくださいしてみてくださいSimpleAdapterためnullになることができませんでした – yummy