• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

IO Exception

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm trying to communicate with GPS receiver to get gps data(which is NMEA data) but i'm getting an ioException when i reads from inputStreem,
"java.io.IOException: could not receive bytes: some line error". could anyone help me, y i'm gettting line error while reading from inputStreem? ur immediate response wud be much appreciated.
Thanks in advance
Aamir
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does you inputstream code look similar to the following partial listing?
HttpConnection http = null;
InputStream iStrm = null;
...
// Create the connection
http = (HttpConnection) Connector.open(url);
...
iStrm = http.openInputStream();
int length = (int) http.getLength();
if (length != -1)
{
// Read data in one chunk
byte serverData[] = new byte[length];
iStrm.read(serverData);
str = new String(serverData);
}
else // Length not available...
{
ByteArrayOutputStream bStrm =
new ByteArrayOutputStream();

// Read data one character at a time
int ch;
while ((ch = iStrm.read()) != -1)
bStrm.write(ch);

str = new String(bStrm.toByteArray());
bStrm.close();
}
John Muchow
Author of : Core J2ME Technology and MIDP
 
Aamir Chaudhry
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, ur code is much similar to mine..... there are a no. of points which i want to mention; i'm using StreamConnection instead of httpConnection, 2ndly, as GPS is writing data continuously on serial port, so i'm reading data in chunks of 512 bytes periodically. the 1st time read works fine BUT when i try to read in 2nd attempt then it throws that IOException: couldn't read bytes: Serial Line Error.
waiting for ur reply.....
Aamir
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May I look at your code? :roll:
 
Aamir Chaudhry
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, following is the code that talks to GPS thru serial port and it works fine for me
Note: i'm using IBM's Web Sphere Deveice Developer
private void connect() {
int ch;
InputStreamReader isr;
StreamConnection srlConn;
private final String protocol = "comm:0;baudrate=4800;bitsperchar=8;stopbits=1;parity=none;autorts=on;autocts=on;blocking=on";

try {
if(srlConn == null)
srlConn = (StreamConnection) Connector.open(specs, access, false);
if(isr == null)
isr = new InputStreamReader(srlConn.openInputStream());
} catch(IOException e) {}

while(true) {
try{ch = isr.read();}
catch(IOException ioe) {
// if ioe error = serial error line error then Ignore and continue;
// else break;
}
// other code goes here
}
}

Aamir
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks like you're doing a fairly specialized project, good luck on finding someone here who has done that. On the other hand, I know that one of the nextel apps being sold right now features a midlet with a a GPS connection. you might want to talk to them.
FutureRoads
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic