0

我在尝试执行以下操作时遇到了 URISyntaxException 异常。我完全不知道是什么导致了这个问题。能得到一些帮助会很好。错误位于最后一行

    EditText edUserName = (EditText)findViewById(R.id.textBox_username_register);
    String strUsernameTemp = edUserName.getText().toString();
    byte[] byteUsernameTemp = null;
    try
    {
        byteUsernameTemp = strUsernameTemp.getBytes("UTF-8");
    }
    catch(UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }
    String strUsername = Base64.encodeToString(byteUsernameTemp, Base64.DEFAULT);

    EditText edPassword = (EditText)findViewById(R.id.passwordBox_password_register);
    String strPasswordTemp = edPassword.getText().toString();
    byte[] bytePasswordTemp = null;     
    try
    {
        bytePasswordTemp = strPasswordTemp.getBytes("UTF-8");
    }
    catch(UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }
    String strPassword = Base64.encodeToString(bytePasswordTemp, Base64.DEFAULT);       

    EditText edEmail = (EditText)findViewById(R.id.textBox_email_register);
    String strEmailTemp = edEmail.getText().toString();
    byte[] byteEmailTemp = null;
    try
    {
        byteEmailTemp = strEmailTemp.getBytes("UTF-8");
    }
    catch(UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }       
    String strEmail = Base64.encodeToString(byteEmailTemp, Base64.DEFAULT);     

    String strD = "22";
    String strM = "11";
    String strY = "1993";
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();        
    HttpGet httpget = new HttpGet(loginData.strAPIURL + "addUser&username=" + strUsername + "&password=" + strPassword + "&email=" + strEmail + "&d=" + strD + "&m=" + strM + "&y=" + strY); // this line causes the error
4

1 回答 1

0

URISyntaxException如果在创建 URI 时无法解析某些信息,通常会抛出此错误。尝试URI使用URLEncoder.

String encodedURI = java.net.URLEncoder.encode(loginData.strAPIURL + "addUser&username=" + strUsername + "&password=" + strPassword + "&email=" + strEmail + "&d=" + strD + "&m=" + strM + "&y=" + strY,"UTF-8");
HttpGet httpget = new HttpGet(encodedURI);
于 2013-04-09T11:42:37.013 回答