Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
yyhokenny
Posts: 38
Registered: ‎07-29-2008
My Device: Simulator

LineReader or readUTFnot functioning properly?

I am wondering if anyone can help me solve this mystery.  All I wanted to do is to open a stored text file and read the content.  I ended up settling on this solution (http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=2362&query.id=197...), which worked.  What I don't understand is why LineReader and readUTF for DataInputStream doesn't work.  I am use Eclipse JDE plug-in with JDE 4.5 API and simulate for testing.

 

Here's how I setup and use the lineReader:

InputStream in = fc.openInputStream();
System.out.println(lr.readLine());

 But nothing come out even though the file contain multiple lines of text.  (And there's nothing wrong with the file or access itself as the solution I used above worked.)

 

I also tried this and it also print nothing.

 

DataInputStream in = fc.openDataInputStream();
System.out.println(in.readUTF());

 Am I missing something fundamental?

 

 


 

 

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,649
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: LineReader or readUTFnot functioning properly?

For the first section, where are you instantiating the LineReader?

 

What behaviour are you seeing?  Does the method block, is an exception thrown or does it return an empty string/byte array?

 

Are you testing on a real BlackBerry handheld or using a BlackBerry Simulator?  What version of BlackBerry handheld software are you testing with?  You can find this under Options, About on the BlackBerry.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
yyhokenny
Posts: 38
Registered: ‎07-29-2008
My Device: Simulator

Re: LineReader or readUTFnot functioning properly?

Sorry about that... I forgot to copy this line:

LineReader lr = new LineReader(in);

 And it does throw a java.io.EOFException.

 

I don't have access to a physical device so I am testing it on the simulator that came with JDE 4.5. (BlackBerry Smartphone Simulator 2.9.0.52/ BlackBerry8300)

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,649
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: LineReader or readUTFnot functioning properly?

What are the details for the exception?  You can see them by doing a .toString call on the exception.

 

Has the BlackBerry simulator been configured to support a micro SD card?

 

How To - Use a computer file system as a microSD card
Article Number: DB-00654

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
yyhokenny
Posts: 38
Registered: ‎07-29-2008
My Device: Simulator

Re: LineReader or readUTFnot functioning properly?

There isn't really any detail (unless I am not monitoring the right output in debug.)  All the .toString call returns from the exception is "java.io.EOFException".

 

The file was injected on to the 8300-sdcard.dmp image file using winImage so I am not using the PC file system as the SD card.  Again, I was able to read the file using the alternate solution in the original post (namely, reading the inputStream into a ByteArrayOutputStream first, then convert the byteArrayOutputStream into byteArray and then into String.)  And the file is also readable using the Media browser in the simulator.  I just don't understand why readUTF or the lineReader won't work and I have to use the very convoluted IS->BAOS->BA->String way to read it.

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,649
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: LineReader or readUTFnot functioning properly?

What version of BlackBerry handheld software are you testing with?  You can find this under Options, About on the BlackBerry.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
yyhokenny
Posts: 38
Registered: ‎07-29-2008
My Device: Simulator

Re: LineReader or readUTFnot functioning properly?

Again, I am testing it using the simulator from the JDE4.5: (BlackBerry Smartphone Simulator 2.9.0.52/ BlackBerry8300).  May be I misunderstood what you mean by version of BlackBerry software.  Can you clarify?

 

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,649
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: LineReader or readUTFnot functioning properly?

I haven't been able to reproduce this.  In my testing LineReader only throws the EOFFileException when it actually reaches the end of the file.

 

Have you tried this with multiple files?  I created a file in Notepad that I tested with.  If you are seeing it with multiple files please post the code where you are reading the data using LineReader.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
amiejoye
Posts: 10
Registered: ‎10-16-2008
My Device: Not Specified

Re: LineReader or readUTFnot functioning properly?

I am having the same problem.  My LineReader is failing.  It continues to hit the last Exception and tell me there is "No schedule available". Any suggestions?

 

try { Class classs = Class.forName("com.rim.samples.device.studentinfodemo.StudentInfoDemoScreen"); InputStream streamsch = getClass().getResourceAsStream("/Data/CCData.txt"); if(streamsch != null) { LineReader lineReaderSch = new LineReader(streamsch); for(;;) { try { String linesch = new String(lineReaderSch.readLine()); int comma1sch = linesch.indexOf(','); String stdid = linesch.substring(0,comma1sch); int comma2sch = linesch.indexOf(',',comma1sch+1); String coursename = linesch.substring(comma1sch+1,comma2sch); int comma3sch = linesch.indexOf(',',comma2sch+1); String dateenrolled = linesch.substring(comma2sch+1,comma3sch); int comma4sch = linesch.indexOf(',',comma3sch+1); String dateleft = linesch.substring(comma3sch+1,comma4sch); int comma5sch = linesch.indexOf(',',comma4sch+1); String expression = linesch.substring(comma4sch+1,comma5sch); int comma6sch = linesch.indexOf(',',comma5sch+1); String tchrlast = linesch.substring(comma5sch+1,comma6sch); String termid = linesch.substring(comma6sch + 1, linesch.length()); if (stdid == student.getStudentID()) { BasicEditField expressionField = new BasicEditField("Period: ", expression, 20, Field.FOCUSABLE); add(expressionField); } } catch(EOFException eof) { // We've reached the end of the file. break; } catch(IOException ioe) { System.out.println("Error reading data from file"); break; } } } else { System.out.println("Could not find resource"); } } catch(Exception ex) { String nosched = new String(); BasicEditField noschedField = new BasicEditField("No schedule available", nosched, 20, Field.FOCUSABLE); add(noschedField); }

 

Please use plain text.