tags:

views:

291

answers:

5

no ':' in url exception am getting that exception when am trying to execute this fragment of code...

FileConnection conn;

try{
    conn =(FileConnection)Connector.open("/NewFile.xml");
    if(!conn.exists())
       conn.create();
    _screen.add(new RichTextField("Connection Established..."));
    _screen.add(new SeparatorField());

} catch(IOException ioe) {
       _screen.add(new RichTextField(ioe.getMessage()));
}

where /NewFile.xml is a xml file in my Project

A: 

A file access URL starts with "file://"...

DevSolar
+4  A: 

You have to write the path like

file:///NewFile.xml/

try{ 
conn =(FileConnection)Connector.open("file:///NewFile.xml/"); 
if(!conn.exists()) 
  conn.create(); 
_screen.add(new RichTextField("Connection Established...")); 
_screen.add(new SeparatorField());

}
catch(IOException ioe)
{
     _screen.add(new RichTextField(ioe.getMessage()));
}

Getting Started with fileconnection

Markus Lausberg
or, perhaps more convenienty, create a java.io.File object, then call toUrl() on that. It saves you having to muck about with obscure file URL syntax.
skaffman
Yes, it needs an absolute url, not a relative one.
Mercer Traieste
+1  A: 

Use File, and then toUrl()

Valentin Rocher
A: 

You do not need a file connection, but can read the data from jar directly by using input stream:

Class.getClass().getResourceAsStream("/NewFile.xml");
JaanusSiim
A: 

add prefix "http://" into your file path or url

Rakesh Soni