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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
kris0725pl
Posts: 115
Registered: ‎03-24-2011
My Carrier: PLAY

How to store Volume Int?

[ Edited ]

I have problem with store volume player on exit applicstion.

 

The player gets the data from

_currentVolume = 50;

and

int _currentVolume;

 

I know how to store data from LabelField, but i know how to store Integer from player value :smileysad:

 

Any help me with this questions?

 

This is my code for get:

 

public void Get() { 
synchronized (store) { 
  _data = (Vector) store.getContents(); 
 
  if (!_data.isEmpty()) { 
StoreInfo info = (StoreInfo) _data.lastElement();
mylabel.setText(info.getElement(StoreInfo.INFO));
} 
} 
};

 


 
 
 
Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Carrier: Vodafone

Re: How to store Volume Int?

You can get the level from VolumeControl interface...

 

Have a look into the media demo.

SendMediaDemo with in BB Sample projects.

Please use plain text.
Developer
simon_hain
Posts: 13,796
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: How to store Volume Int?

if you want to persist the value you can wrap it into an Integer object (which is persistable)
----------------------------------------------------------
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.
Trusted Contributor
kris0725pl
Posts: 115
Registered: ‎03-24-2011
My Carrier: PLAY

Re: How to store Volume Int?

I have code...

 

_player.realize();
volumeControl = (VolumeControl) _player.getControl("VolumeControl");
    volumeControl.setLevel(_currentVolume);
    setVolume(_currentVolume);

and try like this but not working :)

info.setElement(StoreInfo.VOL2, volumeControl.getLevel());
                       

 I got this error...

 

setElement(int,java.lang.String) in USERSTATION.StoreInfo cannot be applied to (int,int)
info.setElement(StoreInfo.VOL2, volumeControl.getLevel());

 

I programming 2 month...and understand all.

 
Please use plain text.
Developer
simon_hain
Posts: 13,796
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: How to store Volume Int?

use http://www.blackberry.com/developers/docs/7.1.0api/java/lang/Integer.html#Integer(int) to store an int value, and http://www.blackberry.com/developers/docs/7.1.0api/java/lang/Integer.html#intValue() to retrieve it from the object.

int is a primive type, Integer is the matching object. you can persist an object, but not the primitve type, so you have to convert one into another.
----------------------------------------------------------
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
rabiray
Posts: 141
Registered: ‎07-13-2011
My Carrier: Vodafone

Re: How to store Volume Int?

try this

 

info.setElement(StoreInfo.VOL2, String.valueOf(volumeControl.getLevel()));
Please use plain text.
Trusted Contributor
kris0725pl
Posts: 115
Registered: ‎03-24-2011
My Carrier: PLAY

Re: How to store Volume Int?

[ Edited ]

I set for Save method this code :smileyhappy:

 

public void Save() { 
 StoreInfo info = new StoreInfo();


Integer.toString(StoreInfo.VOL2, volumeControl.getLevel());
 
 
  _data.addElement(info);

EDIT: My code not working...:smileyhappy:

i try your code a moment :smileyhappy: Restart BB :smileyhappy:

 

This code dont work...i cant exit from application when use them.

 

public void Save() { 
 StoreInfo info = new StoreInfo(); 

info.setElement(StoreInfo.VOL2, String.valueOf(volumeControl.getLevel()));
 
 
  _data.addElement(info); 
  synchronized (store) { 
   store.setContents(_data); 
   store.commit(); 
 }
}; 
 
 public void Get() { 
synchronized (store) { 
  _data = (Vector) store.getContents(); 
 
  if (!_data.isEmpty()) { 
StoreInfo info = (StoreInfo) _data.lastElement();


I dont know how to  :) 
 
 } 
} 
};

 

 

 

 
 
 
Please use plain text.
Trusted Contributor
kris0725pl
Posts: 115
Registered: ‎03-24-2011
My Carrier: PLAY

Re: How to store Volume Int?

[ Edited ]

Anybody help me?

 

I use this but not working...why?

 

public void Save() { 
 StoreInfo info = new StoreInfo(); 



info.setElement(StoreInfo.VOL2, String.valueOf(volumeControl.getLevel()));
 
 
  _data.addElement(info); 
  synchronized (store) { 
   store.setContents(_data); 
   store.commit(); 
 }
 
 //Dialog.inform("Success!"); 
   
  
 }; 
 
 public void Get() { 
synchronized (store) { 
  _data = (Vector) store.getContents(); 
 
  if (!_data.isEmpty()) { 
StoreInfo info = (StoreInfo) _data.lastElement();


volumeControl.setLevel(info.getElement(StoreInfo.VOL2));
 
 
 } 
} 
};

 I got this error:

 

 setLevel(int) in javax.microedition.media.control.VolumeControl cannot be applied to (java.lang.String)
volumeControl.setLevel(info.getElement(StoreInfo.VOL2));

 
 
 
Please use plain text.
Developer
simon_hain
Posts: 13,796
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: How to store Volume Int?

use Integer, not String. It is possible to use String, of course, but it does not make sense when dealing with a primitve int.
----------------------------------------------------------
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.
Trusted Contributor
kris0725pl
Posts: 115
Registered: ‎03-24-2011
My Carrier: PLAY

Re: How to store Volume Int?

[ Edited ]

I try everything :smileyhappy: But nothing works for me :smileysad:

 

I add this code and application works very fine....

 

String str = "30";

int _currentVolume = Integer.parseInt(str);

 Application starts and volume is 30...supa ^^ But when add this code for store, application cant open :smileysad:

 

I got This error in EventLog:

 

guid:0x9C3CD62E3320B498 time: Mon May 28 12:39:07 2012  severity:1 type:3 app:Java Exception data:
	ArrayIndexOutOfBoundsException
	1 >= 1
	net_rim_cldc(4BA7D958)
	 Vector
	 elementAt
	 0xC85C
	App(4FC354D2)
	 SOME$StoreInfo
	 getElement
	 0x4F66
	...

 

 

public void Save() { 

 StoreInfo info = new StoreInfo(); 

 info.setElement(StoreInfo.SMS, basicEditField2.getText());//This works fine

info.setElement(StoreInfo.VOL, String.valueOf(volumeControl.getLevel()));

  _data.addElement(info); 
  synchronized (store) { 
   store.setContents(_data); 
   store.commit(); 
 }
 

   
  
 }; 
 
 public void Get() { 
synchronized (store) { 
  _data = (Vector) store.getContents(); 
 
  if (!_data.isEmpty()) { 
StoreInfo info = (StoreInfo) _data.lastElement();



basicEditField2.setText(info.getElement(StoreInfo.SMS));//Works fine
Integer.parseInt((String)info.getElement(StoreInfo.VOL));


 } 
} 
};
 
static final class StoreInfo implements Persistable { 
 
  private Vector _elements; 
 
  
   public static final int SMS = 0;
public static final int VOL = 1;
 
  

public StoreInfo() { 
 
  _elements = new Vector(2); 
 
for (int i = 0; i < _elements.capacity(); ++i) { 
    _elements.addElement(new String("")); 
  }  
} 
 
  public String getElement(int id) { 
   return (String) _elements.elementAt(id); 
 } 
  public void setElement(int id, String value) { 
   _elements.setElementAt(value, id); 
 } 
 
} 
 
 
 static { 
store = PersistentStore.getPersistentObject (0xdec6a67096f839cL); 
   synchronized (store) { 
  if (store.getContents() == null) { 
     store.setContents(new Vector()); 
     store.commit(); 
   } 
  } 
   _data = new Vector(); 
   _data = (Vector) store.getContents(); 
} 

 Where is the problem??? I cant understand yet :smileyhappy:

 
 
Please use plain text.