Android java.lang.IllegalArgumentException:索引56处查询中的非法字符

Android java.lang.IllegalArgumentException:索引56处查询中的非法字符,android,eclipse,Android,Eclipse,这是运行代码后导致的错误 03-13 16:43:00.901: E/AndroidRuntime(18994): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 03-13 16:43:00.901: E/AndroidRuntime(18994): at java.lang.Thread.run(Thread.java:841) 03-13 16:43:00.90

这是运行代码后导致的错误

03-13 16:43:00.901: E/AndroidRuntime(18994):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-13 16:43:00.901: E/AndroidRuntime(18994):    at java.lang.Thread.run(Thread.java:841)
03-13 16:43:00.901: E/AndroidRuntime(18994): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 56: http://suprabha.orgfree.com/ecg/temp.php?name=10&temper=   31,w=t
03-13 16:43:00.901: E/AndroidRuntime(18994):    at java.net.URI.create(URI.java:727)
03-13 16:43:00.901: E/AndroidRuntime(18994):    at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
03-13 16:43:00.901: E/AndroidRuntime(18994):    at com.example.mobilehealthcare.Temperature$DownloadWebPageTask.doInBackground(Temperature.java:271)
03-13 16:43:00.901:E/AndroidRuntime(18994):在java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-13 16:43:00.901:E/AndroidRuntime(18994):在java.lang.Thread.run(Thread.java:841)
03-13 16:43:00.901:E/AndroidRuntime(18994):原因:java.lang.IllegalArgumentException:索引56处的查询中存在非法字符:http://suprabha.orgfree.com/ecg/temp.php?name=10&temper=   31,w=t
03-13 16:43:00.901:E/AndroidRuntime(18994):位于java.net.URI.create(URI.java:727)
03-13 16:43:00.901:E/AndroidRuntime(18994):位于org.apache.http.client.methods.HttpGet.(HttpGet.java:75)
03-13 16:43:00.901:E/AndroidRuntime(18994):在com.example.mobilehealthcare.Temperature$downloadWebPagetTask.doInBackground(Temperature.java:271)
java文件

package com.example.mobilehealthcare;


public class Temperature extends Activity {

    private static final String TAG = "bluetooth2";
     Button btnOn, btnOff;
      TextView txtArduino;
      Handler h;
      private GraphView mGraph;
      final int RECIEVE_MESSAGE = 1;        // Status  for Handler
      private BluetoothAdapter btAdapter = null;
      private BluetoothSocket btSocket = null;
      private StringBuilder sb = new StringBuilder();

      private ConnectedThread mConnectedThread;

      // SPP UUID service
      private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

      // MAC-address of Bluetooth module (you must edit this line)
     // private static String address = "00:12:09:29:42:57";

     // private static String address = "00:15:83:15:A3:10";

     // private static String address = "20:13:07:12:04:17";

      String sdop = "";
      String pd = "";

      String s1,sa,s1nom,sakom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_temperature);

        SharedPreferences pre = getSharedPreferences("pref", 0);
        s1 = pre.getString("savedDatasd", "10");
        s1nom = pre.getString("savedDatad", "10");

         mGraph = (GraphView)findViewById(R.id.grap);
         txtArduino = (TextView)findViewById(R.id.texView1);

            mGraph.setMaxValue(1024);
            h = new Handler() {
                public void handleMessage(android.os.Message msg) {
                    switch (msg.what) {
                    case RECIEVE_MESSAGE:                                                   // if receive massage
                        byte[] readBuf = (byte[]) msg.obj;
                        String strIncom = new String(readBuf, 0, msg.arg1);                 // create string from bytes array

                        sb.append(strIncom);                                                // append string
                       // int endOfLineIndex = sb.indexOf("\r\n");                            // determine the end-of-line
                        int endOfLineIndex = sb.indexOf("/"); 
                        if (endOfLineIndex > 0) {                                            // if end-of-line,
                            String sbprint = sb.substring(0, endOfLineIndex);               // extract string
                            Toast.makeText(getApplicationContext(), "received message"+"----"+sbprint, 30).show();
                            sb.delete(0, sb.length());                                      // and clear
                            txtArduino.setText(sbprint);            // update TextView
                           // final int s = Integer.parseInt(sbprint);
                           //   mGraph.addDataPoint(s);
                            sdop+= txtArduino.getText().toString()+","; 
                        }

                        break;
                    }
                };
            };

            btAdapter = BluetoothAdapter.getDefaultAdapter();       // get Bluetooth adapter
            checkBTState();

    }

    public void tyre(View v)
    {
        mConnectedThread.write("t"); 
        Toast.makeText(this, "waid for values to be received", Toast.LENGTH_SHORT).show();
    }
     private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {
          if(Build.VERSION.SDK_INT >= 10){
              try {
                  final Method  m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class });
                  return (BluetoothSocket) m.invoke(device, MY_UUID);
              } catch (Exception e) {
                  Log.e(TAG, "Could not create Insecure RFComm Connection",e);
              }
          }
          return  device.createRfcommSocketToServiceRecord(MY_UUID);

    }

      @Override
      public void onResume() {
        super.onResume();

        Log.d(TAG, "...onResume - try connect...");

        // Set up a pointer to the remote node using it's address.
        BluetoothDevice device = btAdapter.getRemoteDevice(s1);

        // Two things are needed to make a connection:
        //   A MAC address, which we got above.
        //   A Service ID or UUID.  In this case we are using the
        //     UUID for SPP.

        try {
            btSocket = createBluetoothSocket(device);
        } catch (IOException e) {
            errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + ".");
        }

        // Discovery is resource intensive.  Make sure it isn't going on
        // when you attempt to connect and pass your message.
        btAdapter.cancelDiscovery();

        // Establish the connection.  This will block until it connects.
        Log.d(TAG, "...Connecting...");
        try {
          btSocket.connect();
          Log.d(TAG, "....Connection ok...");
        } catch (IOException e) {
          try {
            btSocket.close();
          } catch (IOException e2) {
            errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + ".");
          }
        }

        // Create a data stream so we can talk to server.
        Log.d(TAG, "...Create Socket...");

        mConnectedThread = new ConnectedThread(btSocket);
        mConnectedThread.start();
      }

      @Override
      public void onPause() {
        super.onPause();

        SharedPreferences preferences = getSharedPreferences("pref", 0);
        SharedPreferences.Editor editor = preferences.edit();

        //"savedData" is the key that we will use in onCreate to get the saved data
        //mDataString is the string we want to save
       // editor.putString("savedDatasd", sa);
      //  editor.putString("savedDatad", sakom); 


        // commit the edits
        editor.commit();
        Log.d(TAG, "...In onPause()...");

        try     {
          btSocket.close();
        } catch (IOException e2) {
          errorExit("Fatal Error", "In onPause() and failed to close socket." + e2.getMessage() + ".");
        }
      }

      private void checkBTState() {
        // Check for Bluetooth support and then check to make sure it is turned on
        // Emulator doesn't support Bluetooth and will return null
        if(btAdapter==null) {
          errorExit("Fatal Error", "Bluetooth not support");
        } else {
          if (btAdapter.isEnabled()) {
            Log.d(TAG, "...Bluetooth ON...");
          } else {
            //Prompt user to turn on Bluetooth
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, 1);
          }
        }
      }

      private void errorExit(String title, String message){
        Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show();
        finish();
      }

      private class ConnectedThread extends Thread {
            private final InputStream mmInStream;
            private final OutputStream mmOutStream;

            public ConnectedThread(BluetoothSocket socket) {
                InputStream tmpIn = null;
                OutputStream tmpOut = null;

                // Get the input and output streams, using temp objects because
                // member streams are final
                try {
                    tmpIn = socket.getInputStream();
                    tmpOut = socket.getOutputStream();
                } catch (IOException e) { }

                mmInStream = tmpIn;
                mmOutStream = tmpOut;
            }

            public void run() {
                byte[] buffer = new byte[256];  // buffer store for the stream
                int bytes; // bytes returned from read()

                // Keep listening to the InputStream until an exception occurs
                while (true) {
                    try {
                        // Read from the InputStream
                        bytes = mmInStream.read(buffer);        // Get number of bytes and message in "buffer"
                        h.obtainMessage(RECIEVE_MESSAGE, bytes, -1, buffer).sendToTarget();     // Send to message queue Handler
                    } catch (IOException e) {
                        break;
                    }
                }
            }

            /* Call this from the main activity to send data to the remote device */
            public void write(String message) {
                Log.d(TAG, "...Data to send: " + message + "...");
                byte[] msgBuffer = message.getBytes();
                try {
                    mmOutStream.write(msgBuffer);
                } catch (IOException e) {
                    Log.d(TAG, "...Error data send: " + e.getMessage() + "...");    
                  }
            }
        }

      public void bus(View v)
      {
          Intent jkl = new Intent(this,Select.class);
          startActivity(jkl);
          finish();
      }

      private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
            @Override
            protected String doInBackground(String... urls) {
                String response = "";
                for (String url : urls) {
                    DefaultHttpClient client = new DefaultHttpClient();
                    HttpGet httpGet = new HttpGet(url);
                    try {
                        HttpResponse execute = client.execute(httpGet);
                        InputStream content = execute.getEntity().getContent();

                        BufferedReader buffer = new BufferedReader(
                                new InputStreamReader(content));
                        String s = "";
                        while ((s = buffer.readLine()) != null) {
                            response += s;
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                return response;
            }

            @Override
            protected void onPostExecute(String result) {

                //msg.setText(result);
                if (result.contains("success")) {

                    Toast.makeText(getApplicationContext(), "Values are isent to Doctor", 30).show();

                }else{Toast.makeText(getApplicationContext(), "Values are not sent to Doctor", 30).show();}

            }
        }

      public void sav(View v)
      {
        String e = "t";


            DownloadWebPageTask task = new DownloadWebPageTask();

            task.execute(new String[] { "http://suprabha.orgfree.com/ecg/temp.php?name="+s1nom+"&temper="+sdop+"w="+e });
      }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.temperature, menu);
        return true;
    }

}
package com.example.mobilehealthcare;
公共课活动{
私有静态最终字符串TAG=“bluetooth2”;
按钮btnOn,btnOff;
TextView-txtArduino;
处理程序h;
私人图形视图经理;
final int receive_MESSAGE=1;//处理程序的状态
私有蓝牙适配器btAdapter=null;
私有BluetoothSocket btSocket=null;
私有StringBuilder sb=新StringBuilder();
私有连接线程mConnectedThread;
//SPP UUID服务
私有静态最终UUID MY_UUID=UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”);
//蓝牙模块的MAC地址(您必须编辑此行)
//私有静态字符串地址=“00:12:09:29:42:57”;
//私有静态字符串地址=“00:15:83:15:A3:10”;
//私有静态字符串地址=“20:13:07:12:04:17”;
字符串sdop=“”;
字符串pd=“”;
字符串s1、sa、s1nom、sakom;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、活动和温度);
SharedReferences pre=getSharedReferences(“pref”,0);
s1=pre.getString(“savedDatasd”,“10”);
s1nom=pre.getString(“savedDatad”,“10”);
mGraph=(GraphView)findViewById(R.id.grap);
txtArduino=(TextView)findViewById(R.id.texView1);
管理器设置最大值(1024);
h=新处理程序(){
public void handleMessage(android.os.Message msg){
开关(msg.what){
案例接收信息://如果接收按摩
字节[]readBuf=(字节[])msg.obj;
String strIncom=新字符串(readBuf,0,msg.arg1);//从字节数组创建字符串
sb.append(strIncom);//追加字符串
//int endoflindex=sb.indexOf(“\r\n”);//确定行的结尾
int endoflindex=sb.indexOf(“/”);
如果(endOfLineIndex>0){//如果行尾,
String sbprint=sb.子字符串(0,endoflindex);//提取字符串
Toast.makeText(getApplicationContext(),“已接收消息”+“----”+sbprint,30).show();
sb.delete(0,sb.length());//并清除
txtArduino.setText(sbprint);//更新文本视图
//final int s=Integer.parseInt(sbprint);
//经理添加数据点;
sdop+=txtArduino.getText().toString()+“,”;
}
打破
}
};
};
btAdapter=BluetoothAdapter.getDefaultAdapter();//获取蓝牙适配器
checkBTState();
}
公用轮胎(视图五)
{
mConnectedThread.write(“t”);
Toast.makeText(这是“waid for value to received”,Toast.LENGTH_SHORT.show();
}
私有BluetoothSocket createBluetoothSocket(BluetoothDevice设备)引发IOException{
如果(Build.VERSION.SDK_INT>=10){
试一试{
最后一个方法m=device.getClass().getMethod(“CreateSecurerCommsocketToServiceRecord”,新类[]{UUID.Class});
return(BluetoothSocket)m.invoke(device,MY_UUID);
}捕获(例外e){
Log.e(标记“无法创建不安全的RFComm连接”,e);
}
}
返回设备.createrFComSocketToServiceRecord(我的UUID);
}
@凌驾
恢复时公开作废(){
super.onResume();
Log.d(标记“…恢复-尝试连接…”);
//使用远程节点的地址设置指向该节点的指针。
BluetoothDevice=btAdapter.getRemoteDevice(s1);
//建立连接需要两件事:
//上面我们看到的MAC地址。
//服务ID或UUID。在本例中,我们使用
//用于SPP的UUID。
试一试{
btSocket=createBluetoothSocket(设备);
}捕获(IOE异常){
errorExit(“致命错误”,“在onResume()和套接字创建中失败:“+e.getMessage()+”);
}
//发现是资源密集型的。请确保它不会继续进行
//当您尝试连接并传递消息时。
btAdapter.cancelDiscovery();
//建立连接。这将阻止,直到连接为止。
Log.d(标记“…连接…”);
试一试{
btSocket.connect();
Log.d(标记“…连接正常…”);
}捕获(IOE异常){
试一试{
btSocket.close();
}捕获(IOE2异常){
public class Register extends Activity {

EditText a,b,c,d,e,f,g;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    a = (EditText) findViewById(R.id.editname1);
    b = (EditText) findViewById(R.id.editpas1);
    c = (EditText) findViewById(R.id.age);
    d = (EditText) findViewById(R.id.editph1);
    e = (EditText) findViewById(R.id.editadd1);
    f = (EditText) findViewById(R.id.editem1);
    g = (EditText) findViewById(R.id.dph);




}

private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        String response = "";
        for (String url : urls) {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try {
                HttpResponse execute = client.execute(httpGet);
                InputStream content = execute.getEntity().getContent();

                BufferedReader buffer = new BufferedReader(
                        new InputStreamReader(content));
                String s = "";
                while ((s = buffer.readLine()) != null) {
                    response += s;
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return response;
    }

    @Override
    protected void onPostExecute(String result) {

        //msg.setText(result);
        if (result.contains("success")) {
            Intent i2 = new Intent(getApplicationContext(), Login.class);
            //i.putExtra("id",na);
            startActivity(i2);
        }else{Toast.makeText(getApplicationContext(), result, 30).show();}

    }
}

public void insert(View v)
{
    String h,i,j,k,l,m,n;
    h = a.getText().toString();
    i = b.getText().toString();
    j = c.getText().toString();
    k = d.getText().toString();
    l = e.getText().toString();
    m = f.getText().toString();
    n = g.getText().toString();

    DownloadWebPageTask task = new DownloadWebPageTask();

    task.execute(new String[] { "http://suprabha.orgfree.com/ecg/regis.php?name="+h+"&pass="+i+"&age="+j+"&ph="+k+"&addr="+l+"&em="+m+"&docph="+n });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.register, menu);
    return true;
}

}
URLEncoder.encode(url, "UTF-8");
HttpGet httpGet = new HttpGet(URLEncoder.encode(url, "UTF-8"));