Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android应用程序未连接到xamp数据库_Android_Listview_Arraylist_Android Adapter - Fatal编程技术网

Android应用程序未连接到xamp数据库

Android应用程序未连接到xamp数据库,android,listview,arraylist,android-adapter,Android,Listview,Arraylist,Android Adapter,它没有给出错误,但当运行和启动活动时,它给出的应用程序名称停止工作。在android清单中,我添加了internet权限。URL路径工作非常好,因为我直接将其放入浏览器中,它会给出所需的结果。我是android应用程序开发的新手。请帮助我,我在最后一年的项目中需要它。 StartingPoint.java public class StartingPoint extends Activity implements OnClickListener { Button bed; @Override

它没有给出错误,但当运行和启动活动时,它给出的应用程序名称停止工作。在android清单中,我添加了internet权限。URL路径工作非常好,因为我直接将其放入浏览器中,它会给出所需的结果。我是android应用程序开发的新手。请帮助我,我在最后一年的项目中需要它。 StartingPoint.java

public class StartingPoint extends Activity implements OnClickListener {
Button  bed;

@Override
protected void onCreate(Bundle savedInstanceState) {

    setContentView(R.layout.activity_starting_point);

    inialize();



    bed.setOnClickListener(MenuListener);


}

private void inialize() {
    // TODO Auto-generated method stub

    bed = (Button) findViewById(R.id.bActivityBed);
    mirror = (Button) findViewById(R.id.bActivityMirror);
}


private OnClickListener MenuListener = new OnClickListener()  {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.bActivitySofa:
            Intent i = new Intent("com.example.pb.SOFA");
            startActivity(i);
            break;

        case R.id.bActivityChair:
            Intent chair = new Intent("com.example.pb.CHAIR");
            startActivity(chair);
            break;
        case R.id.bActivityBed:
            Intent bed = new Intent("com.example.pb.BED");
            startActivity(bed);
            break;
        case R.id.bActivityMirror:
            Intent mirror = new Intent("com.example.pb.MIRROR");
            startActivity(mirror);
            break;
        }
    }

};}
java((可能是导致问题的实际类))

公共课堂活动{
私人对话;
JSONParser jParser=新的JSONParser();
ArrayList productsList;
私有静态字符串url\u所有产品=”http://192.168.1.3/AndriodConnect/ReadProducts.php";
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
私有静态最终字符串TAG_PRODUCTS=“PRODUCTS”;
私有静态最终字符串标记_PID=“prodId”;
专用静态最终字符串标记_NAME=“prodName”;
JSONArray产品=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(右布局,床);
productsList=新的ArrayList();
新建LoadAllProducts().execute();
ListView lv=getListView();
lv.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//从选定的ListItem获取值
字符串pid=((TextView)view.findViewById(R.id.tvId)).getText()
.toString();
Intent in=新的Intent(getApplicationContext(),
沙发类);
in.putExtra(标签号PID,PID);
startActivityForResult(in,100);
}
});
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
//TODO自动生成的方法存根
super.onActivityResult(请求代码、结果代码、数据);
如果(结果代码==100){
Intent=getIntent();
完成();
星触觉(意向);
}
}
公共类LoadAllProducts扩展异步任务{
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
pDialog=新建进度对话框(Bed.this);
pDialog.setMessage(“加载产品.Plz等待”);
pDialog.setUndeterminate(假);
pDialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…args){
//TODO自动生成的方法存根
List params=new ArrayList();
JSONObject json=jParser.makeHttpRequest(url_all_products,“Get”,params);
Log.d(“所有产品”,json.toString());
试一试{
int success=json.getInt(TAG_success);
如果(成功==1){
products=json.getJSONArray(TAG_products);
对于(int i=0;i我使用了WAMP,因为“联机”必须签入通知,否则它无法连接。您应该在xamp中找到相同的内容。我切换到WAMP只是出于这个原因


Android和你的系统应该在同一个网络(WAN或LAN)中。

你遇到了什么错误?还有加载项清单,还有加载项清单我单击bed时没有错误。它给出的应用程序名称的java图标停止工作。发送信号。PID:22230 SIG:9Xamp服务器启动。
public class Bed extends ListActivity {
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> productsList;

private static String url_all_products="http://192.168.1.3/AndriodConnect/ReadProducts.php";

private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
private static final String TAG_PID = "prodId";
private static final String TAG_NAME = "prodName";

JSONArray products = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bed);

    productsList = new ArrayList<HashMap<String,String>>();

    new LoadAllProducts().execute();

    ListView lv = getListView();

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // getting values from selected ListItem
            String pid = ((TextView) view.findViewById(R.id.tvId)).getText()
                    .toString();

            Intent in = new Intent(getApplicationContext(),
                    Sofa.class);
            in.putExtra(TAG_PID, pid);
            startActivityForResult(in, 100);
        }
    });
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==100) {
        Intent intent = getIntent();
        finish();
        startActivity(intent);
    }
}
public class LoadAllProducts extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        pDialog = new ProgressDialog(Bed.this);
        pDialog.setMessage("Loading products.Plz wait");
        pDialog.setIndeterminate(false);
        pDialog.show();
    }
    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        JSONObject json = jParser.makeHttpRequest(url_all_products, "Get", params);
        Log.d("All products", json.toString());
        try {
            int success = json.getInt(TAG_SUCCESS);
            if(success == 1) {
                products = json.getJSONArray(TAG_PRODUCTS);
                for(int i=0; i<products.length();i++) {
                    JSONObject c = products.getJSONObject(i);
                    String id = c.getString(TAG_PID);
                    String name = c.getString(TAG_NAME);
                    HashMap<String,String> map = new HashMap<String,String>();
                    map.put(TAG_PID, id);
                    map.put(TAG_NAME, name);
                    productsList.add(map);
                }
            }
            }
            catch(JSONException e) {
                e.printStackTrace();
            }

        return null;
    }
    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        pDialog.dismiss();
        runOnUiThread(new Runnable() {
        public void run() { 

        ListAdapter adapter = new SimpleAdapter(Bed.this, productsList,
                R.layout.list_item,new String[] {TAG_PID,TAG_NAME},
                new int[] {R.id.tvId, R.id.tvName});
        setListAdapter(adapter);
        }
        });
    }

}

}
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;

}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".StartingPoint"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.STARTINGPOINT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Login"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.LOGIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Prefs"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.PREFS" />
           <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".AboutUs"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.ABOUTUS" />
           <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Sofa"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.SOFA" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
           <activity
        android:name=".Mirror"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.MIRROR" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
           <activity
        android:name=".Bed"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.BED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
           <activity
        android:name=".Chair"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.CHAIR" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
          <activity
        android:name=".AllProductsActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.pb.PRODUCTS" /> 
           <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
   </application>
</manifest>