Stiv i Java, simpel klasse interaktion
Jeg har to filer, den ene indeholder en klasse der kan regne downloadshastighed ud. Det skal test-filen så printe ud, men jeg har lidt problemer.test.java:
public class test
{
public static void main(String[] arg)
{
downloadSpeed a = new downloadSpeed(123, 123);
System.out.println("Test" + a.time['0']);
}
}
downloadSpeed.java:
import java.math.*;
public class downloadSpeed
{
public double usr_kbit; // Users connection to the net in KB/s
public double chars_pr_secs; // How many chars that can be transferred pr. second
public double file_size; // The size of the file the user wants to download
public double seconds; // How many seconds, is used temporarely to calculate the other values
public double time[];
downloadSpeed(double speed, double size)
{
usr_kbit = speed;
file_size = size;
chars_pr_secs = usr_kbit * 1024.0; // Calculate how many characters the user can download in seconds
file_size = Math.floor(file_size * 1024.0 * 1024.0); // Calculate how much bytes the download is
double time[] = new double[3];
seconds = file_size / chars_pr_secs;
time[0] = Math.floor(seconds / 3600.0); // hours
seconds = seconds - time[0] * 3600.0;
time[1] = Math.floor(seconds / 60.0); // minutes
time[2] = seconds - time[1] * 60.0; // seconds
}
public void output()
{
//Virkede egentligt ikke selvom jeg forventede det ville virke, nogen der vil give noget info heromkring?
//System.out.println("TID: " + this.time[0] + " hours, " + this.time[1] + " minutes, " + this.time[2] + " sekunder.");
//return time;
}
}
Fejlen er:
me@you ~/java $ java test
Exception in thread "main" java.lang.NullPointerException
at test.main(test.java:8)
