getResourceAsStream() stops working when run online!

I have written an applet that I am hosting on a geocities website. The applet

runs fine in NetBeans, and locally fram an html file, but when I try to run the

applet online, the:

BufferedReader in=new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("One.txt")));

(it used to be "this.getClass().getResourceAsStream()", but after many

forum searches and revisions the above version still works in NetBeans

but not online)

line throws a NullPointerException because it cant find the file.

When I disable this line of code, the applet shows up just fine,

but has no functionality because it draws graphs of the information

found in the text file I am trying to read.

Everything is in the same directory, is this a problem with file permissions?

Or is it a problem with how getResourceAsStream() looks for files?

[1036 byte] By [mtb70mpha] at [2007-11-27 10:44:24]
# 1

Url url = getClass().getResource("/One.txt");

cotton.ma at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks for the reply, but its still not working =/

I did what you said

URL urll = getClass().getResource("/One.txt");

Then did this to get the inputstream

BufferedReader in= new BufferedReader(new InputStreamReader(urll.openStream()));

Any ideas?

mtb70mpha at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 3

>the applet shows up just fine,

Have you tried to use the apllet getCodeBase() method ?

http://java.sun.com/docs/books/tutorial/deployment/applet/data.html

java_2006a at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 4

All of the files are in the same directory though, I have already tried putting them in a subdirectory and using the codebase="foldername" part in the applet tag, but the same error results. I was thinking that this could be due to security measures on geocities (my applet isnt signed), but wouldn't that throw a SecurityException rather than a NullPointerException?

Thanks for all of the responses by the way =)

mtb70mpha at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 5

Is the file really called "One.txt"? It might be the case that it's called "one.txt" (note that the initial letter is lower case).

When running the code offline (locally) in a windows environment it will find "one.txt" when you request "One.txt". The web server that serves the file might not be as forgiving and tell you "There is no One.txt"!

JoachimSauera at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 6

Its "One.txt", with capitalization

mtb70mpha at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 7

Hm ... can you tell us exactly what the layout of your files is? Where is the .html-file, is your applet in a .jar-file? If so, where is it? Otherwise, where are your .class-files? How does the applet tag look like?

JoachimSauera at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 8

I am not using a jar at the moment, I was messing with that earlier and

was more complicated than it needed to be, I have all of the class files

for my buttons and such as well as the main applet class "Grapher.class"

and the class that reads the text file "GetStuff.class" in the main directory of

my geocities page, "www.geocities.com/bbubenheim/" and the applet tag in

the html is:

<applet code="Graph.class" height="600" width="1000">

</applet>

since everything is in the main directory and not jarred then there should be

no need for an "archive" or "codebase" part.

Should I try hosting it somewhere else? Or am I missing something?

mtb70mpha at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 9

try accessing "http://www.geocities.com/bbubenheim/One.txt".

For me this results in some error page, and since the Applet doesn't really do anything different from the browser it won't get the desired result as well. You need to figure out why geocities doesn't want to serve that file (and the solution might very well include switching to another hoster).

JoachimSauera at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 10

Oh ****, thats because I tried doing a JARConnection a few minutes ago

that involved reading 240 smaller portions of my .txt file, and I think the error

message results when geocities get freaked out by something trying to

access information 240 times in a second, I really dont like geocities i was just

using it because it is free, I'll try to host it somewhere else, thanks for the help,

is there anything I can try that is not host server-related?

mtb70mpha at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...
# 11

What the hell happened to this thread?

cotton.ma at 2007-7-28 20:06:39 > top of Java-index,Java Essentials,Java Programming...