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
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: save fonts

Why didn't you tell us this at the start?

 

You have a null pointer exception on this line:

saveimagevector.addElement(index);

 

We know index is not null.  So what is your problem?

 

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

i think u did not got my point, if u look at the code for changing the backgroung images with object choice field that is working fine, but if i closed the app and start the ap again i want to show the same image that image that was selected by the user before closing the app. 

for this i'm trying to store the index value in persistence. 

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

Re: save fonts

Yes I am well aware of what you are trying to do. 

 

Is the following code, which is what is actually persisting the index value, ever being run?

store.setContents(saveimagevector);

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

[ Edited ]

no that did not run,i don't know why that was throwing Nullpointer excp

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

yes i got success to save the selected value into persistence , ihave change my code ,look at below

public final class MyScreen extends MainScreen 
{
	String[] Backimages = {"image1","image2","image3","image4","image5","image6"};
	ObjectChoiceField pickSize, Background;   
    private VerticalFieldManager mainManager;
    private VerticalFieldManager subManager;
    private Bitmap _backgroundBitmap = Bitmap.getBitmapResource("a.png");       
    private int deviceWidth = Display.getWidth();
    private int deviceHeight = Display.getHeight();
    Bitmap backgroundBitmap = Bitmap.getBitmapResource("brush.png");
    String index, storevalue;
    static PersistentObject store;
    static {
    	store = PersistentStore.getPersistentObject( 0xa1a569278238dad2L );
    	}
    private Vector saveimagevector,first ,second; 
    
    public MyScreen() 
    {
        super(NO_VERTICAL_SCROLL);
        
        //this manager is used for the static background image
        Background = new ObjectChoiceField("images:", Backimages,0);
       
        mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR);
        mainManager.setBackground(BackgroundFactory.createBitmapBackground(_backgroundBitmap));
        
        //this manger is used for adding the componentes
        subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR)
        {
            protected void sublayout(int maxWidth, int maxHeight)
            {
                int displayWidth = deviceWidth;
                int displayHeight = deviceHeight;
 
                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
            }
        };
                
        // add your component to this subManager       
        subManager.add(Background);
        Background.setChangeListener(new FieldChangeListener() {
			
			public void fieldChanged(Field field, int context) {
				// TODO Auto-generated method stub
				if(field == Background)
		         {
					saveimagevector = new Vector();
					first = new Vector();
					second = new Vector();
					
		      	   try {
					   index = (String) Background.getChoice(Background.getSelectedIndex());
					   System.out.println("INDEX========"+Background.getSelectedIndex());
					   System.out.println("selected choice=="+Background.getChoice(Background.getSelectedIndex()));
					  
					   if(Background.getSelectedIndex() == 0)
					   {
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(backgroundBitmap));
					   }else if(Background.getSelectedIndex() == 1){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("c.png")));
					   }else if(Background.getSelectedIndex() == 2){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("f.jpg")));
					   }else if(Background.getSelectedIndex() == 3){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("g.jpg")));
					   }else if(Background.getSelectedIndex() == 4){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("h.jpg")));
					   }else if(Background.getSelectedIndex() == 5){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("i.jpg")));
					   }
					   
					   storevalue = ""+Background.getChoice(Background.getSelectedIndex());
					  
					   first.addElement(storevalue);
					   System.out.println("first="+first);
					   
					    synchronized(store) {
					    	try {
								store.setContents(first); 
								store.commit();
							} catch (ControlledAccessException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
					    }
					    synchronized(store) {
					    	second = (Vector) store.getContents();
					    	System.out.println("second = "+second);
					    }
					    
					    
					
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					System.out.println(e.toString());
				}	      	   
		         }  
			}
		});
        
        //add subManager over the mainManager
        mainManager.add(subManager);
        
        //finally add the mainManager over the screen
        this.add(mainManager); 
        
    } 
   
    
}

 

 

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

now plz can u tell me how can i want to check the value seleced by the user, when user again starts the app after closing and that image when app is started

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

Re: save fonts

Before answering this question, I'd like to take a moment or two to review what has happened so far on this Thread.

 

2 weeks or so ago, you asked about persisting some data.  You were supplied with a number of links including a tutorial which reviewed the options.

 

On Tuesday you asked if we could explain it a bit more.  I pointed you at the same tutorial I had already pointed you at.

 

Yesterday you gave us about 40 lines of code of which only 1 line was relevant to your question. (You have one value that you need to persist, how you get that value and what you do with that value is not relevant to this problem.) It appeared that you were asking us to write the persistence code for you. 

 

When we didn't, you managed to write some persistence code for yourself. 

 

You had a problem with it, which you reported as "not storing the vector".  It appeared that you had written the code and when it did not work, you just posted it, because when I got you to put some debugging lines in the code, you found the actual problem.  If you had done any reasonable debugging, you would have found the problem yourself. 

 

Now that some data is being stored, you are again asking us to write some code for you, this time to retrieve and use the persisted data.

 

Overall if you look at the questions you have asked on this Thread, it seems that you expect us to help you writing and debugging this application for you.  But we are not getting paid to do this, you are. 

 

And you are not actually asking us for help on things you can't do :

a) You have managed to read the persistence information and put some persistence code in your application

b) You managed to debug your program and resolve the issue, but I shouldn't have needed to get you to put those lines - you should have done it by yourself. 

 

So why aren't you doing this for yourself? 

 

This unfortunately is not the first time you have done this.  I have pointed out these issues to you on many occasions and pointed you at documentation that was written to help people in your situation.  However you are still doing the same things. 

 

I have been sympathetic till now because you were new and it appears English is not your first language.  But my patience is worn out. 

 

So sorry, I will not help you in future unless I think you are

(a) asking a valid question,

(b) have tried to find the information for yourself,

(c) have debugged your code, and

(d) have thought about the information you need to post so that you provide all the required information, but only the relevant code. 

 

In this case, you fail on (b) and (d).

 

Look at the tutorial.  It would be silly to have tutorial that explained how to persist data that did not also explain how to extract the data.  Once you have the data, then look at the API to see how you can use the value you have retained. 

 

Good luck.

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

ok, i did not need your help, i have solve my problem myself,
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: save fonts

I am pleased to hear this:

 

But I am confused, why did you ask the question if you could solve it yourself?

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

Re: save fonts


Achin wrote:
ok, i did not need your help, i have solve my problem myself,

The good feedback after a few pages of thread is what makes this forum so unique :Innocent:

----------------------------------------------------------
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.