I'm developing a foreign exchange rate app that downloads data from a specific url and then search for a string that contains an ISO code that identifies each currency and its value in another currency. I've developed this in python, but I'm trying to port it to Java and subsequently to Android.
Python Code: Using urllib(2)
Code: Select all
import urllib
import urllib2
from urllib import urlencode
from urllib2 import urlopen
from encodings import utf_8
import os
pg = urlopen("http://rss.timegenie.com/forex.txt")
text = pg.read().decode("utf8")
usd = text.find('USD')
start_of_priceusd = usd + 25
end_of_priceusd = start_of_priceusd + 6
priceusd = float(text[start_of_priceusd:end_of_priceusd])
.
.
.So far I've written this in standard Java:
Code: Select all
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL curr = new URL("hhttp://rss.timegenie.com/forex.txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(
curr.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}Code: Select all
List<Float> priceList = new ArrayList<Float>();
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
String usd = inputline.substring(inputline.indexOf("USD")+25,inputline.length);
Float f = Float.valueOf(usd);
priceList.add(f);
}
in.close();
return priceList; Code: Select all
Exception in thread "main" java.lang.NullPointerException
at URLReader.main(URLReader.java:18)Sorry for my English.
Advertising

