Android php mysql,不带日志操作



我做了一个应用程序:mysql <-> Android使用php。

I success to mysql with php

http://localhost/phptest/newfile.php

id: jogi - password: 1234

id: jogi1 - password: 12341

id: jogi2 - password: 12342

但是我在连接Android时有一些问题。

一些代码被忽略。并且不发送日志信息。安卓AVD也没有停止,但没有显示任何变化。控制台也没有显示错误…我能做什么?或者我如何检查错误?

MainActivity.java

package com.example.phpmysql;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
  private TextView result;
   @Override 
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);      
      result = (TextView)findViewById(R.id.text_view1);    
   }
   public void Show_list(View view){
       new SigninActivity(this,result,0).execute(); 
   }
}

SigninActivity.java

package com.example.phpmysql;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.TextView;
public class SigninActivity  extends AsyncTask<String,Void,String>{
   private TextView resultField; //statusField
   private int byGetOrPost = 0; 
   public SigninActivity(Context context,TextView resultField,int flag) {
      byGetOrPost = flag;
   }
   protected void onPreExecute(){
   }
   @Override
   protected String doInBackground(String... arg0) {
       String  myResult = null; //initiate;
      if(byGetOrPost == 0){ //means by Get Method
          Log.d("flag","0");
          try { 
              URL url = new URL("http://http://localhost/phptest/newfile.php");   
              HttpURLConnection http = (HttpURLConnection) url.openConnection();   
              Log.d("where","http connect");

              http.setDefaultUseCaches(false);                                            
              http.setDoInput(true);                         
              http.setDoOutput(true);                       
              http.setRequestMethod("POST");         
              http.setRequestProperty("content-type", "application/x-www-form-urlencoded"); 
              Log.d("where","property");
              //-------------------------- 
              InputStreamReader tmp = new InputStreamReader(http.getInputStream(), "EUC-KR");
              BufferedReader reader = new BufferedReader(tmp); 
              StringBuilder builder = new StringBuilder(); 
              String str;
              Log.d("where","inputstream");
              while ((str = reader.readLine()) != null) {       
                   builder.append(str + "n");                     
              } 
              myResult = builder.toString();                       
              Log.d("myresult",myResult);
             return myResult;
         } catch (MalformedURLException e) { 
                // 
         } catch (IOException e) { 
                //  
         } // try 
      }
      else{
      }
    return myResult;
   }
   @Override
   protected void onPostExecute(String result){
      if(result != null)
          this.resultField.setText(result);
      else
          Log.d("failed", "postfailed");
   }
}

这是我所有的日志。打开时只有一个错误,但我认为AVD连接良好,所以不重要。一个奇怪的事情是,我找不到标签"输入流"在SigninActivity.java;

08-16 07:31:48.603: E/Trace(772): error open Trace file: No such file or directory (2)

08-16 07:31:49.753: D/gralloc_金鱼(772):未检测到GPU仿真的模拟器。

08-16 07:32:55.214: D/flag(772): 0

08-16 07:32:55.224: D/where(772): http connect

08-16 07:32:55.224: D/where(772): property

08-16 07:32:55.417: D/failed(772): postfailed

应用程序启动时没有错误。如果点击"列表"按钮,没有错误,也没有停止,但没有任何改变视图。只有空白的屏幕。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginRight="26dp"
    android:layout_toLeftOf="@+id/button2"
    android:onClick="Show_list"
    android:text="@string/Show_List" />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/button1" >

    <TextView
        android:id="@+id/text_view1" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp" />
</LinearLayout>

你不是直接与mysql对话,你的android应用程序将收到来自web服务器的响应,所以你需要调用web服务器可访问的url。如果您是在本地网络中,请在

中提供web服务器本地地址
 URL url = new URL("http://{webserverURL}/phptest/newfile.php");

您可以使用ipconfig (Windows), ifconfig (linux)从安装apache的机器获取IP。

最新更新