ObjectChoiceField getSelectedIndex method always returns-1

Hello

I am facing a problem since these days, but I couldn't get an answer to the it from anywhere. I hope I can get the answer here:

I have a screen that has Menu and ObjectChoiceField but when I want to extract the ObjectChoiceField getSelectedIndex, it always returns-1. I don't know why! The code is very simple. If please see this and tell me where I'm wrong:

public class ConfigurationScreen extends MainScreen implements FieldChangeListener {

    private ObjectChoiceField list;
    private MyMenuItem save; // I have a class for this seperately.
    String [] cities ;

    public ConfigurationScreen ()
    {
           cities  = new String [] {"New York","London","Paris"};
           list = new ObjectChoiceField ("Cities :", cities);
           list.setChangeListener(this);
           this.add(list);

       save = new MyMenuItem("Save",1,0){
             public void run ()
             {
                 Dialog.alert(list.getSelectedIndex()+"");
             }
         };
         this.addMenuItem(save);

    }

   public boolean onClose()
   {
       Dialog.alert(list.getSelectedIndex()+"");
       return true;
   }
    public void fieldChanged(Field field, int context)
    {
            int selectedIndex = list.getSelectedIndex();
            Dialog.alert(selectedIndex+"");
        }

    }

}

The code could have a few spelling mistakes, but there is no syntax error in it. I get-1 whereeve I call the method getSelectedIndex()!

Help, please

Try this. It worked for me. Tested on BB 9000 Simulator. JDE 4.6.

public class ConfigurationScreen extends MainScreen implements FieldChangeListener
{

    private ChoiceField list;
    String [] cities ;

    public ConfigurationScreen ()
    {
        cities  = new String [] {"New York","London","Paris"};
        list = new ObjectChoiceField ("Cities :", cities);
        list.setChangeListener(this);
        this.add(list);
    }

    public boolean onClose()
    {
        Dialog.alert(list.getSelectedIndex()+"");
        return true;
    }   

    public void fieldChanged(Field field, int context)
    {
        int selectedIndex = list.getSelectedIndex();
        Dialog.alert(selectedIndex+"");
    }
}

Tags: BlackBerry Developers

