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

Posts: 193
Registered: ‎02-27-2009
My Device: Not Specified
Accepted Solution

Generating GUIDs with Eclipse plugin

Some APIs -- such as the global event listeners and persistence APIs -- expect you to provide a GUID. Code samples generally show a hard-coded long literal. I imagine there would be some chance of ID collisions. How does one normally generate such GUIDs when using Eclipse? Thanks.
BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Generating GUIDs with Eclipse plugin

The recommended approach is to use your package name and classed name:






This example equates to: 0x9fd1c13aff6c669dL


To convert a string to a long value highlight the string in the BlackBerry JDE or Eclipse, right click and then choose "Convert String to Long".  Note that if you are using Eclipse this feature requires the BlackBerry JDE Plug-in for Eclipse be installed.



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
New Developer
Posts: 1
Registered: ‎03-19-2009
My Device: Not Specified

Re: Generating GUIDs with Eclipse plugin



Is there a way to do this programitically? It would be nice to be able to do something like:


static long persistantKey = "com.rim.samples.device.helloworld".hashCode();


However, this only produces an integer not a long so I think it is not as unique.




- Will Mathies

Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Generating GUIDs with Eclipse plugin

/    static final long pik=
//            StringUtilities.stringHashToLong(pkg+".history.thingy");