Farshid pc 0 ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ گزارش اشتراک گذاری ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ با سلام خدمت دوستان عزیز لطفا راهنماییم کنید تو پروژه به یه مشکلی برخوردم 2-3 روزه هر چی میگردم سایتهای داخلی و خارجی رو گشتم چیزی پیدا نمیکنم من می خوام از دیتابیس mysql داده ها رو با json پارس کنم و تو آندروید و داخل یه لیست ویو نمایش بدم اول تو یه هاست رایگان (gigfa) تست کردم برنامه کرش میشه اینم کد کرش: $ adb shell am start -n "com.example.farshid.myconnect/com.example.farshid.myconnect.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Connected to process 1823 on device emulator-5554 Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. D/: HostConnection::get() New Host Connection established 0xb7a14f60, tid 1823 W/EGL_emulation: eglSurfaceAttrib not implemented D/OpenGLRenderer: Enabling debug mode 0 D/dalvikvm: GC_FOR_ALLOC freed 72K, 5% free 2903K/3040K, paused 2ms, total 2ms I/dalvikvm-heap: Grow heap (frag case) to 3.503MB for 635808-byte allocation D/dalvikvm: GC_FOR_ALLOC freed 2K, 4% free 3522K/3664K, paused 1ms, total 2ms D/AndroidRuntime: Shutting down VM W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xaf849b20) E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.farshid.myconnect, PID: 1823 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.farshid.myconnect/com.example.farshid.myconnect.AllProductsActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ListActivity.onContentChanged(ListActivity.java:243) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:293) at android.app.Activity.setContentView(Activity.java:1929) at com.example.farshid.myconnect.AllProductsActivity.onCreate(AllProductsActivity.java:51) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Application terminated. و فایل php و فایل جاوای AllProductsActivityو MainActivity رو هم ضمیمه کردم لطفا راهنمایم کنید <?php $host= "sbt-upvc.ir/myphp"; $dbname="sbtupvci_myShop"; $user = "sbtupvci_shop"; $pass = "farshid"; $response = array(); $con = mysqli_connect($host,$user,$pass,$dbname); // get all products from products table $sql = "select * from tblshop "; $result = mysqli_query($con,$sql); //$result = mysqli_query($con,"SELECT *FROM tblshop"); // check for empty result if ($result->num_rows > 0) { // looping through all results // products node $response["tblshop"] = array(); while ($row = mysqli_fetch_array($result)) { // temp user array $product = array(); $product["idImage"] = $row["idImage"]; $product["nameKala"] = $row["nameKala"]; $product["fiPrice"] = $row["fiPrice"]; $product["description"] = $row["description"]; //$product["updated_at"] = $row["updated_at"]; // push single product into final response array array_push($response["tblshop"], $product); } // success $response["success"] = 1; // echoing JSON response echo json_encode($response); } else { // no products found $response["success"] = 0; $response["message"] = "No products found"; // echo no users JSON echo json_encode($response); } ?> package com.example.farshid.myconnect; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.http.NameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; public class AllProductsActivity extends ListActivity { // Progress Dialog private ProgressDialog pDialog; // Creating JSON Parser object JSONParser jParser = new JSONParser(); ArrayList<HashMap<String, String>> productsList; // url to get all products list private static String url_all_products = "http://sbt-upvc.ir/myphp/get_all_products.php"; // JSON Node names private static final String TAG_SUCCESS = "success"; private static final String TAG_PRODUCTS = "tblshop"; private static final String TAG_nameKala= "nameKala"; private static final String TAG_fiPrice = "fiPrice"; // products JSONArray JSONArray tblshop = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.all_products); // Hashmap for ListView productsList = new ArrayList<HashMap<String, String>>(); // Loading products in Background Thread new LoadAllProducts().execute(); // Get listview ListView lv = getListView(); // on seleting single product // launching Edit Product Screen lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // getting values from selected ListItem String nameKala = ((TextView) view.findViewById(R.id.pid)).getText() .toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), EditProductActivity.class); // sending pid to next activity in.putExtra(TAG_fiPrice, nameKala); // starting new activity and expecting some response back startActivityForResult(in, 100); } }); } // Response from Edit Product Activity @Override protected 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(); finish(); startActivity(intent); } } /** * Background Async Task to Load all product by making HTTP Request * */ class LoadAllProducts extends AsyncTask<String, String, String> { /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(AllProductsActivity.this); pDialog.setMessage("Loading products. 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>(); // 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 tblshop = json.getJSONArray(TAG_PRODUCTS); // looping through All Products for (int i = 0; i < tblshop.length(); i++) { JSONObject c = tblshop.getJSONObject(i); // Storing each json item in variable String nameKala = c.getString(TAG_nameKala); String fiPrice = c.getString(TAG_fiPrice); // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); // adding each child node to HashMap key => value map.put(TAG_nameKala, nameKala); map.put(TAG_fiPrice, fiPrice); // adding HashList to ArrayList productsList.add(map); } } else { // no products found // Launch Add New product Activity Intent i = new Intent(getApplicationContext(), NewProductActivity.class); // Closing all previous activities i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } } 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( AllProductsActivity.this, productsList, R.layout.list_item, new String[] { TAG_nameKala, TAG_fiPrice}, new int[] { R.id.pid, R.id.name }); // updating listview setListAdapter(adapter); } }); } } } package com.example.farshid.myconnect; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; public class MainActivity extends Activity { Button btnViewProducts; Button btnNewProduct; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Buttons btnViewProducts = (Button) findViewById(R.id.btnViewProducts); btnNewProduct = (Button) findViewById(R.id.btnCreateProduct); // view products click event btnViewProducts.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Launching All products Activity Intent i = new Intent(getApplicationContext(), AllProductsActivity.class); startActivity(i); } }); // view products click event btnNewProduct.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Launching create new product activity Intent i = new Intent(getApplicationContext(), NewProductActivity.class); startActivity(i); } }); } } نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
Farshid pc 0 ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ مالک گزارش اشتراک گذاری ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ کسی نیست راهنمایی کنه؟ نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
Farzad Sarseifi 575 ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ گزارش اشتراک گذاری ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ خطای شما ربطی به هاست نداره نقل قول Process: com.example.farshid.myconnect, PID: 1823 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.farshid.myconnect/com.example.farshid.myconnect.AllProductsActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list از لیست ویو ایراد میگیره که دیتایی که براش ارسال میکنید اشتباه هستش 1 نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
Farshid pc 0 ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ مالک گزارش اشتراک گذاری ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ (ویرایش شده) در 31 دقیقه قبل، Farzad Sarseifi گفته است : خطای شما ربطی به هاست نداره از لیست ویو ایراد میگیره که دیتایی که براش ارسال میکنید اشتباه هستش ممنون بابت پاسختون من یه لیست ویو دارم که آیدیش list هست دیگه فایل xml رو همر فرستادم <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> ویرایش شده ۲۲ اردیبهشت ۱۳۹۷ توسط Farshid pc نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
Farshid pc 0 ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ مالک گزارش اشتراک گذاری ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ اینم JSONParesr که نوشتم: package com.example.farshid.myconnect; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONException; import org.json.JSONObject; import android.util.Log; public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } // function get json from url // by making HTTP POST or GET mehtod public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try { // check for request method if(method == "POST"){ // request method is POST // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); }else if(method == "GET"){ // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String return jObj; } } نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
Farshid pc 0 ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ مالک گزارش اشتراک گذاری ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ البته داخل مرورگر با اطلاعات : <?php //Define your host here. $HostName = "sql207.gigfa.com"; //Define your database username here. $HostUser = "gigfa_22018905"; //Define your database password here. $HostPass = "farshid"; //Define your database name here. $DatabaseName = "gigfa_22018905_myShop"; ?> میزنم درست پارس میکنه {"tblshop":[{"idImage":"24","nameKala":"test","fiPrice":"20000","description":"this is a text","imgPhoto":null}],"success":1} ولی در نمایش داخل آندورید کرش میشه. من تازه کارم 3-4 هم نمونه کد امتحان کردم باز کرش میکنه نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
Farshid pc 0 ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ مالک گزارش اشتراک گذاری ارسال شده در ۲۲ اردیبهشت ۱۳۹۷ در 6 ساعت قبل، Farzad Sarseifi گفته است : خطای شما ربطی به هاست نداره از لیست ویو ایراد میگیره که دیتایی که براش ارسال میکنید اشتباه هستش خب راه حلش چیه متوجه نمیشم چطور درستش کنم نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .