No source code is available for type java.io.File; did you forget to inherit a required module?

1,716 views
Skip to first unread message

raghu prashanth k b

unread,
Mar 3, 2009, 3:38:01 AM3/3/09
to Google Web Toolkit
Hi...I am new to GWT and i'm trying to develop a small
application...but here i need to open a directory and count the no.of
files in it.......I'm doing it as follows:

File dir = new File(file);
String[] pages = dir.list();
int count = pages.length;

I have imported java.io.File but the GWT compiler gives me the
following error.....plz help....

No source code is available for type java.io.File; did
you forget to inherit a required module?

Shawn Brown

unread,
Mar 3, 2009, 11:57:04 AM3/3/09
to Google-We...@googlegroups.com
> I have imported java.io.File but the GWT compiler gives me the
> following error.....plz help....
>
>               No source code is available for type java.io.File; did
> you forget to inherit a required module?

How are you compiling?

shell script or ant build?

In either case, your .java file has imported the code but the build
script or ant build doesn't know where to find java.io.File. You'll
have to pass in the .jar location to the script or ant build file.

Isaac Truett

unread,
Mar 3, 2009, 12:02:49 PM3/3/09
to Google-We...@googlegroups.com
Doesn't matter. You won't be able to use java.io.File on the client.
You can't access the client's file system without using an Applet,
Flash, ActiveX, or other component to which the user has granted
permission.

Lothar Kimmeringer

unread,
Mar 3, 2009, 12:07:01 PM3/3/09
to Google-We...@googlegroups.com
raghu prashanth k b schrieb:

> Hi...I am new to GWT and i'm trying to develop a small
> application...but here i need to open a directory and count the no.of
> files in it.......I'm doing it as follows:
>
> File dir = new File(file);
> String[] pages = dir.list();
> int count = pages.length;

If you do that on the client-side of your application, you should
ask yourself, how you would do that with Javascript. If you can
come up with an answer (you can't without the use of signed applets
or other tweaks), the compiler can't either.

This is a question that has been answered so many times already
that searching for the error-message, in this group should bring
up a lot of results, including ways how to solve your problem
(that is dependent if you really want to have a file-list of the
files residing on the client-side or if you want ot list files
residing on the server-side).


Regards, Lothar

ginger_ninja

unread,
Mar 4, 2009, 4:38:30 AM3/4/09
to Google Web Toolkit
Hi Raghu,

The GWT compiler complains because it doesn't support the full range
of Java classes present in your run of the mill JRE. The reason for
this can be found in asking the question; "What does the GWT compiler
produce as output?". Answering this question yields a far more
pertinent question; "Where does the resulting JavaScript execute?".
The answer of course is the client's browser.

Knowing this, it's fairly safe to assume that if we can achieve the
same thing using pure JavaScript in the browser (i.e. we could port
our Java code to JavaScript) then it's possible with GWT. Given that a
browser has no native mechanism that supports file IO (besides perhaps
the file input tag) then it makes sense that there would be no File
class in GWT. The GWT developers know this and to this extent they've
exposed a great deal of base Java classes (primarily the java.lang
package) as native peers. This is relatively straight-forward for
things like String which can easily be wrapped with a Java class that
provides the expected API yet are manipulated underneath the covers
using standard JS string functions.

If you're ever unsure as to whether or not a native Java class is
supported in GWT you can always refer back to the JRE emulation
reference here: http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=RefJreEmulation

Regards,

Dave
Reply all
Reply to author
Forward
0 new messages