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
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel
Accepted Solution

Unexpected Behavior of File picker

I am working on File picker from image gallery thats working fine in my 9850 os 7 but when same app if i am deployin to 9780 Bold  device file picker is not firing.

 

This is my code.

 

package mypackage;

import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

import net.rim.device.api.io.IOUtilities;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.picker.FilePicker;
import net.rim.device.api.ui.picker.FilePicker.Listener;

/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class MyScreen extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
Bitmap bitmap;
ButtonField click;
BitmapField bitmapField;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("FilePicker Screen");
createGUI();
}
private void createGUI()
{
add(new LabelField("Click to select the image", Field.FIELD_HCENTER));
click=new ButtonField("Click");
click.setChangeListener(this);
add(click);
bitmapField=new BitmapField();
add(bitmapField);
}
private Bitmap getTheImage(String url)
{
Bitmap bitmap=null,scaleBitmap=null;
InputStream inputStream=null;
FileConnection fileConnection=null;
try
{
fileConnection=(FileConnection) Connector.open(url);
inputStream=fileConnection.openInputStream();
byte[] data=new byte[(int)fileConnection.fileSize()];
data=IOUtilities.streamToBytes(inputStream);
inputStream.close();
fileConnection.close();
bitmap=Bitmap.createBitmapFromBytes(data,0,data.length,1);

//You can return this bitmap otherwise, after this you can scale it according to your requirement; like...
scaleBitmap=new Bitmap(250, 250);
bitmap.scaleInto(scaleBitmap, Bitmap.FILTER_LANCZOS);
}
catch (Exception e)
{
try
{
if(inputStream!=null)
{
inputStream.close();
}
if(fileConnection!=null)
{
fileConnection.close();
}
}
catch (Exception exp)
{

}
scaleBitmap=Bitmap.getBitmapResource("noimage.png");//Your known Image;
}
return scaleBitmap;
}

public void fieldChanged(Field field, int context)
{
if(field==click)
{
try
{
FilePicker filePicker;
filePicker=FilePicker.getInstance();
filePicker.setPath("file:///store/home/user/pictures/");
filePicker.setListener(new Listener()
{
public void selectionDone(String path)
{
bitmapField.setBitmap(getTheImage(path));
}
});
filePicker.show();//it show what ever you select.
}
catch (Exception e)
{

}
}
}
}

 

 

Please use plain text.
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel

Re: Unexpected Behavior of File picker

Edit forgot to add problem i am facing in 9780 os 6 bold 

Please use plain text.
Developer
SumiGhosh
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
My Carrier: Vodafone

Re: Unexpected Behavior of File picker

please move it to java section

Please use plain text.
Developer
slashkyle
Posts: 818
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: Unexpected Behavior of File picker

You will likely have better luck posting this question in the Java development forum for BBOS, Blackberry 10 doesn't suppot this code

 

http://supportforums.blackberry.com/t5/Java-Development/bd-p/java_dev

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Unexpected Behavior of File picker

did you compile the code with JRE 6?
The compilation level has to be the same or lower compared to the OS of the target device.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel

Re: Unexpected Behavior of File picker

Yes i am compiling with code with JRE 6.
Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Unexpected Behavior of File picker

i would suggest to debug the code and/or add logging.
is the changelistener called when you click the button?
is an exception thrown? (empty catch blocks are evil)
etc
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel

Re: Unexpected Behavior of File picker

@ Hi simon 

 

i checked lts not throwing any exception 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Unexpected Behavior of File picker

[ Edited ]

I think Simon wanted you to do a little more debugging than just checking for an Exception.

 

On your FieldChanged method you have the following:

 

if(field==click)
{
try
{
FilePicker filePicker;
filePicker=FilePicker.getInstance();
filePicker.setPath("file:///store/home/user/pictures/");

...

 

You could put a break point in this code and make sure it processes correctly by stepping through it. 

 

Also I don't see a filePicker.show().  So how does the FilePicker get displayed?

 

Finally do you see this error when you run it on a Simulator for the 9780, with  a similar level of OS to the one you are using?

 

Edit:  Thanks Simon, ignore my comment about there being no show....

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Unexpected Behavior of File picker

the show is below the inline definition of the listener.
otherwise, yes, there were a couple of suggestions, please check them all.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.