getResourceAsStream(file), j2me  
Author Message
Rafal Suchowirski





PostPosted: 2005-2-21 4:07:00 Top

java-programmer, getResourceAsStream(file), j2me hi

i'm writing a program for mobile phone, and i use
getResourceAsStream(String)
when i use:
readFile("/data/file/1");
i can read file, but when i use
readFile("/data/file/"+randomINT);
i get error
java.lang.NullPointerException
but the file exist...:(

it's my code

public final Enumeration readFile(String s) {
Vector v = new Vector();
try {
InputStream in = this.getClass().getResourceAsStream("/res/"+s);
StringBuffer data = new StringBuffer();
/*.....
.....*/
} catch (Exception _e) { _e.printStackTrace();}
return v.elements();
}

What could be wrong?
 
Darryl Pierce





PostPosted: 2005-2-21 8:35:00 Top

java-programmer >> getResourceAsStream(file), j2me Rafal Suchowirski wrote:
> i'm writing a program for mobile phone, and i use
> getResourceAsStream(String)
> when i use:
> readFile("/data/file/1");
> i can read file, but when i use
> readFile("/data/file/"+randomINT);
> i get error
> java.lang.NullPointerException
> but the file exist...:(

What is the value of "randomINT" at the above point where it's used?

> it's my code
>
> public final Enumeration readFile(String s) {
> Vector v = new Vector();
> try {
> InputStream in = this.getClass().getResourceAsStream("/res/"+s);

Does your jar actually have a directory called "/res" and does it
contain a file whose name matches the value of "s" i the above code
snippet?

> What could be wrong?

Any of a number of things:

o the directory /res isn't in the JAR file
o the directory's there but doesn't contain a file whose name matches
the value of s
o the value of s is empty or null

--
Darryl L. Pierce <email***@***.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard
 
Rafal Suchowirski





PostPosted: 2005-2-21 14:34:00 Top

java-programmer >> getResourceAsStream(file), j2me Darryl Pierce napisa?a):
>> i'm writing a program for mobile phone, and i use
>> getResourceAsStream(String)
>> when i use:
>> readFile("/data/file/1");
now i use readFile("1");

>> i can read file, but when i use
>> readFile("/data/file/"+randomINT);
and readFile(randomINT);
where randomINT is a random numer from 1 to 20

>> i get error
>> java.lang.NullPointerException
>> but the file exist...:(


>
>> it's my code
>>
>> public final Enumeration readFile(String s) {
>> Vector v = new Vector();
>> try {
>> InputStream in = this.getClass().getResourceAsStream("/res/"+s);
>
>
> Does your jar actually have a directory called "/res" and does it
> contain a file whose name matches the value of "s" i the above code
> snippet?
>

yes, it has directory called /res and contain files
/res/1
...
/res/20


>> What could be wrong?
>
> Any of a number of things:
>
> o the directory /res isn't in the JAR file
> o the directory's there but doesn't contain a file whose name matches
> the value of s
> o the value of s is empty or null
JAR file has /res directory and contain files
and i can open file from /res
when i use String that it's known before compiling midlet

but when i use randomINT (when value isn't known before compiling)
it fails

System.out.println(""+s);
print value of s and it's in /res directory



 
 
Darryl Pierce





PostPosted: 2005-2-21 21:13:00 Top

java-programmer >> getResourceAsStream(file), j2me Rafal Suchowirski wrote:
> Darryl Pierce napisa?a):
>
>>> i'm writing a program for mobile phone, and i use
>>> getResourceAsStream(String)
>>> when i use:
>>> readFile("/data/file/1");
<snip>

> JAR file has /res directory and contain files
> and i can open file from /res
> when i use String that it's known before compiling midlet

Your readFile method in the above example is using "/data/file" and not
"/res". Is that your problem?

--
Darryl L. Pierce <email***@***.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard