Results 1 to 5 of 5
- 07-30-2011, 10:35 PM #1
Senior Member
- Join Date
- Nov 2010
- Posts
- 150
- Rep Power
- 3
Why am I getting the error: Incompatible Type
So I am going through the Java tutorial on Oracle' site and I have hit another bump.
I cut out the unimportant part. The question is why am I getting the error: incompatible type:Java Code:import java.io.File; import java.io.*; import java.util.Date; public class Test { public static void main(String[] args) throws NullPointerException, IOException { //Testing the setLastModified() File e = new File("xanadu.txt").setLastModified(new Date().getTime()); } }
I copied this code from the tutorial after thinking that I typed it wrongly and somehow missed something.Java Code:----jGRASP exec: javac -g Test.java Test.java:66: error: incompatible types File e = new File("xanadu.txt").setLastModified(new Date().getTime()); ^ required: File found: boolean 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
Would you point me in the right direction please? Thanks!
- 07-30-2011, 10:50 PM #2
Read the API doc for the setLastModified() method. What does it return?
What is on the left side of the assignment operator?
Break your chained method calls up into single steps.
- 07-31-2011, 01:37 AM #3
Senior Member
- Join Date
- Nov 2010
- Posts
- 150
- Rep Power
- 3
Sweet. You're the man Norm. It worked. See code below.
I am now wondering what would be the way to chain the methods and get the desired result? The tutorial had it as one last, but There was no declaration, so I don't know the type on the left of the left hand side.Java Code:File e = new File("xanadu.txt"); boolean ex = e.setLastModified(new Date().getTime()); System.out.println(ex);
- 07-31-2011, 02:30 AM #4
I personally do NOT like chaining. It doesn't save you any execution time and it can be confusing and cause problems like you just had.what would be the way to chain the methods and get the desired result?
- 07-31-2011, 02:41 AM #5
Senior Member
- Join Date
- Nov 2010
- Posts
- 150
- Rep Power
- 3
Similar Threads
-
Incompatible type for method. Can't convert java.lang.String to char.
By renu in forum New To JavaReplies: 1Last Post: 07-27-2010, 06:01 PM -
incompatible types error
By magic in forum New To JavaReplies: 3Last Post: 06-02-2010, 04:58 PM -
Help in incompatible type JTextArea
By sj_420 in forum Advanced JavaReplies: 4Last Post: 04-15-2010, 03:00 AM -
> Operator cannot be applied error and return incompatible types error
By corney_16 in forum New To JavaReplies: 1Last Post: 03-10-2010, 01:53 PM -
Error: incompatible types, found: int required: boolean
By silvia in forum New To JavaReplies: 6Last Post: 10-08-2008, 08:09 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks