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
Contributor
ankit232
Posts: 38
Registered: ‎05-21-2011
My Device: 8900
My Carrier: rrr

application successfully run on jde 4.6.1 but could not run on plugin 1.3

hi,

I have a little bit problem in my code. when i execute application on jde4.6.1 then program successfuly run but when i try to run same code in plugin 1.3 then face compiler error in edit menu function (myList.set(myEdit.getText());  . thats why i am unable to edit value. please resolve this problem.

 

package mypackage;
import java.util.*;
import net.rim.device.api.collection.*;
import net.rim.device.api.collection.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.util.*;
public class MyList extends UiApplication implements FieldChangeListener {
    MyScreen myScreen = new MyScreen();
    public static void main(String args[]) {
        MyList app = new MyList();
        app.enterEventDispatcher();
    }
    public MyList() {
        MainScreen titleScreen = new MainScreen();
        titleScreen.setTitle("Click the button:");
        ButtonField myButton = new ButtonField("Show the list", ButtonField.CONSUME_CLICK) ;
        myButton.setChangeListener(this);
        titleScreen.add(myButton);
        pushScreen(titleScreen);
    }
    public void fieldChanged(Field field, int context) {
        pushScreen(myScreen);
    }
}
class MyScreen extends MainScreen {
    ObjectListField myList = new ObjectListField();
    static PersistentObject myStore;
    static Vector myData;
    static {
        myStore = PersistentStore.getPersistentObject(0xb77f8e453754f37aL);
        myData = (Vector) myStore.getContents();
        if (myData == null) {
                myData = new Vector();
                myData.addElement("String 1");
                myData.addElement("String 2");
                myData.addElement("String 3");
                myStore.setContents(myData);
        }
    }
    public MyScreen() {
        setTitle("Edit the list below:");
        add(myList);
        addMenuItem(addItem);
        addMenuItem(editItem);
        addMenuItem(removeItem);
    }
    // load data from persistent store into the ListField
    private void loadData() {
        // clear the ListField
        myList.setSize(0);
        // copy data from the Vector to the ListField
        for (int i = myData.size() - 1; i >= 0; i--)
            myList.insert(0, myData.elementAt(i));
    }
    // save data from the ListField into the persistent store
    private void saveData() {
        // clear the Vector
        myData.removeAllElements();
        // copy data from the ListField to the Vector
        for (int i = myList.getSize() - 1; i >=0; i--)
            myData.addElement(myList.get(myList, i));
        synchronized(PersistentStore.getSynchObject()) {
            myStore.commit();
        }
    }
    protected void onUiEngineAttached(boolean attached) {
        if (attached) {
            loadData();
        }
    }
    public void save() {
        saveData();
        // UPDATE: when I call setDirty(false); here, then
        // the app starts displaying Save/Discard/Cancel dialog
        // on its exit - so there must be a better way...
    }
    private final MenuItem addItem = new MenuItem("Add Item", 0, 0) { 
        public void run() {
            String[] buttons = {"Add", "Cancel"};
            Dialog myDialog = new Dialog("Add Item", buttons, null, 0, null);
            EditField myEdit = new EditField("Item: ", "");
            myDialog.add(myEdit);
            if (myDialog.doModal() == 0) {
                myList.insert(0, myEdit.getText());
                setDirty(true);
            }
        }
    };
    private final MenuItem editItem = new MenuItem("Edit Item", 0, 0) { 

        public void run() {
            String[] buttons = {"Save", "Cancel"};
            Dialog myDialog = new Dialog("Edit Item", buttons, null, 0, null);
            int index = myList.getSelectedIndex();
            if (index == -1) {
                return;
            }
            String selectedItem = (String) myList.get(myList, index);
            EditField myEdit = new EditField("Item: ", selectedItem);
            myDialog.add(myEdit);
            if (myDialog.doModal() == 0) {
          myList.set(myEdit.getText());         
                setDirty(true);
            }
        }
    };
    private final MenuItem removeItem = new MenuItem("Remove Item", 0, 0) { 
        public void run() {
            String[] buttons = {"Delete", "Cancel"};
            Dialog myDialog = new Dialog("Remove Item", buttons, null, 0, null);
            int index = myList.getSelectedIndex();
            if (index == -1) {
                return;
            }
            String selectedItem = (String) myList.get(myList, index);
            LabelField myLabel = new LabelField("Really delete " + selectedItem + "?");
            myDialog.add(myLabel);
            if (myDialog.doModal() == 0) {
                myList.delete(index);
                setDirty(true);
            }
        }
    };
}


Please use plain text.
Developer
ankit
Posts: 146
Registered: ‎07-24-2008
My Device: none
My Carrier: none

Re: application successfully run on jde 4.6.1 but could not run on plugin 1.3

I compiled your code as i am getting error in jde 4.6 and jde 5.0 both. I do not have 4.6.1 at the moment so could not test on that.
try this
myList.set(new String[]{myEdit.getText()});

the set method expects an array and you are passing it a string. Thats why its giving compilation error.

Thanks
Ankit
Thanks & Regards,
Ankit Dubey
Module Lead Software Engineer, mLabs
Impetus InfoTech (India) Pvt. Ltd.
Please use plain text.
Contributor
ankit232
Posts: 38
Registered: ‎05-21-2011
My Device: 8900
My Carrier: rrr

Re: application successfully run on jde 4.6.1 but could not run on plugin 1.3

Thanks Ankit,

but when i try  to edit value with your code then string has been modify but predefined above 3 string has removed so it should not be done.

but i have resolve this problem.

i have use

myList.delete(myList.getSelectedIndex());
myList.insert(myEdit.getIndex(), myEdit.getText());

with replace of  error code. so my problem has resolved.

Please use plain text.
Developer
ankit
Posts: 146
Registered: ‎07-24-2008
My Device: none
My Carrier: none

Re: application successfully run on jde 4.6.1 but could not run on plugin 1.3

Great.
The code i put was just a pointer to resolve the compilation error.

i think you can mark this thread as solved.

Thanks
Ankit
Thanks & Regards,
Ankit Dubey
Module Lead Software Engineer, mLabs
Impetus InfoTech (India) Pvt. Ltd.
Please use plain text.