Reputation: 146
just want to add all the variables in a "Performer-object" an add it to a list afterwards. So i have the class "Performer" and if i want to initialize a object would be like:
Performer a = new Performer("Red Hot Chili Peppers", Kind.Punk, LocalDateTime.of(2015, 07, 17, 14, 00), LocalDateTime.of(2015, 07, 17, 16, 00) , Stage.MainStage)
Also have a method addBand with the part:
System.out.println("End:");
sc.nextLine();
sc.findInLine("(\\d\\d)\\.(\\d\\d)\\. (\\d\\d):(\\d\\d)");
try{
MatchResult mr =sc.match();
int month = Integer.parseInt(mr.group(2));
int day = Integer.parseInt(mr.group(1));
int hour = Integer.parseInt(mr.group(3));
int minute = Integer.parseInt(mr.group(4));
LocalDateTime end = LocalDateTime.of(year, month, day, hour, minute);
//System.out.println(end);
} catch (IllegalStateException e)
{
System.err.println("Invalid input!");
}
Performer performer = new Performer(bandname, kind, start, end , stage);
listperformer.add(performer);
return listperformer;
Turns out, that eclipse says: "end cannot be resolved to a varialbe" Same code for end i do have for start, so same error here. I have no clue wheres the problem.
Upvotes: 0
Views: 1255
Reputation: 524
You declare the end
variable inside the try
block, but you access it outside the block. This give you the error that the end
variable cannot be resolved.
The other thing is, I also didn't see where you define the year
variable. This also will give you the same error.
Upvotes: 0
Reputation: 1067
end variable is declare inside the try block so it can't be used outside the try block.
declare it outside of try block and initialize this inside try block.
LocalDateTime end = null;
try{
MatchResult mr =sc.match();
int month = Integer.parseInt(mr.group(2));
int day = Integer.parseInt(mr.group(1));
int hour = Integer.parseInt(mr.group(3));
int minute = Integer.parseInt(mr.group(4));
end = LocalDateTime.of(year, month, day, hour, minute);
//System.out.println(end);
} catch (IllegalStateException e){
System.err.println("Invalid input!");
}
Performer performer = new Performer(bandname, kind, start, end , stage);
listperformer.add(performer);
return listperformer;
Upvotes: 1