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

Web and WebWorks Development

Reply
Developer
Posts: 61
Registered: ‎06-01-2009
My Device: Not Specified
Accepted Solution

How to show javascript error in simulator?

Hi, I meet several problem in the developing using webwork.

 

I have use Blackberry webwork in eclipse plugin to develop the program, my simulator is 9800 6.0.0.337.

 

I meet the problem when I try to load its pin number and file read / write.

 

var pin = blackberry.identity.PIN;

 

The file read/write sample I have directly copy from the sample code download in Blackberry.com. 

Both of them does not work. I want to use try{ }catch(err){ } to alert the error, but it return "undefined" to me.

 

Is that something I forget to setup?

Developer
Posts: 125
Registered: ‎01-17-2011
My Device: Playbook
My Carrier: Vodacom

Re: How to show javascript error in simulator?

Hi fenixlam

 

Quick guess:

 

Did you forget to include in your config.xml

 

 

<feature id="blackberry.identity" version="1.0.0"/> 

 

 

see http://www.blackberry.com/developers/docs/widgetapi/

 

 

Kind Regards,

Heiko

 

Developer
Posts: 61
Registered: ‎06-01-2009
My Device: Not Specified

Re: How to show javascript error in simulator?

I have add this in config.xml and it still get error.

Developer
Posts: 125
Registered: ‎01-17-2011
My Device: Playbook
My Carrier: Vodacom

Re: How to show javascript error in simulator?

[ Edited ]

 

I just tested this in the playbook simulator and it doesn't seem to work.

 

even used the example code from the widgetapi

 

 

<script type="text/javascript">
    var service = blackberry.identity.getDefaultService();
    alert("Default service name is:" + service.name + " and default email address is:" + service.emailAddress);
    alert("PIN: " + blackberry.identity.PIN);
    alert("IMSI: " + blackberry.identity.IMSI);
    alert("IMEI: " + blackberry.identity.IMEI);

</script> 

 

 

(and included the <feature id="blackberry.identity" version="1.0.0"/> tag in config.xml)

 

So there seems to be a problem - unless we both forgetting something

Maybe it'll work for the smatphones but def not for playbook simulator (Beta2)

 

.H

 

Developer
Posts: 61
Registered: ‎06-01-2009
My Device: Not Specified

Re: How to show javascript error in simulator?

 

I really found what my wrong:

 

 

not work:

<feature id="blackberry.identity.PIN"  required="true" version="1.0.0" />

 

work:

<feature id="blackberry.identity"  required="true" version="1.0.0" />

 

but my file read write still cannot work in this:

<feature id="blackberry.io.file"  required="true" version="1.0.0" />

or

<feature id="blackberry.io"  required="true" version="1.0.0" />

 

but my location had been change to this:

var filePath = "file:///store/home/user/stock.txt";

instead of original:

var filePath = "file:///SDCard/stock.txt";

 

I dont think that is the problem. here is my code:

 

function saveFile() {
    //need to get the text inside of the textarea of the iframe
	var textarea = document.getElementById("filecache");
    //check to see if the file exists.  Exception will be thrown if the path is to a existing file
	alert("file save begin");
	try{
	    if (blackberry.io.file.exists(filePath)) {
	        var check = confirm("Are you sure you want to override the existing file?");
	        if (check == true) {
	            //if the file exists, you have to delete the existing one before saving the new copy
	            blackberry.io.file.deleteFile(filePath);
	        }
	    }
	    var blob = blackberry.utils.stringToBlob(filecache);
	    blackberry.io.file.saveFile(filePath, blob);
	}catch(err){
		
		alert("Error description: " + err.description);
	}
    alert("file saved");
}

 

 

I am sure I have add this in config.xml:

 

<feature id="blackberry.system" required="true" version="1.0.0" />

  <feature id="blackberry.ui"  required="true" version="1.0.0" />

  <feature id="blackberry.ui.menu" required="true" version="1.0.0" />

  <feature id="blackberry.utils"  required="true" version="1.0.0" />

  <feature id="blackberry.io.file"  required="true" version="1.0.0" />

 

 

Highlighted
Developer
Posts: 125
Registered: ‎01-17-2011
My Device: Playbook
My Carrier: Vodacom

Re: How to show javascript error in simulator?

 

Sorry can't help any further as I think most of these functions don't work on the playbook simulator

(in your case you testing on smartphone where I would expect most of API to work .. )

 

Last try though ... Smiley Happy

Check the following line in your code sample:

 

var blob = blackberry.utils.stringToBlob(filecache);

 

should that not be:

 

var blob = blackberry.utils.stringToBlob(textarea);

 ?

 

Regards,

H.

 

 

PS: as for playbook simulator the following functions are supect - i.e. don't think they work:

 

blackberry.utils.stringToBlob(somestring)
blackberry.utils.documentToBlob(somedoc)

blackberry.identity.getDefaultService()
blackberry.identity.PIN
blackberry.identity.IMSI
blackberry.identity.IMEI

amongst others ..