Question: In my application i want to replace space with %20 in my string.I tried in this way,

```
String flag1="http://74.208.194.142/admin/upload_image/1342594079_images (2).jpg";
flag1.replaceAll("", "%20");

```

But it is not working please help me.I am getting null pointer exception.

Answer: 
You should do it like:

```
flag1 = flag1.replaceAll(" ", "%20");

```

first you were putting empty string instead of space..
and second you must return the value into the `flag1` variable..
```
    String flag1="http://74.208.194.142/admin/upload_image/1342594079_images (2).jpg";
    URI uri = null;
    try {
        uri = new URI(flag1.replaceAll(" ", "%20"));
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(uri);

```

The console will display output as 

`http://74.208.194.142/admin/upload_image/1342594079_images%20(2).jpg`