Similar Questions

  • Message.getPriority () always return 3

    I have been using the following code to decide the priority of messages in the Inbox:

    Message messages [] = fFolder.getMessages ();

    for (int j = 0; j)

    System.out.println ("priority:" + messages [i] .getPriority ());

    }

    Eventhough, I have different priority messages in the Inbox, the Message.getPriority () method always returns the byte-code 3. That is to say, low priority

    When I implement FolderListener and get incoming messages to the messagesAdded method, it Message.getPriority () returns perfectly according to the priority of the message.

    How can we read the list of the messages in the Inbox to count certain priority message?

    Sorry for posting without prior testing.

    I talked instead of the loop variable j.

    Message.getPriority () works as expected

  • CoverageInfo.isCoverageSufficient (CoverageInfo.COVERAGE_MDS) always returns false on Simulator

    Hello world

    In my application, I would like to send data on a certain interval using the BES (MDS).  When the Blackberry is on the cover, I send the data right away... but when the Blackberry is out of coverage, I'm storing data on the PersistentStore and send it to the next interval.

    This is the condition that I use to determine whether or not the Blackberry is on the cover:

    {If ((RadioInfo.getState ()! = RadioInfo.STATE_OFF & (RadioInfo.getNetworkService () & RadioInfo.NETWORK_SERVICE_DATA)! = 0) & {CoverageInfo.isCoverageSufficient (CoverageInfo.COVERAGE_MDS))}

    It works perfectly on a real device Blackberry... but it always returns false on the Simulator (I tried Curve 8310 Rogers and 8330 Curve with my code point 4.2.1).)  It seems to be this specific line which is not correct:

    CoverageInfo.isCoverageSufficient (CoverageInfo.COVERAGE_MDS)

    It is not a very big problem because it works on a real device... it's just development and debugging more complicated as I have to remember to put this line in the comments when you use the Simulator and remove the comments before installing the application on a real device.

    I have to do something special on the Simulator to enable this?  Or is it a problem with my code?

    Thanks for your help!

    I saw that too. Put the CoverageInfo into your own method and use DeviceInfo.isSimulator () to work around the call and returns "true" If you run on the simultor.

  • CHOOSE the Menu malfunction, HP 48 G always returns the value '0', regardless of the selection

    I choose a menu with different functions which are useful when dealing with circles. I programmed on my HP 50 g and transferred directly to my HP 48 g by Kermit ASCII. The menu choose does not seem to highlight a specific choice, as it does on the HP 50 g, there is no indication of the choice is selected and jumping to menu options via defined their number also does not work. On the debugger, no matter if OK or entry is activated under any option '0' is always returned, as if I had cancled out of the menu. Any help would be appreciated. Perhaps CHOOSE menus are slightly different on the HP 48 G?

    I found the problem. The syntax to CHOOSE is slightly different than the one on the 50g. On the 50g, I used to write my statements like this

    { { ... } } CHOOSE 0

    The 48G requires it:

    { { ... } } 1. CHOOSE

  • Table of index always returns zero when reading the table 3D

    I have a 9 x 2000 x 5 table table 3D diamension.  I have this table filled with data and when I try to read a data point unique on the table the function Index Array always reads zero. I place a probe on the 3D input array and when I put in the index of the probe to the same data point the probe shows the value stored in the table. I also have an indicator showing the 3D table and it displays data in all locations. For example if I try to read the location 0, 144.0 in 3D it array always return zero. Yet I know that the value of this element is 6.8616E - 5. Each item I try to retreave table gives zero.

    Anyone saw the Index room table this kind of behavior?

    Problem solved. As usual, it was pilot error on my part had knocked down the lines of lines and columns.

  • The icons on my desktop page always returned to the left of the start screen.

    The icons on my desktop page always returned to the left of the start screen. I have to uncheck the "align icons on the grid. Any ideas why & how can arange the icons as I want! Do not know if by chance, but it started after I recently had to reinstall MS Essentials

    Hello

    I suggest you to follow the steps and check if it helps.

    a. right click on the desktop.

    b. choose 'Customize'.

    c. on the left side of the Control Panel, click on "Change desktop icons"

    d. uncheck "allow themes to change desktop icons."

    See also:

    Show or hide common icons on the desktop

    http://Windows.Microsoft.com/en-us/Windows7/show-or-hide-common-icons-on-the-desktop

    The desktop (overview)

    http://Windows.Microsoft.com/en-us/Windows7/the-desktop-overview

    I hope this helps.

  • Method that returns the bb::cascades:Application?

    Hi, is there a method that returns the bb::cascades:Application?

    I solved the problem by simply passing the request of my class that needs it. If its solved because there is no such method I think.

  • LocationProvider.getInstance always returns null

    I'm trying to run a slightly modified version of the application on a BlackBerry 7250 GPSDemo. As my device software is version 4.1, I use the BlackBerry JDE 4.1. No matter what are the parameters for the criteria, I pass in LocationProvider.GetInstance, I always return null. I can run google maps on this unit and get my location, so I'm assuming that the GPS is supported in this regard. Did anyone see any problem with code and/or information on the devices below?

    Wireless blackBerry 7250 (CDMA)

    v4.1.0.353 (Platfor 2.2.0.159)

    The kernel v3.8.3.7 encryption

    The microedition configuration: CLDC-1. 1

    Microedition profile: MIDP-2. 0

    Microedition JTWI Version: 1.0

    Microedition Media Version: 1.1

    Microedition PIM Version: 1.0

    Try
    {
    GpsReceiverCriteria criteria = new Criteria();
    gpsReceiverCriteria.setHorizontalAccuracy (Criteria.NO_REQUIREMENT);
    gpsReceiverCriteria.setVerticalAccuracy (Criteria.NO_REQUIREMENT);
    gpsReceiverCriteria.setCostAllowed (true);
    gpsReceiverCriteria.setPreferredPowerConsumption (Criteria.POWER_USAGE_LOW);
    gpsReceiverCriteria.setAddressInfoRequired (false);

    _locationProvider = LocationProvider.getInstance (gpsReceiverCriteria);
               
    If (_locationProvider is nothing)
    {
    Runnable ShowGpsLocationProviderNull1Dialog = new Runnable()
    {
    public void run()
    {
    Dialog.Alert ("Provider is null - HA: NR VA: NR CA:T PC:L");
    }
    };
    invokeLater (showGpsLocationProviderNull1Dialog);  Ask the event dispatcher thread to display the dialog box as soon as POSSIBLE
    }
       
    gpsReceiverCriteria.setHorizontalAccuracy (Criteria.NO_REQUIREMENT);
    gpsReceiverCriteria.setVerticalAccuracy (Criteria.NO_REQUIREMENT);
    gpsReceiverCriteria.setCostAllowed (false);
    gpsReceiverCriteria.setPreferredPowerConsumption (Criteria.POWER_USAGE_LOW);
    gpsReceiverCriteria.setAddressInfoRequired (false);

    _locationProvider = LocationProvider.getInstance (gpsReceiverCriteria);
               
    If (_locationProvider is nothing)
    {
    Runnable ShowGpsLocationProviderNull2Dialog = new Runnable()
    {
    public void run()
    {
    Dialog.Alert ("Provider is null - HA: NR VA: NR CA:F PC:L");
    }
    };
    invokeLater (showGpsLocationProviderNull2Dialog);  Ask the event dispatcher thread to display the dialog box as soon as POSSIBLE
    }

    _locationProvider = LocationProvider.getInstance (null);
               
    If (_locationProvider is nothing)
    {
    We would like to display a dialog box indicating that the GPS is not supported, but because that
    the event dispatcher thread has not been started yet, modal screens cannot be pushed on
    the battery in the display.  So delay the operation until the event dispatcher thread runs
    asking him to call the executable object following as soon as possible.
    Runnable showGpsUnsupportedDialog = new Runnable() {}
    public void run() {}
    Dialog.Alert ("No receiver GPS on this unit is available, exit...");
    System.Exit (1);
    }
    };
    invokeLater (showGpsUnsupportedDialog);  Ask the event dispatcher thread to display the dialog box as soon as POSSIBLE
    }
    on the other
    {
    only a single listener can be associated with a provider and point it comes to the same
    call, but with the value null, so, no need to cache the listener instance
    request an update every second
    _locationProvider.setLocationListener (new LocationListenerImpl(), _interval, 1, 1);
    retval = true;
    }
    } catch (LocationException) {}
    System.Err.println ("Failed to instantiate the object LocationProvider, exit...");
    System.Err.println (the);
    System.Exit (0);
    }

    Oops... sory. My dyslexia again out of in

    I think that the 7250 has no GPS function at all.

    Yet again, Google it didn't need because they have their own turn cells DB and web services to retrieve the "approximate" location

  • String.startsWith always returning true.

    Hello, I have a small issue that has been driving me nuts. I am a beginner in Java, so the problem is most likely something stupid that I monitor, so I would like another opinion.

    Basically I have a listfield I want to make it searchable. I had another problem earlier with indexOfList always returning-1, so I gave up using it. Instead, I am a loop in the listfield table and see if _seriesList [i] .startsWith (_searchField.getText ()). For some reason, it ALWAYS returns true, causing the first item in the list to be chosen as the result of the search. Here is the code:

      for(int i = 0; i < _seriesListField.getSize(); i++)    {     String temp = _searchField.getText();     System.out.println(_seriesList[i].Title);     System.out.println(temp);     if(_seriesList[i].Title.startsWith(temp));        {         System.out.println("startsWith returned TRUE");           _seriesListField.setSelectedIndex(i);         return;       } }
    

    No matter what value I give, startsWith return true. I also tried to use substring (0, temp.length () .equals (temp) instead and who also returned the value true. My console output is:

    07 - ghost<-- the="" name="" of="" the="" first="" item="" in="" the="">
    C<-- the="" value="" i="" typed="" into="" the="">

    startsWith, returned the TRUE value

    The javadoc for startsWith says he can return true if the prefix is null or if channels .of each other, see, however I see that these two are clearly false from the console output.

    I could use help to find out why this happens and fixing it, and if it turns out to be something mind-numbingly stupid and/or obvious I apologize profusely in advance.

    It is a sad, sad day for me. I had a semicolon after the if test. While the error itself is not so bad, the fact that it took me nearly an hour to discover this is painful.

  • Value of the EL Expression always return false

    Hello

    I use JDEV 12.1.3

    I have it here's the expression where it always returns false? Why? I set the value always true

    #{ApplicationParameter.isShowLetter}

    Java class:

    public class ApplicationParameter {}

    Private boolean isShowLetter = true;

    {} public void setIsShowLetter (boolean isShowLetter)

    this.isShowLetter = isShowLetter;

    }

    public boolean isIsShowLetter() {}

    Return isShowLetter;

    }

    JSPX:

    "http://Java.Sun.com/jsp/page" version = "2.1" xmlns:f ="http://java.sun.com/jsf/core"

    xmlns:af ="http://xmlns.oracle.com/adf/faces/rich" >. "

    Bean code:

    package com.avio.otn;

    Import org.apache.myfaces.trinidad.event.AttributeChangeEvent;

    public class MyBean {}

    Private boolean showLetter = true;

    public MyBean() {}

    }

    {} public void setShowLetter (boolean showLetter)

    this.showLetter = showLetter;

    }

    public boolean isShowLetter() {}

    System.out.println ("show:" + showLetter);

    Return showLetter;

    }

    }

    Taskflow recording of the bean:

    MyBean

    com.avio.otn.MyBean

    pageFlow

    And everything works as expected... If I put real, this one appears fine, set it to false, it disappears...

    HTH

  • ViewObject get attribute always returns null

    Hi guys,.

    I need your help, I'm going crazy.

    I'm just trying to browse a ViewObject as I did a thousand times but despite getEstimatedRowCount return 1 and the Row inside the SENTENCE object is not null, getattribute always returns null, does not care if I call getAttribute (String) or getAttribut (int)

    This is the last code I tested:

    AppMod = (PeopleFinderAppModuleImpl) this.getApplicationModule () PeopleFinderAppModuleImpl;

    PfUserGetInfoImpl pf_Info = (PfUserGetInfoImpl) appMod.getPfUserGetInfo1 ();

    pf_Info.setp_userid (UserID);

    pf_Info.executeQuery ();

    System.out.println ("# view getEstimatedRowCount:" + pf_Info.getEstimatedRowCount ());

    PfUserGetInfoRowImpl r = null;

    RowSetIterator rsIterator = pf_Info.createRowSetIterator (null);

    While (rsIterator.hasNext ()) {}

    r = (PfUserGetInfoRowImpl) rsIterator.next ();

    System.out.println ("# AttributeCount:" + r.getAttributeCount ());

    String [] uploading = r.getAttributeNames ();

    for (int i = 0; i < attrs.length; i ++) {}

    System.out.println (I + "" + uploading [i] + "=" + r.getAttributeValues () [i]);

    }

    }

    rsIterator.closeRowSetIterator ();

    The output is:

    # userid: EPETRANG

    # Discovers getEstimatedRowCount: 1

    # AttributeCount: 13

    0 Userid = null

    1 name = null

    2 Givenname = null

    3 family name = null

    4 title = null

    5 Dn = null

    6 mail = null

    7 company = null

    8 Department = null

    9 Telephonenumber = null

    Mobile 10 = null

    11 Ipphone = null

    Manager of 12 = null

    My Env record:

    Build JDEVADF_11.1.1.7.0_GENERIC_130226.1400.6493

    1.6.0_45 64-bit JVM

    Of course, the query returns 1 row SQLDeveloper and ApplicationModule compressiometre is as well.

    You see something wrong in the code? I tried to delete and re-create the ViewObject without a bit of luck.

    Hi guys,.

    Thanks to you all.

    This morning I just tried to delete and recreate the Weblogic JDev field and now everything works fine. Looks like that integrated weblogic has been screwed

    Thanks again.

  • I work in a large project on my main composition and have always return all night but cannot give more than one inside and out...?

    Hello.

    I work in a big project on my main composition in 2015 of EI, Yosemite 10.10.5 and always return all night but cannot give more than one inside and out...?

    If I give several definitions in my composition to queue rendering, After Effects rendered all points, but only the last again and again.

    I never need to make multiple files during the night, so I don't know if this is normal or there at - there a Posibility to return more control then a?

    Kind regards

    Florian.

    It's one of these bugs CC 2015. It would be possible to set using render settings different, it seems to occur with specific formats.

    Mylenium

  • Selector presentation VC:datastore always returns 0 for capacity (GB), freeSpace (GB)

    vCenter Version: 5.5.0,1476327

    vCO Version: 5.5.1

    vCenter Plugin: 5.5.1.1614908

    When you select a selector of presentation VC:Datastore... Capacity (GB), freeSpace (GB) columns are not met and always returns 0. This behavior was not present in previous versions of 5.5.

    Reflections, workarounds?

    ~ Alex Allen c.

    Have you tried to 'com.vmware.o11n.vim.useInventoryService' to 'false' (in vmo.properties). ?

  • File navigation dialog box always returns the application folder, not the one I selected

    My script uses a hardcoded destination path to save files. I want to make it more flexible with a file navigation dialog box.

    The function of file selectDlg seems obvious, but it always returns the location of the folder of Photoshop, not the folder I chose in the dialog box.

    For example:

    var outputFolder = Folder();

    outputFolder.selectDlg ("output :"); folder

    $.write (outputfolder);

    Expected:

    My JavaScript console must declare the file I selected in the system dialog box.

    Actual results:

    Regardless of the folder in which I select in the dialog box, it returns always like:

    /c/program%20Files/Adobe/Adobe%20Photoshop%20CC%202014/tmp00000001

    The directory path is where Photoshop is installed on my computer. The tmp00000001 file seems to come.

    Am I missing something obvious?

    var f = Folder();
    var outputFolder = f.selectDlg("Output folder:");
    $.write(outputFolder);
    
  • How a plugin method can return an object of properties (javascript)

    Hello

    With VC0 4.1, I have a plugin method written in Java. I would like that this method returns an object which Orchestrator (VCO) will see as an object of Properties javascript directly without passing by the serialization or other treatment...

    To do:

    -What class of java object my plugin method must return?

    -What should I use as return-type attribute when my method declaration in the VSO.xml file?

    "< script-the method name = 'myMethod' java-name = 'myMethod' return-type ="?">"

    Thanks in advance.

    Arnaud

    Hi Arnaud,.

    You're right, the object that returns your method should be Hashtable (I actually thought that properties should also be valid since it extends from Hashtable).

    Try with:

    public Hashtable {getInfosInProperties()}
    Hashtable retMap = new Hashtable ();

    retMap.put ("key1", "value 1");
    retMap.put ("Key2", new Long (2));
    retMap.put ("key3", true);

    Return retMap;
    }

    The vso.xml file is very good with "Properties". And you will get an object from the vCO scripting API to script properties.

    I hope it helps.

    Sergio

Maybe you are looking for