Article View: borland.public.jbuilder.java.language
Article #8314getResourceAsStream() & ObjectInputStream()
From: Lars Thuring
Date: Thu, 29 Mar 2001 23:56
Date: Thu, 29 Mar 2001 23:56
50 lines
2173 bytes
2173 bytes
Hi list,
while moving a java app into a jar I run into problems when reading
serialized objects from a stream.
The commented lines were the original ones, which I swapped for
getResourceAsStream(). Now this throws an exception when run (even if
not in the JAR):
// FileInputStream source=null;
InputStream source=null; //NEW FOR JAR
ObjectInputStream ois=null;
LosDbEntry los = new LosDbEntry(scenario);
LosDbEntry newLos;
int count = 0;
int numToRead = 0;
try{
// source = new FileInputStream("los.db");
source = Map.class.getResourceAsStream("los.db"); //NEW FOR
JAR
ois = new ObjectInputStream(source); //Throws
exception..
The exception is:
java.lang.NullPointerException
at
java.io.ObjectInputStream.readFullyInternal(ObjectInputStream.java:1780)
at java.io.ObjectInputStream.bufferData(ObjectInputStream.java:1750)
at java.io.ObjectInputStream.readShort(ObjectInputStream.java:1935)
at
java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:842)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
at com.thuring.jasl.Map.loadLosDB(Map.java:251)
...
Any hints?
TIA,
Lars
Technical Details
Message-ID:
<3AC3CB9E.8DE996A6@t-online.de>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!news.tele.dk!194.213.69.151!news.algonet.se!algonet!newsfeed1.uni2.dk!newssuck.uni2.dk!dnews!217.87.107.122Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1bf224a5ac7c380a,start X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-29 16:36:02 PST Message-ID: <3AC3CB9E.8DE996A6@t-online.de> Date: Fri, 30 Mar 2001 01:56:15 +0200 From: Lars Thuring <thuring@t-online.de> X-Mailer: Mozilla 4.71 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: getResourceAsStream() & ObjectInputStream() Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 217.87.107.122 X-Trace: 29 Mar 2001 15:50:33 -0800, 217.87.107.122 Lines: 53 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!news.tele.dk!194.213.69.151!news.algonet.se!algonet!newsfeed1.uni2.dk!newssuck.uni2.dk!dnews!217.87.107.122