【问题标题】:Illegal Argument Exception at query index 70查询索引 70 处的非法参数异常
【发布时间】:2013-05-02 08:02:25
【问题描述】:

我正在尝试使用与从编辑文本值发送的值相关的一些值来更新我的数据库字段... 我的代码是:

Intent myintent = getIntent();
//mdate = intent.getStringExtra("mdate");
//Toast.makeText(getApplicationContext(), mdate.toString(), Toast.LENGTH_LONG).show();
title=(EditText)findViewById(R.id.editText1);
Bundle extras = getIntent().getExtras();
if(extras != null){ 
    mtitle = extras.getString("title");
    stime = extras.getString("mtime");
    sdate = extras.getString("mdate");
    cvenue = extras.getString("venue");
}

title.setText(mtitle);
title.setFocusable(false);
cdate=(EditText)findViewById(R.id.editText2);
cdate.setText(sdate);
cdate.setFocusable(false);
venue=(EditText)findViewById(R.id.editText4);
venue.setText(cvenue);
venue.setFocusable(false);
ctime=(EditText)findViewById(R.id.editText3);
ctime.setText(stime);
ctime.setFocusable(false);
cnfrm=(Button)findViewById(R.id.button1);
cnfrm.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
          // TODO Auto-generated method stub
          try {
                 Toast.makeText(getApplicationContext(), "Befor", 
                         Toast.LENGTH_LONG).show();
         get= new HttpGet("http://10.0.2.2/meetingschedular/confirmmeet.php?
                       res="+resy.toString()+"&title="+title.getText().toString()+"&
                       venue="+venue.getText().toString()+"&cdate="+cdate.getText()
                       .toString()+"&ctime="+ctime.getText().toString()+"&
                       attend="+uid.toString());
                 client= new DefaultHttpClient();
                 res=client.execute(get);
         Toast.makeText(getApplicationContext(), "After res", 
                         Toast.LENGTH_LONG).show();
                 in = res.getEntity().getContent();
         StringBuffer str = new StringBuffer();
                 int ch;
                 while((ch=in.read())!=-1) {
                       str.append((char)ch);
                 }
                 String tmp=str.toString();
                 tmp=tmp.trim();
                 //txt.setText(tmp);
                 if(flag.equals(tmp)) {
                      Toast.makeText(getApplicationContext(), tmp, 
                                Toast.LENGTH_LONG).show();
                 } else {
                      Toast.makeText(getApplicationContext(), "Sorry cannot confirm", 
                              Toast.LENGTH_LONG).show();
                 }
           } catch(Exception e) {
               Toast.makeText(getApplicationContext(), e.toString(), 
                      Toast.LENGTH_LONG).show();
           }
     }
});

我的php代码:

 <?php 
$con=mysql_connect('localhost','root','');
mysql_select_db('meetingschedulardata',$con);
if(!$con)
{
die("can not connect".mysql_error());
}
$title=$_GET['title'];
$cdate=$_GET['cdate'];
$ctime=$_GET['ctime'];
$attend=$_GET['attend'];
$venue=$_GET['venue'];
$res=$_GET['res'];
$sdate = strtotime($cdate);
$new_date = date('Y-m-d', $sdate);
$stime = strtotime($ctime);
$new_time = date('h:i:s', $stime);
$order="Update meetingdetails SET status='$res' WHERE status IS NULL AND
         title='$title' AND mdate='$new_date' AND mtime='$new_time' AND
           attendees='$attend' AND venue='$venue'";
$result=mysql_query($order,$con);
if($result==1)
{
echo "true";
}
else{
echo "false".mysql_error();
}
mysql_close($con);
?>

每当我尝试点击我的确认按钮时,都会出现此错误..

我不知道我的错误到底在哪里。请帮助我。提前谢谢。

【问题讨论】:

  • 堆栈跟踪?出现错误的行?
  • 请向我们展示您打印的查询
  • 我想知道你想看的查询..我已经给出了我的 php 代码以及 java 代码..我不是你想要的 @ZouZou
  • 您的查询中 pos 70 的字符似乎有问题

标签: android http-post android-button http-get


【解决方案1】:

如日志:

IllegalArgumentException:查询中的非法字符

表示您在带有 URL 的 QueryString 中传递了错误的字符。在发出请求之前使用URLEncoder.encode作为编码参数。尝试如下:

String str_params=URLEncoder.encode(res="+resy.toString()+
                              "&title="+title.getText().toString()+
                              "&venue="+venue.getText().toString()+
                              "&cdate="+cdate.getText().toString()+
                              "&ctime="+ctime.getText().toString()+
                              "&attend="+uid.toString(),"UTF-8");
get= new HttpGet("http://10.0.2.2/meetingschedular/confirmmeet.php?"
                                                            +str_params); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多