Hi Leute!
Ich entwickle momentan ein kleines Arbeitszeitentool. Habe aber jetzt ne NullPointer und weiß nicht wieso.
Bin noch Anfänger in seinen Anfängen, also nicht schimpfen
Das ist die Exception:
Exception in thread "main" java.lang.NullPointerException
at de.worktimes.main.Calculation.calculateTime(Calculation.java:41)
at de.worktimes.main.Input.inputDataForCalculation(Input.java:41)
at de.worktimes.main.Main.main(Main.java:22)
Ich habe schon gedebuggt, verstehe aber einfach nicht, warum er die "null" statt dem eingegebenen Datum bzw. Uhrzeit übergibt.
Vielen Dank schonmal im Vorraus!
Ich entwickle momentan ein kleines Arbeitszeitentool. Habe aber jetzt ne NullPointer und weiß nicht wieso.
Bin noch Anfänger in seinen Anfängen, also nicht schimpfen
Java:
package de.worktimes.main;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
String again;
Input currentInput = new Input();
Times times = new Times("abc", "def", "ghi", "jkl", "mno", 2);
Scanner input = new Scanner(System.in);
do {
currentInput.inputChaseAtMenu();
if (currentInput.check.equals("1"))
{
currentInput.inputDataForCalculation();
}
else if (currentInput.check.equals("2")) {
for (int i = 0; i < times.list.size(); i = i + 1) {
System.out.println("Date: " + times.list.get(i).getdate()
+ " " + "Worked on this day: "
+ times.list.get(i).getFullWork() + "hours.");
}
}
else if (currentInput.check.equals("3")) {
Export export = new Export();
export.exportDataToTXT();
}
else if (currentInput.check.equals("4")) {
Export export = new Export();
export.exportDataToXml();
}
else if (currentInput.check.equals("5")) {
System.out.println("Thank you for using worktimes.");
System.exit(0);
}
else if (currentInput.check.equals("6")) {
Export export = new Export();
export.exportDataToMysql();
}
else
System.out.println("Incorrect entry!!!");
System.out.println("Go to main menu? (y/n)");
again = input.next();
} while (again.equals("y"));
System.out.println("Thank you for using worktimes.");
System.exit(0);
}
}
Java:
package de.worktimes.main;
import java.util.GregorianCalendar;
public class Calculation {
Input input = new Input();
//Times times = new Times(null, null, null, null, null, 0);
public void getDayOfWeek()
{
String[] splitDate = times.getdate().split("-");
int year = Integer.valueOf(splitDate[2]);
int month = Integer.valueOf(splitDate[1]);
int day = Integer.valueOf(splitDate[0]);
GregorianCalendar calendar = new GregorianCalendar(year, month, day);
int icurrDay = calendar.get(GregorianCalendar.DAY_OF_WEEK);
switch (icurrDay)
{
case 1: times.setCurrDay("Sunday");
case 2: times.setCurrDay("Monday");
case 3: times.setCurrDay("Tuesday");
case 4: times.setCurrDay("Wednesday");
case 5: times.setCurrDay("Thursday");
case 6: times.setCurrDay("Friday");
case 7: times.setCurrDay("Saturday");
}
}
public void calculateTime()
{
String[] splitStartTime = input.getSstartTime().split(":");
double startHour = Integer.valueOf(splitStartTime[0]).intValue();
double startMinute = Integer.valueOf(splitStartTime[1]).intValue();
double istartTime = startHour * 60 + startMinute;
String[] splitEndTime = input.getSendTime().split(":");
double endHour = Integer.valueOf(splitEndTime[0]).intValue();
double endMinute = Integer.valueOf(splitEndTime[1]).intValue();
double iendTime = endHour * 60 + endMinute;
String[] splitPauseStart = input.getSpauseStart().split(":");
double pauseStartHour = Integer.valueOf(splitPauseStart[0]).intValue();
double pauseStartMinute = Integer.valueOf(splitPauseStart[1])
.intValue();
double ipauseStart = pauseStartHour * 60 + pauseStartMinute;
String[] splitPauseEnd = input.getSpauseStart().split(":");
double pauseEndHour = Integer.valueOf(splitPauseEnd[0]).intValue();
double pauseEndMinute = Integer.valueOf(splitPauseEnd[1]).intValue();
double ipauseEnd = pauseEndHour * 60 + pauseEndMinute;
if (iendTime < istartTime) {
if (ipauseEnd < ipauseStart) {
input.setIfullWork( (((24 * 60) + iendTime - istartTime) - ((24 * 60) + (ipauseEnd - ipauseStart))) / 60);
}
else {
input.setIfullWork( (((24 * 60) + iendTime - istartTime) - (ipauseEnd - ipauseStart)) / 60);
}
}
else {
input.setIfullWork( ((iendTime - istartTime) - (ipauseEnd - ipauseStart)) / 60);
}
}
}
Java:
package de.worktimes.main;
import java.util.Scanner;
public class Input {
String sdate;
String sstartTime;
String sendTime;
String spauseStart;
String spauseEnd;
double ifullWork = 0;
String check;
String again;
Times currentTime = new Times(sdate, sstartTime, sendTime,
spauseStart, spauseEnd, ifullWork);
Scanner input = new Scanner(System.in);
public void inputDataForCalculation() {
do {
System.out.println("Enter the date: ");
setSdate(input.next());
System.out.print("Enter the check-in time: ");
sstartTime = input.next();
System.out.println("Enter the check-out time");
sendTime = input.next();
System.out.println("Please enter the start of the Pause");
spauseStart = input.next();
System.out.println("Please enter the end of the pause: ");
spauseEnd = input.next();
currentTime.list.add(currentTime);
Calculation calculation = new Calculation();
calculation.calculateTime();
calculation.getDayOfWeek();
System.out.println("You have worked on " + currentTime.currDay
+ " " + currentTime.getFullWork() + "hours.");
System.out.println("");
System.out.println("Check another date in? (y/n)");
again = input.next();
} while (again.equals("y"));
}
public void inputChaseAtMenu() {
System.out
.println("What do you want to do? Type in the requested topic."
+ "\n");
System.out.println("1.Enter worktime");
System.out.println("2.List all worktimes");
System.out.println("3.Export data as TXT");
System.out.println("4.Export data as XML");
System.out.println("5.Exit");
System.out.println("6.Export to MySQL Database");
check = input.next();
}
public String getSdate() {
return sdate;
}
public void setSdate(String sdate) {
this.sdate = sdate;
}
public String getSstartTime() {
return sstartTime;
}
public void setSstartTime(String sstartTime) {
this.sstartTime = sstartTime;
}
public String getSendTime() {
return sendTime;
}
public void setSendTime(String sendTime) {
this.sendTime = sendTime;
}
public String getSpauseStart() {
return spauseStart;
}
public void setSpauseStart(String spauseStart) {
this.spauseStart = spauseStart;
}
public String getSpauseEnd() {
return spauseEnd;
}
public void setSpauseEnd(String spauseEnd) {
this.spauseEnd = spauseEnd;
}
public double getIfullWork() {
return ifullWork;
}
public void setIfullWork(double ifullWork) {
this.ifullWork = ifullWork;
}
}
Das ist die Exception:
Exception in thread "main" java.lang.NullPointerException
at de.worktimes.main.Calculation.calculateTime(Calculation.java:41)
at de.worktimes.main.Input.inputDataForCalculation(Input.java:41)
at de.worktimes.main.Main.main(Main.java:22)
Ich habe schon gedebuggt, verstehe aber einfach nicht, warum er die "null" statt dem eingegebenen Datum bzw. Uhrzeit übergibt.
Vielen Dank schonmal im Vorraus!