Archive for the 'Hamster Climb' Category

HttpURLConnection getInputStream FileNotFoundException

Hello Android/Java coders!

So I recently got some weird errors when doing http requests in my Android game Hamster Climb. I was trying to get the input stream from a HttpURLConnection but kept getting a FileNotFoundException even tho the URL worked perfectly in my desktop browser. Here’s an example, without error catching stuff, of how the code could look like:

String user = getUser();
String url = "http://somesite.com/page?user=" + user;
URL u = new URL(url);

HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setDoInput(true);
c.setDoOutput(true);
c.connect();

InputStream is = c.getInputStream();

The problem was that at the last line the call to getInputStream generated a FileNotFoundException. I printed the URL that was used and tried it in the browser. Worked prefectly.

I managed to solve it tho. The problem was that even tho creating a URL object with the built url string works, the url might be broken. For example, if user is “Some guy” the url will contain a space which is not valid. Browsers solve this by automatically replacing the space with %20 which is what my browser did.

To solve this in code you use the URLEncoder class’ static method encode. This method takes a string and encodes it to a string that is ok to put in a URL. So replacing

String url = "http://somesite.com/page?user=" + user;

with

String url = "http://somesite.com/page?user="
+ URLEncoder.encode(user, "UTF-8");

solves the problem when user contains illegal URL characters.

Hope this helps someone out there getting weird errors. 🙂

Hamster Climb site updates

Both here on this blog and over at the Hamster Climb site I’ve updated the information and screenshots of the game. The info now matches the currently released version and the new screenshots show more screens of the game. 🙂

Hamster Climb’s New Home

Hamster Climb now has it’s own web site! 😀 I have made pages for reporting problems with the game and for submitting suggestions.

Link

Hamster Climb 0.21

Woohoo! Hamster Climb just got a Global High Scores list! 😀 Now live on the market. 🙂

Hamster Climb

Android Market link

Yay! Finally my first Android game is up on the Android Market! 😀

Hamster Climb is a game where you control a hamster and your task is to jump on falling mail cargo to get as high up as possible.

The game starts out with only crates coming down. They are pretty big and easy to jump on. After that smaller packages start appearing and the vertical spacing between cargo start to increase. Now the birds start coming. When you jump on them your current score is doubled! Higher up letters start coming down. They fall like letters do, swaying back and forth which obviously makes them harder to jump on. All the while the number of crates dwindle and the letters start to behave more and more erratic, the vertical spacing between the cargo is still increasing and your finger is getting tired.

Will you beat my high scores? 😉


I am a student of Engineering Physics at Uppsala University and am currently working on my master's thesis. On this website I mostly write about my own programming projects.