开发者

In my android application when two or more words are entered separated by space character it force closes!

There is an option to write reviews in my android application. it accepts a single word of any length, but it does not accept two or more words separated by a space character.it force closes when the submit button is pressed.plz help

why is this happening?the code for what happens when the submit button is clicked is given below:

public class WriteRev extends Activity {
EditText name;
EditText title;
EditText msg;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wr);
    msg=(EditText)findViewById(R.id.EditText03);
    title=(EditText)findViewById(R.id.EditText02);
    name=(EditText)findViewById(R.id.EditText01);
    Button b=(Button)findViewById(R.id.Button01);
     b.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            String Name=name.getText().toString();
            String Title=title.getText().toString();
            String Msg=msg.getText().toString();
            if(Name.equalsIgnoreCase("")|| Title.equalsIgnoreCase("") || Msg.matches("^[ ]*$")  )
            {
                Toast.makeText(WriteRev.this,"fields cannot be empty...", Toast.LENGTH_LONG).show();
            }
            else
            {


            String url="http://192.168.1.100:8080/finder/review/wr?name="+Name+"&title="+Title+"&message="+Msg+"&place="+Contents.id;
            Toast.makeText(getBaseContext(), "review added" , Toast.LENGTH_SHORT).show();
            JSONObject retData=RestClient.connect(url, WriteRev.this);
    /*      Intent k = new Intent();
            k.setClass(WriteRev.this, Contents.class);
            startActivity(k);*/

            }
        }
});

   Button b1=(Button)findViewById(R.id.Button02);
     b1.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent k = new Intent();
            k.setClass(WriteRev.this, Contents.class);
            startActivity(k);
        }
     });
}

}

the reported error from logcat is

06-17 12:15:36.403: WARN/KeyCharacterMap(372): No keyboard for id 0
06-17 12:15:36.403: WARN/KeyCharacterMap(372): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-17 12:15:38.694: DEBUG/dalvikvm(213): GC freed 243 objects / 14344 bytes in 104ms
06-17 12:15:52.794: INFO/NotificationService(58): enqueueToast pkg=com.lpss callback=android.app.ITransientNotification$Stub$Proxy@44db6998 duration=0
06-17 12:15:53.035: DEBUG/AndroidRuntime(372): Shutting down VM
06-17 12:15:53.044: WARN/dalvikvm(372): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-17 12:15:53.054: ERROR/AndroidRuntime(372): Uncaught handler: thread main exiting due to uncaught exception
06-17 12:15:53.093: ERROR/AndroidRuntime(372): java.lang.IllegalArgumentException: Illegal character in query at index 65: http://192.168.1.100:8080/finder/review/wr?name=shalini&title=hey whats up&message=nono n&place=null
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at java.net.URI.create(URI.java:970)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at com.lpss.RestClient.connect(RestClient.java:69)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at com.lpss.WriteRev$1.onClick(WriteRev.java:42)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.View.performClick(View.java:2364)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.View.onTouchEvent(View.java:4179)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.widget.TextView.onTouchEvent(TextView.java:6540)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.View.dispatchTouchEvent(View.java:3709)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.os.Looper.loop(Looper.java:123)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at android.app.ActivityThread.main(ActivityThread.ja开发者_StackOverflowva:4363)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at java.lang.reflect.Method.invokeNative(Native Method)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at java.lang.reflect.Method.invoke(Method.java:521)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-17 12:15:53.093: ERROR/AndroidRuntime(372):     at dalvik.system.NativeStart.main(Native Method)
06-17 12:15:53.114: INFO/Process(58): Sending signal. PID: 372 SIG: 3
06-17 12:15:53.124: INFO/dalvikvm(372): threadid=7: reacting to signal 3
06-17 12:15:53.154: INFO/dalvikvm(372): Wrote stack trace to '/data/anr/traces.txt'
06-17 12:17:24.804: DEBUG/dalvikvm(58): GC freed 21737 objects / 1032728 bytes in 222ms


you have replace space by "%20" because URL does not accept space character . use the following code

String url="http://192.168.1.100:8080/finder/review/wr?name="+Name.replace(" ", "%20")+"&title="+Title.replace(" ", "%20")+"&message="+Msg.replace(" ", "%20")+"&place="+Contents.id;


add this line before you send the JSON object.

url = URLEncoder.encode(url,"UTF-8");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