Hallo allerseits!
Ich versuche mich gerade an einem Programm, dass u.A. aktuelle Kursdaten von Aktien über die API von Yahoo!Finance herunterlädt.
Leider bekomme ich in der Testklasse eine
[code=Java]Exception in thread "main" java.lang.NullPointerException
at test.DownloaderTest.<init>(DownloaderTest.java:22)
at test.DownloaderTest.main(DownloaderTest.java:30)[/code]
Hier der Code:
[code=Java]package test;
import java.util.Date;
import download.Downloader;
import stocks.Stock;
public class DownloaderTest {
/**
* @param args
*/
static Stock stock;
static Downloader download;
public DownloaderTest(){
stock = new Stock("test");
stock.setSymbolName("AB1.DE");
Double[] values;
values = download.loadWeekData(stock, 1, 1, 2012);
for(int i=0; i<values.length; i++){
System.out.println(values[i]);
}
}
public static void main(String[] args) {
DownloaderTest test = new DownloaderTest();
}
}[/code]
[code=Java]public Double[] loadWeekData(Stock stock, int day1, int month1, int year1) {
System.out.println("test");
Stock stock1 = stock;
long currentTime = (new Date()).getTime();
Double[] value = new Double[5];
try{
System.out.println("test1");
URL yahoofin = new URL("http://ichart.finance.yahoo.com/table.csv?s="
+ stock1.getSymbolName() + "&a="+(month1-1)+"&b="+ day1+"&c="+ year1 +
"&d="+ (month1-1) + "&e="+ (day1+5) + "&f="+year1+ "&g=d"+"&e=.cvs");
System.out.println("test2");
URLConnection yc = yahoofin.openConnection();
System.out.println("test3");
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
System.out.println("test4");
String inputLine;
String[] data2 = null;
while((inputLine = in.readLine()) != null){
String[] data = inputLine.split(",");
data2 = data;
}
in.close();
for(int i=0; i < data2.length; i++){
value[i] = Double.valueOf(data2[i]);
}
}catch (NumberFormatException ex) {
System.out.println("Number-Exception" + ex.getMessage());
}
catch (Exception ex) {
System.out.println("Unable to get stockinfo..." + ex.getMessage());
}
return value;
}[/code]
Das eigenartige ist, dass keiner der Teststrings ausgeben wird, geschweige denn eine Exception abgefangen wird. :bahnhof:
Ich bitte um Rat! Danke schonmal im Vorraus!