diff --git a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java index 8bd4da9..c676eec 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java @@ -18,9 +18,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; -/** - * Created by ProgrammingKnowledge on 1/5/2016. - */ public class PHPComm extends AsyncTask { private static final String TAG = "MainActivity"; Context context; @@ -28,13 +25,14 @@ public class PHPComm extends AsyncTask { PHPComm (Context ctx) { context = ctx; } - static public String return_json; + static String json_return; @Override protected String doInBackground(String... params) { String type = params[0]; String login_url = "http://192.168.1.21/database/communication/comm.php"; if(type.equals("get")) { try { + Log.d(TAG,"received get"); String id = params[1]; String value = params[2]; URL url = new URL(login_url); @@ -79,15 +77,13 @@ public class PHPComm extends AsyncTask { @Override protected void onPostExecute(String result) { alertDialog.setMessage(result); - Log.d(TAG, "AlertBoxSet" + result); - setJson(result); + Log.d(TAG, "AlertBoxSet " + result); + json_return = result; + alertDialog.show(); } @Override protected void onProgressUpdate(Void... values) { super.onProgressUpdate(values); } - static private void setJson(String json){ - return_json = json; - } } diff --git a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java index 3432a4a..61ec9dc 100644 --- a/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java +++ b/FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java @@ -84,17 +84,23 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener { Bundle extras = getIntent().getExtras(); if (extras != null) { prod_loc = extras.getString("key"); - //The key argument here must match that used in the other activity + //The key argument here must match that used in the other activitylgo } // This method is called once with the initial value and again // whenever data at this location is updated. PHPComm comm = new PHPComm(this); comm.execute("get", "1", "Products"); try { - json_str = PHPComm.return_json; - Log.d(TAG,"get json str" + json_str); - JSONObject jsonObj = new JSONObject(json_str); - }catch (JSONException e) { + json_str = comm.json_return; + while(json_str == null){ + json_str = comm.json_return; + continue; + } + + Log.d(TAG,"This is a pointer"); + //Log.d(TAG,"get json str" + json_str); + //JSONObject jsonObj = new JSONObject(json_str); + }catch (NullPointerException e) { Log.d(TAG, "An error occured with the json!"); } /*