indexOf problems

In my code, I upload a HTML file, convert to an array of bytes to a string using:

String s1 = new String(byteArray);

When I view s1, it seems to be an exact replica of the HTML file. When I use indexOf on s1, any search string I use,-1 is returned (even if the search string is in the HTML file).

When I declare an arbitrary string through coding and use the same operation indexOf, indexOf returns the location of the search string as expected.

Why indexOf doesn't seem to work on the downloaded string? I have the impression that it is because there is an extra byte added to each character, but I'm just guessing and don't know where to go from here.

Thank you

-sd

Sorry, I fixed it.

Tags: BlackBerry Developers

Similar Questions

  • Problems with IndexOf and lastIndexOf?

    Hello

    The last time when I was using the code below, it returns 3 and 0.

    code 1

    var txt:String = "abcd";

    trace (txt. IndexOf ("d"));          3

    trace (txt. LastIndexOf ("d"));     0

    He is now back 0 and 0.

    code 2

    var txt:String = "abcd";

    trace (txt. IndexOf ("d"));          0

    trace (txt. LastIndexOf ("d"));     0

    I guess I accidentally changed something, but surely there must be a simple way to return as code 1.

    use:

    var int index = findFromEndF (Votrechaine, searchstring)

    where:

    function findFromEndF(s:String,ss:String):int {}

    {if (s.IndexOf (SS) > = 0)}

    return of s.lastIndexOf (ss)-s.length + 1;

    } else {}

    Returns - 1;

    }

  • problems with indexOf

    I can't get the indexOf an array (myArr1) that contains 24 different channels that exist within the document XML (obrasXML)

    var numButtons:Number = 25; one more of are on the scene since the loop starts at 1


    var myArr1:Array = new Array (25);
    var carregadorURL:URLLoader = new URLLoader;
    var pedidoURL:URLRequest = new URLRequest ("obras.xml");


    carregadorURL.addEventListener (Event.COMPLETE, xmlCarregado)

    var obrasXML:XML = new XML();
    obrasXML.ignoreWhitespace = true;


    function xmlCarregado(e:Event):void
    {
    obrasXML = XML (carregadorURL.data);

    for (var i: uint = 1; i < numButtons; i ++) / / loop starts at 1, because the instance names begin at 1
    {
    myArr1[i]=obrasXML.pintura[i].@titulo;
    var st:String = myArr1 [i];
    var sw:Number = st.length;
    var pos:Number = Math.round (-(sw*6.36));
    This ["work_btn_" + i] .addEventListener (MouseEvent.CLICK, abrir_obra);
    This ["work_btn_" + i] .buttonMode = true;
    This ["work_btn_" + i]. text_activo.text = myArr1 [i];
    This ["work_btn_" + i]. text_inactivo.text = myArr1 [i];
    This ["work_btn_" + i].work_btn_masc.width = Math.round (sw * 6.36) + 10;
    This ["work_btn_" + i]. text_activo.x = pos;

    }

    }
    carregadorURL.load (pedidoURL);

    function abrir_obra(e:MouseEvent):void
    {
    trace(myArr1[1]);   output: "Ich möchte Ritter breast" (that's the string for index [1] and the "myArr1' at index [1] of the 'obrasXML')
    var alvo:String = e.target.text;

    trace (alvo); same output: "Ich möchte Ritter breast"

    trace (myArr1.IndexOf (ALVO)) / / output:-1 (should be '1')
    }

    All the channels that have been attributed to myArr1 in the xmlCarregado function event.COMPLETE, are still in the table in the function abrir_obra, but I can´t seem to be able to access their respective indexes. It always returns the value -1 .

    any help?

    Thanks in advance

    Alex

    Yes, any code that requires waiting for the data arriving should be dealt with through this complete function.

    For what is the event handler function, no, do not nest functions.  You can set the event listener in this function, but there is no need to define the event handler in this function.

  • Tracing of data from a source of problems

    Visual Studio 2010, Measurement Studio 2010 standard, c#, .NET

    I made a new NI Windows (application forms). Added a MySQL database as a data source, added to a table control to verify the data are there... Yes displayed fine.

    Then, I put in a WaveformGraph OR. Right-click, properties, data, databindings, data binding and added the Datasouce.

    Don't compile, nothing, no plot.

    any ideas?

    I'll write here what it was is available for any other beginner c# who may have the same problem.

    The problem was my understanding of the works of the 'link '. I had the thin binding to the database configuration, but the values were not reading. I ended up doing this:

    ' private void load_DB_data_and_plot (object sender, EventArgs e)
    {
    waveformPlot2.PlotY (getCol ("meter_out"));

    }

    Private double [] getCol (string column-name)
    {
    int col_index = 0;
    foreach (DataColumn col in getColumns())
    If (col. ColumnName is column-name)
    col_index = getColumns(). IndexOf (col);

    Double [] values = double [getRows (new). Length];
    for (int i = 0; i)< getrows().length;="">
    {
    values [i] = Convert.ToDouble (getRows () [i]. ItemArray [col_index]);
    }
    return values;
    }

  • [Combo Box problem in Google Chorme + ripple]

    How can I see the results in the ComboBox so to open it one can not

    Please check the picture below: HERE

    My case is executed.

    The problem is solved by replacing the line 58 to bbui - 0.9.4.js

    bb.device.isRipple = (navigator.userAgent.indexOf('Ripple') >= 0);
    

    with

    bb.device.isRipple = (navigator.userAgent.indexOf('Ripple') >= 0) || window.tinyHippos;
    
  • Problems with GZip &amp; FTP

    Hello

    in my application, I need to send a file compressed using ftp.

    To do this, I used a class initially write to use with J2SE (SimpleFTP)

    I have change for use with RIM API and it work with file bit compressed (like 4 KB) but when I try to send one just a little big (12Ko) I have a problem to decompress: gzip - me to say end of file unexpected.

    It is a bit of cod used:

    //In a thread i create the connection and change to BIN
    ftp.connect(ip, port, user, psw, true, apn, apnUser, apnPsw);
    ftp.cwd(dir);
    ftp.bin();
    
    //here I obtain a csv representation of my object and store it in a //String var
    String csv = r.toCSV();
    
    //this method ask to ftp object to store a ByteArray in the file named //file and i want to zip it and return true if all is ok
    if (ftp.stor(new ByteArrayInputStream(csv.getBytes("UTF-8")),file,true))
    //...do things
    

    the method of object ftp stor have this code:

    /**
     * Sends a file to be stored on the FTP server. Returns true if the file
     * transfer was successful. The file is sent in passive mode to avoid NAT or
     * firewall problems at the client end.
     */
    public synchronized boolean stor(InputStream inputStream, String filename, boolean zipped) throws IOException {
    
        sendLine("PASV");
        String response = readLine();
        if (!response.startsWith("227 ")) {
            throw new IOException("SimpleFTP could not request passive mode: " + response);
        }
        String ip = null;
        int port = -1;
        int opening = response.indexOf('(');
        int closing = response.indexOf(')', opening + 1);
        if (closing > 0) {
            String dataLink = response.substring(opening + 1, closing);
            String[] tokenizer = Functions.splitString(dataLink, ',', -1);
            try {
                ip = tokenizer[0] + "." + tokenizer[1] + "." + tokenizer[2] + "." + tokenizer[3];
                port = Integer.parseInt(tokenizer[4]) * 256 + Integer.parseInt(tokenizer[5]);
            } catch (Exception e) {
                throw new IOException("SimpleFTP received bad data link information: " + response);
            }
        }
        String url = "socket://" + ip + ":" + port + urlParam;
        Logger.log(this, "Try to open passive connection to "+url);
        SocketConnection dataSocket = (SocketConnection) Connector.open(url);
        dataSocket.setSocketOption(SocketConnection.LINGER, 5);
        dataSocket.setSocketOption(SocketConnection.DELAY, 5);
    
        sendLine("STOR " + filename);
    
        response = readLine();
        if (!response.startsWith("125 ")&&!response.startsWith("150 ")) {
            dataSocket.close();
            dataSocket=null;
            throw new IOException("SimpleFTP was not allowed to send the file: " + response);
        }
        Logger.log(this, "Connected to "+url);
    
        OutputStream output;
        if (zipped)
            output = new GZIPOutputStream(dataSocket.openOutputStream(),GZIPOutputStream.COMPRESSION_BEST);
        else
            output = dataSocket.openOutputStream();
    
        byte[] buffer = new byte[512];
        int bytesRead = 0;
    
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
        }
    
        output.flush();
        output.close();
        output = null;
        dataSocket.close();
        dataSocket=null;
    
        response = readLine();
        return response.startsWith("226 ");
    }
    

    The readline() and sendline("") methods read or write to the ftp decision-making, a line ended with CR and I so need to send FTP commands

    I think that everything is ok, for this problem I find in a forum that the problem will be the use of ASCII in FTP method, but I change to BIN

    Any idea?

    Thank you in advance!

    Hello

    Finally, I solved the problem.

    I find the solution in the documentation GZIPOutputStream

    You must pass OutputStream to GZIPOutputStream, zipping it and then you must close GZIPOutputStream but you must use the original OutputStream.

    So in my SimpleFTP class I have to write about gzip, close it then flush() and close() the original outputstream.

    Knit

    I had the new method of stor() here to see

    /**
         * Sends a file to be stored on the FTP server. Returns true if the file
         * transfer was successful. The file is sent in passive mode to avoid NAT or
         * firewall problems at the client end.
         */
        public synchronized boolean stor(InputStream inputStream, String filename, boolean zipped) throws IOException {
    
            sendLine("PASV");
            String response = readLine();
            if (!response.startsWith("227 ")) {
                throw new IOException("SimpleFTP could not request passive mode: " + response);
            }
    
            String ip = null;
            int port = -1;
            int opening = response.indexOf('(');
            int closing = response.indexOf(')', opening + 1);
            if (closing > 0) {
                String dataLink = response.substring(opening + 1, closing);
                String[] tokenizer = Functions.splitString(dataLink, ',', -1);
                try {
                    ip = tokenizer[0] + "." + tokenizer[1] + "." + tokenizer[2] + "." + tokenizer[3];
                    port = Integer.parseInt(tokenizer[4]) * 256 + Integer.parseInt(tokenizer[5]);
                } catch (Exception e) {
                    throw new IOException("SimpleFTP received bad data link information: " + response);
                }
            }
            String url = "socket://" + ip + ":" + port + urlParam;
            Logger.log(this, "Try to open passive connection to "+url);
            SocketConnection dataSocket = (SocketConnection) Connector.open(url);
            dataSocket.setSocketOption(SocketConnection.LINGER, 5);
            dataSocket.setSocketOption(SocketConnection.DELAY, 5);
    
            sendLine("STOR " + filename);
    
            response = readLine();
            if (!response.startsWith("125 ")&&!response.startsWith("150 ")) {
                dataSocket.close();
                dataSocket=null;
                throw new IOException("SimpleFTP was not allowed to send the file: " + response);
            }
            Logger.log(this, "Connected to "+url);
    
            OutputStream output = dataSocket.openOutputStream();
            byte[] buffer = new byte[512];
            int bytesRead = 0;
    
            if (zipped){
                GZIPOutputStream zipOutput = new GZIPOutputStream(output,6, GZIPOutputStream.MAX_LOG2_WINDOW_LENGTH);;
                while (!isAskForAbort() && (bytesRead = inputStream.read(buffer)) != -1) {
                    zipOutput.write(buffer, 0, bytesRead);
                }
                zipOutput.close();
            } else {
                while (!isAskForAbort() && (bytesRead = inputStream.read(buffer)) != -1) {
                    output.write(buffer, 0, bytesRead);
                }
            }
            if (isAskForAbort()){
                abor();
                output.close();
                output = null;
                dataSocket.close();
                dataSocket=null;
                try {
                    setAskForAbort(false);
                } catch (BbException e) {/*nothing to do. Here ftp is conected*/}
                return false;
            }
            output.flush();
            output.close();
            output = null;
            dataSocket.close();
            dataSocket=null;
    
            response = readLine();
            return response.startsWith("226 ");
        }
    

    Thank you much for the help.

  • Having a problem in DateFormat when the time zone is changed...

    Hi, the following code converts a Date string to a Date which I am able to successfully... The problem I am facing is when I put the Moble zone as the format of Casablance (GMT) and my Format for a Date string is "2009-09-27 03:02:00:00 of" "" then I am to get the hour of the date as "kills Sep 27 03:02:00 GMT 2009", but when the time zone is changed to Canberra, Sydney (+ 10), the Date is "Mon Sep 28 19:37:13 Australia/Sydney 2009"... which is not the correct date in strgin Format ' "» nicely in this matter helps no matter what time zone after the conversion, I should get the date given to a string date... help kindly with respect to thei...

    public static Date getDateTmeFrmStrgFormat(String strDate)
         {
    
             Date date;
             String month,day,year,hour,min,sec;
                         month = strDate.substring(0,strDate.indexOf("/"));
                if(month.length() < 2) month = "0" + month;
    
                strDate = strDate.substring(strDate.indexOf("/") + 1);
    
                day = strDate.substring(0,strDate.indexOf("/"));
                if(day.length() < 2) day = "0" + day;
    
                strDate = strDate.substring(strDate.indexOf("/") + 1);
    
                year = strDate.substring(0,strDate.indexOf(" "));
    
                strDate = strDate.substring(strDate.indexOf(" ") + 1);
    
                hour = strDate.substring(0,strDate.indexOf(":"));
                if(hour.length() < 2) hour = "0" + hour;
    
                strDate = strDate.substring(strDate.indexOf(":") + 1);
    
                 min = strDate.substring(0,strDate.indexOf(":"));
                if(min.length() < 2) min = "0" + min;
    
                strDate = strDate.substring(strDate.indexOf(":") + 1);
    
                sec = strDate;
                if(sec.length() < 2) sec = "0" + sec;
    
                //sec = "00";
                date = new Date (HttpDateParser.parse(year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec));
                //date = new Date (HttpDateParser.parse(year + "-" + month + "-" + day + " " + hour + ":" + 00 + ":" + 00)); 
    
                return date;
            }
    

    Like this.  This code is NOT tested, it is presented only to explain the use of the calendar in this situation.

    public static Date getDateTmeFrmStrgFormat(String strDate)     {         String month,day,year,hour,min,sec;         month = strDate.substring(0,strDate.indexOf("/"));         strDate = strDate.substring(strDate.indexOf("/") + 1);         day = strDate.substring(0,strDate.indexOf("/"));         strDate = strDate.substring(strDate.indexOf("/") + 1);         year = strDate.substring(0,strDate.indexOf(" "));         strDate = strDate.substring(strDate.indexOf(" ") + 1);         hour = strDate.substring(0,strDate.indexOf(":"));         strDate = strDate.substring(strDate.indexOf(":") + 1);         min = strDate.substring(0,strDate.indexOf(":"));         strDate = strDate.substring(strDate.indexOf(":") + 1);         sec = strDate;         Calendar cl = Calendar.getInstance();         cl.set(Calendar.YEAR,|Integer.parseInt(year));         cl.set(Calendar.MONTH,|Integer.parseInt(month)-1);         cl.set(Calendar.DATE,|Integer.parseInt(day));         cl.set(Calendar.HOUR_OF_DAY,|Integer.parseInt(hour));         cl.set(Calendar.MINUTE,|Integer.parseInt(min));         cl.set(Calendar.SECOND,|Integer.parseInt(sec));         return cl.getTime();     }
    
  • Problem connecting to the server by using the url with the logical name!

    Hi all!

    I looked for information on this subject, but have not seem to found a solution.

    I'm developing a Smartphone application that needs to connect to a server to retrieve data. Then I use a direct connection with the correct settings (I hope):

    URL = "url of the server" + "deviceside:true" + "AFN:...» »

    The problem is that the connection should be done without Hardcoding the "apn". These are the tests I've done so far (assuming I'm always add the ' deviceside: true ' parameter):

    URL (logical name) + AFN OK!
    FAILURE of the URL (logical name)
    URL (static IP) OK!

    * by logical name, I mean a url as www.google.com

    What I need is to use the logical name, without the parameter apn!  Maybe I'm missing another parameter that I don't know?

    Some additional info that might be useful! :

    -The server is a server of Vodafone, which, as has been explained to me, should be on the list of white of the RIM (not sure what that means, but I guess it has to do with the fact that BB connection through the RIM at one point servers, and be in this list gives a sort of 'privilege' when you browse servers of RIM) , and I don't know it is publicly accessible as (see following)

    -An android version of the application works fine without Hardcoding the AFN and using the logical name (I guess it has to do with the RIM servers!)

    Any help or ideas towards the solution that it is greatly appreciated!  If I'm missing some info that you think I should add! Please tell me!

    Thanks for your help!

    Juan

    Thanks Peter!

    I could solve it by looking at the code of the alternative of the Api network in the link sent you me!

    The solution was the addition of the ConnectionUID parameter to the url String!  as to why this solves the problem I still don't understand it! (If you can enlighten me with the reason, I would be very grateful)

    This value is found in the service books!, I have the zip code just in case it helps someone!

    Hogshead string = null;

    Full book sb = ServiceBook.getSB ();

    Reviews [] ServiceRecord = sb.getRecords ();

    for (int i = 0; i)< records.length;="">

    {

    String cid = records [i] .getCid () .toLowerCase ();

    String uid = records [i] .getUid () .toLowerCase ();

    If ((cid.indexOf ("wptcp")! = - 1) & (uid.indexOf ("wifi") ==-1) & (uid.indexOf ("mms") ==-1))

    {

    Hogshead = records [i] .getUid ();

    }

    }

    then add the parameter: ConnectionUID = Hogshead

    Once again, thank you!

  • Problem in getting number of Mobile Contact list

    Hello

    I write the code for the number of cell phone contacts list. But if there are two number (phone number, mobile phone number) in a single contact, then I'm unable and differentiate.

    BlackBerryContactList contacts = null;
            try {
                PIM pim = PIM.getInstance();
                contacts = (BlackBerryContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
                PIMItem item = contacts.choose();
                if (item == null || !(item instanceof Contact)) {
                    return;
                }
    
    BlackBerryContact contact = (BlackBerryContact) item;
    
                int nTelNoCount = contact.countValues(BlackBerryContact.TEL);
    
                for (int i = 0; i < nTelNoCount; ++i)
    
                {
    
                    int telAttrs = contact.getAttributes(BlackBerryContact.TEL, i);
    
                    if ((telAttrs & BlackBerryContact.TEL) != 0 || contacts.isSupportedField(BlackBerryContact.ATTR_MOBILE)) {
    
                        String str;
                        Logger.out(m_strClassName,"---------3");
                        str = textbox.getText().trim();
                        if (str.equals(""))
    
                        {
    
                            String strMob = contact.getString(BlackBerryContact.TEL, i).trim();
    
                            Logger.out("InviteFriendScreen", "----------------strMo" + strMob + "--len--" + strMob.length() + "---" + strMob);
    
                            textbox.setText(strMob);
    
                        }
    
                        else if (str.indexOf((contact.getString(BlackBerryContact.TEL, i))) != -1)
    
                        {
    
                            Dialog.alert(Constants.ALERT_ENTER_DIFFERENT_NUMBER);
    
                        }
                        else
    
                        {
                            String addContact = contact.getString(BlackBerryContact.TEL, i);
                            Logger.out(m_strClassName,"---------4");
                            if (str.indexOf(addContact) == -1)
    
                            {
                                Logger.out(m_strClassName,"---------5");
                                textbox.setText(str + "," + addContact);
                            }
                        }
    
                        break;
    
    //              } else {
    //
    //                  Dialog.alert(Constants.ALERT_ADD_ONLY_MOBILE_NUMBER);
                    }
    
                }
    
            }
            catch (PIMException e)
            {
    
            }
            try
    
            {
                Logger.out(m_strClassName,"---------7");
                contacts.close();
    
            }
    
            catch (PIMException e)
    
            {
                Logger.out(m_strClassName,"---------8");
                e.printStackTrace();
    
            }
        }
    

    Now here when I added only the contact number of work and is not added and showing an alert (add only Mobile number). But if a person has mobile number and contact number of work, then that's all first showing the alert and then adding the mobile number.

    How can I solve this problem?

    Yes, I solve it...

  • Problem with Listfield and expandable background bitmap

    Hello

    I struggled for a while to make this work, and after searching the forums and knowledge base, I can't seem to do right. What I try to do is:

    1 header is a bitmap expandable width of 1px to the bottom, more a company logo bitmap, with position fixed (only the items below it is scrolling)

    2. use a listfield, which contains 4 elements:

    -1 px wide image bitmap background for each line, repeat horizontally

    -1 px width bitmap image of background for the highlighted line, repeat horizontally

    -an icon bitmap for each line on the left side, and

    -a title text for each line

    Here is the screenshot and code what I've done so far, so the problem is:

    1. when I scroll, scrolls the header (what I want is to position of the header is fixed, only the listfield below is scrolling).

    2. the background image is only painted on the first line of the listfield, how can I do this with all the lines?

    3. How is - that replace you the default blue color on a bitmap background highlighted line?

    public class AjsScreen extends MainScreen{
    
        // constructor
        public AjsScreen() {
            super();
    
            // --- 1. Main Header --- \\
    
            //prepare images upfront
            final Bitmap bgHeader = Bitmap.getBitmapResource("bg-header.jpg"); // repeating background image for main header
            final Bitmap logoAjs = Bitmap.getBitmapResource("logo-ajs.png"); // company logo in main header
            final Bitmap bgMenu = Bitmap.getBitmapResource("bg-menu.jpg"); // repeating background image for main menu
            final Bitmap bgMenuRo = Bitmap.getBitmapResource("bg-menu-ro.jpg"); // repeating background image for main menu (highlighted)
    
            //images used as repeating background
            final Background backgroundHeader = BackgroundFactory.createBitmapBackground(bgHeader, 0, 0, Background.REPEAT_VERTICAL); //REPEAT HORIZONTAL ???
            Background backgroundMenu = BackgroundFactory.createBitmapBackground(bgMenu, 0, 0, Background.REPEAT_VERTICAL);
            Background backgroundMenuRo = BackgroundFactory.createBitmapBackground(bgMenuRo, 0, 0, Background.REPEAT_VERTICAL);
    
            //main header background, with stretched width, and fixed height
            HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH){
                public int getPreferredHeight() {
                    return 55;
                }
            };
            hfm.setBackground(backgroundHeader);
    
            //main header logo
            BitmapField bf = new BitmapField(logoAjs);
            bf.setPadding(2, 0, 0, 5);//clockwise from top, right, bottom, left
            hfm.add(bf);
    
            add(hfm);
    
            // --- 2. Main Menu --- \\
    
            ListField lf = new ListField(){ //4, USE_ALL_HEIGHT | USE_ALL_WIDTH
                protected void paint(Graphics graphics) {
                    // TODO Auto-generated method stub
                    super.paint(graphics);
                }
            };
            lf.setBackground(backgroundMenu);
            lf.setRowHeight(40);
    
            final Vector le = new Vector();
            le.addElement("Menu 1");
            le.addElement("Menu 2");
            le.addElement("Menu 3");
            le.addElement("Menu 4");
            le.addElement("Menu 5");
            le.addElement("Menu 6");
            le.addElement("Menu 7");
            le.addElement("Menu 8");
            le.addElement("Menu 9");
    
            lf.setCallback(new ListFieldCallback() {
                public int indexOfList(ListField listField, String prefix, int string) {
                    return le.indexOf(prefix, string);
                }
                public int getPreferredWidth(ListField listField) {
                    return Display.getWidth();
                }
                public Object get(ListField listField, int index) {
                    return le.elementAt(index);
                }
                public void drawListRow(ListField listField, Graphics g, int index, int y, int w) {
                    g.drawBitmap(0, y, bgMenu.getWidth(), bgMenu.getHeight(), bgMenu, 0, 0);
    
                    String text = (String) le.elementAt(index);
                    g.drawText(text, 0, y, 0, w);
                }
            });
    
            lf.setSize(le.size());
    
            add(lf);
    
        }
    
    }
    

    Thank you very much

    Yusuf

    «1. when I scroll, scrolls the header (what I want is in the position of the header is fixed, only the listfield below scrolls).»

    ListField will do this for you.  I suggest that you look at setTitle in the screen and put your part not scrolling in there

    '2. the background image is only painted on the first line of the listfield, how can I do this with all the lines?'

    Don't know (haven't looked hard) how your background is painted on the first line, but this line:

    g.drawBitmap (0, bgMenu.getWidth (), bgMenu.getHeight (), bgMenu, 0, 0);

    doesn't seem to work for your lines.  You need to paint the entire width like this.

    ". How do replace you line default highlighted in blue on a background bitmap? »

    There are a number of ways to do I think.  Is to determine if you paint the selected line and act accordingly

    (if (listField.getSelectedInde () == index) {...})

    } else {}

    }

    Some people I think drawFocus override for the ListField - if you're looking for tour you will find examples.

    I think there are other ways, I'm looking round I think that this question has been asked before.

  • DateFormat of DateField causing problem JDE 4.5

    I have a DateField, which uses the DateFormat class to display Date

    SimpleDateFormat myDtTm = new SimpleDateFormat ("YYYY/MM/dd hh: mm aa");

    DateField _dateField = new DateField ("Date:", System.currentTimeMillis (), myDtTm, DateField.DATE_TIME);

    Add (_dateField);

    DateField is added to the main screen

    Problem:

    As in hh hour is represented as 05 (i.e. two-digit)

    I tested the application for 4.5 and Simulator Date time does not appear as hh(i.e. 05 two digits), it is shown as 5 (i.e. h )

    Why does. I'm using _dateField.toString () and obtaining each field as day, month, year, minutes and seconds

    public Calendar convertStringToDate(String dateTime)
    {
    Calendar date = Calendar.getInstance();            date.set(Calendar.DATE,Integer.parseInt(dateTime.substring(0, 2)));
    date.set(Calendar.MONTH, Integer.parseInt(dateTime.substring(3,5))-1);
    date.set(Calendar.YEAR, Integer.parseInt(dateTime.substring(6,10)));
    date.set(Calendar.HOUR, Integer.parseInt(dateTime.substring(11,13)));
    date.set(Calendar.MINUTE, Integer.parseInt(dateTime.substring(14,16)));
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    
    String am_pm = dateTime.substring(17);
    
    //getIntAM_PM will return AM or PM
    
    int am_pmInt = getIntAM_PM(am_pm);
    date.set(Calendar.AM_PM,am_pmInt);
    return date;
    }
    

    Here, I get error because the time is only a number IE 5, during recovery, so 5: which is not analyze in Int

    Help, please...

    no need

    indexOf(':')

    will work fine.

  • String IndexOf does not work

    Hello

    I received the text of an email and store it in a string...

    I have problem to parse this string... I think it's the encoding problem... but I don't know...

    Text is the following:

    Client:

    Gary Hong

    WINE:

    XXXXX

    Business phone:

    (123) 456

    Text.Substring ("Customer") is ok

    but when I do

    Text.Substring ("Business Phone :") it doesn't... returns-1... ")

    someone has an idea?

    garyyanyan wrote:

    How can I check?

    String.Replace (Characters.NO_BREAK_SPACE, ' ') before the use of the indexOf.

  • BlackBerry, need help Urgent network connection problem

    Hi all

    I put an application Blackberry OS 6 and 7 of the OS, this application uses the salesforce connection and its other api calls.

    My application works well here in India, but when I deliver it to the customer I had connection timeout error (in the United States). I tried all the string connection possible but still unable to solve the problem at my end.

    Can someone help me with this problem?

    Its very urgent. I need to connect via WAP2 and the code for my connection parameter string is:

    "

    Dim connectionString As String ="";

    String carrierUid = getCarrierBIBSUid();
    String wap2 = getWAP2ServiceRecord();
    If (carrierUid! = null) {}
    Otherwise, use the Uid to build a valid transport BIBS
    request
    Logger.logEventInfo ("uid is:" + carrierUid);
    connectionString = '; deviceside = false; connectionUID ="
    + carrierUid + ";". " » ;
    } ElseIf (wap2! = null) {}
    connectionString = '; deviceside = true; connectionUID =' + wap2;
    } else {}
    A carrier coverage, but not the BIBS. So use TCP of the carrier
    network
    Logger.logEventInfo ("no Uid");
    connectionString = '; deviceside = true;
    }

    return connectionString;

    "

    the definations of function are:

    "

    private static String getCarrierBIBSUid() {}
    Reviews [ServiceRecord] is ServiceBook.getSB () .getRecords ();.

    for (int i = 0; i)< records.length;="" i++)="">
    If (records [i] .getCid () .toLowerCase () .equals ("ippp")) {}
    If (records [i] .getName () .toLowerCase () .indexOf ("bibs") > = 0) {}
    Records return [i] .getUid ();
    }
    }
    }

    Returns a null value.
    }

    private static String getWAP2ServiceRecord() {}
    Full book sb = ServiceBook.getSB ();
    Reviews [] ServiceRecord = sb.findRecordsByCid ("WPTCP");
    String uid = null;
    for (int i = 0; i)< records.length;="" i++)="">
    Search through all records of service to find the
    valid non-Wi-Fi and non - MMS
    Booklet of WAP 2.0 Gateway Service.
    If (records [i] .isValid () &! records [i] .isDisabled ()) {}
    If (records [i] .getUid ()! = null)
    & records [i] .getUid () .length ()! = 0) {}
    If ((records [i] .getCid () .toLowerCase () .indexOf ("wptcp")! = - 1))
    & (records [i] .getUid () .toLowerCase)
    .indexOf("wifi") is - 1).
    & (records [i] .getUid () .toLowerCase)
    .indexOf ("mms") ==-1)) {}
    UID = records [i] .getUid ();
    break;
    }
    }
    }
    }
    If (uid! = null) {}
    Open a connection WAP 2
    Returns the uid;
    } else {}
    Consider another action transport or alternative.
    Returns a null value.
    }

    }

    "

    I get "unable to select the descriptor of adequate transport for the url:

    "https://login.salesforce.com/services/oauth2/token ...". "

    any help is appreciated

    Thank you

    Manish Kumar

    Hi all

    I solved the problem.

    My connection setting requires '; EndToEndDesired' for HTTPS request (although it works for me without this parameter). I tested the app using deviceanywhere and after the addition of this application of the setting run perfectly.

    connectionString = '; deviceside = true; connectionUID =' + wap2
    + "; EndToEndDesired ';

    Thank you for your comment stone

    I was actually using reproductive WAP2.

    Version of the client OS is BB OS 7 (on the Torch 2 9810)

    Concerning

    Manish Kumar

  • Problem with PersistentObject.

    Hi all

    I am new to the BB and bad English (I'm Thai), sorry if you confuse in my words. I have a project that has thead to download the server image and record in PersistentObject using my CustomHashTable. The problem is that I have an error message "NonPersistableObjectException", which is based on the method "persistentObject.commit ();" in "getEncodedImage()" when I debug, here is my code.

    public class TestApp extends UiApplication{
    
        public static void main(String[] args) {      UiApplication app = new TestApp();        app.enterEventDispatcher();   }
    
      TestApp(){        pushScreen(new TestScreen()); }}
    
    public class TestScreen extends MainScreen{
    
       EncodedImage encodedImage;    CustomHashTable persistentHashtable;  private DataInputStream dis;  private byte[] encodeData;    private ByteArrayOutputStream byteStream; PersistentObject persistentObject = PersistentStore.getPersistentObject(0x61a0ab9f850b5c9bL);
    
      TestScreen(){     super();      if (persistentObject.getContents() == null) {         persistentHashtable = new CustomHashTable();          persistentObject.setContents(persistentHashtable);            persistentObject.commit();        }else {           persistentHashtable = (CustomHashTable)persistentObject.getContents();        }     encodedImage = getEncodedImage("http://download.magikmobile.mobi/scodp/mpreview.do?idc=683979&size=140x90&","4952","hot");       encodedImage = scaleImage(encodedImage);
    
          this.setTitle("Test my app");     this.add(new BitmapField(encodedImage.getBitmap()));  }
    
      public EncodedImage scaleImage(EncodedImage image) {      int displayWidth = Fixed32.toFP(Display.getWidth());      int imageWidth = Fixed32.toFP(image.getWidth());      int scalingFactor = Fixed32.div(imageWidth, displayWidth);        EncodedImage scaledImage = image.scaleImage32(scalingFactor, scalingFactor);      return scaledImage;   }
    
      public EncodedImage getEncodedImage(String url, String id, String catagory) {
    
           EncodedImage enc = null;      if (persistentHashtable.containsKey("EncodeImage01")) {           enc = (EncodedImage)persistentHashtable.get("EncodeImage01");     }
    
            if (enc != null) {          System.out.println(">>>>>  image not null");            return enc;        } else {            System.out.println(">>>>>  image null");            try {                String newURL = null;                while (url.indexOf("&") > 0) {                    newURL = url.substring(0, url.indexOf("amp;"));                    url = url.substring(url.indexOf("amp;") + 4);                    url = newURL + url;                }
    
                    newURL = null;                String suffix = "";                HttpConnection httpConnection = (HttpConnection) Connector.open(url+suffix);                httpConnection.setRequestMethod(HttpConnection.GET);                if (httpConnection.getResponseCode() == 302) {                   boolean b = true;                    while (b) {                        if (httpConnection.getResponseCode() == 200) {                            b = false;                            break;                        }                        httpConnection = (HttpConnection) Connector.open(httpConnection.getHeaderField("Location"));                    }                }                dis = httpConnection.openDataInputStream();                int length = (int) httpConnection.getLength();                if (length > 0) {                    encodeData = new byte[length];                    dis.readFully(encodeData);                } else {                    byteStream = new ByteArrayOutputStream();                    int ch;                    while ((ch = dis.read()) != -1) {                        byteStream.write(ch);                    }                    encodeData = byteStream.toByteArray();                    byteStream.close();                    byteStream = null;                }                dis.close();                dis = null;                httpConnection.close();                httpConnection = null;                try {                    enc = EncodedImage.createEncodedImage(encodeData, 0, encodeData.length);                } catch (OutOfMemoryError e) {                  System.out.println(">>>>  OutOfMemoryError");                    e.printStackTrace();                    return null;                } catch (NullPointerException e) {                 System.out.println(">>>>  NullPointerException");                    e.printStackTrace();                    return null;                } catch (IllegalArgumentException e) {                 System.out.println(">>>>>  IllegalArgumentException");                    e.printStackTrace();                    return null;                } catch (ArithmeticException e) {                  System.out.println(">>>>  ArithmeticException");                    e.printStackTrace();                    return null;                }                encodeData = null;                persistentHashtable.put("EncodeImage01", enc);                persistentObject.commit();                catagory = null;                id = null;                url = null;                return enc;            } catch (SecurityException ex) {                ex.printStackTrace();                return null;            } catch (IOException ex) {                ex.printStackTrace();                return null;            }        }    }
    
    }
    
    public class CustomHashTable extends Hashtable implements Persistable{
    
    }
    

    What should I do?

    Thank you very much

    ~ MazMellow ~.

    I see no problem here, hashtable will have any object as second parameter to the function, so you can put hashtable in storage of place (it is supported and commonly used):

    Hash hash = new Hashtable();

    data Byte [] = image.getData ();

    Hash.put ("first", data);

    ....

    ...

    ...

    ....

    data Byte [] (byte []) = hash.get ("first");

    image = EncodedImage.createEncodedImage (data,...);

  • ListField focus problem.

    Hi people,

    I have a problem with listfield focus. in the 8900 v4.6.1, the last update does not disappear when I select a new line.

    Do the invalidate in line works, but navigation has become with the slow performance.

    Code:

    package mypackage;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Hashtable;
    import java.util.Vector;
    
    import javax.microedition.lcdui.Font;
    
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.BitmapField;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.component.ListField;
    import net.rim.device.api.ui.component.ListFieldCallback;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    
    public final class HelpScreen extends CustomMainScreen {
        protected boolean onSavePrompt() {
            try {
                save();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.err.println("Excecao HelpScreen 1 " + e.getClass() + " - " + e.getMessage());
                e.printStackTrace();
            }
            return true;
        }
    
        private Vector content = null;
        private ListHelpScreen callback;
    
        public HelpScreen() {
    
            // System.out.println("HelpScreen");
    
            setBanner(new BitmapField(Bitmap.getBitmapResource(ScreenManager.getStringProperty("helpscreen.banner"))));
            setBackground(BackgroundFactory.createSolidBackground(0x434343));
            content = getVector();
    
            ListField list = initCallbackListening();
    
            list.setSize(content.size());
            // list.setRowHeight(62);
            int rowheight = ScreenManager.getPositionAtKey("helpscreen.listfield.rowheight");
    
            list.setRowHeight(rowheight);
            add(list);
            LabelField copyright = new LabelField("Cielo Mobile " + ServerRequests.version + "\n" + "© Todos os direitos reservados",
                    Field.USE_ALL_WIDTH) {
                protected void paint(Graphics graphics) {
                    graphics.setColor(Color.WHITE);
                    super.paint(graphics);
                }
    
            };
            copyright.setBackground(BackgroundFactory.createSolidBackground(0x434343));
            copyright.setPadding(ScreenManager.getPositionAtKey("helpscreen.copyright.padding.top"),
                    ScreenManager.getPositionAtKey("helpscreen.copyright.padding.right"),
                    ScreenManager.getPositionAtKey("helpscreen.copyright.padding.bottom"),
                    ScreenManager.getPositionAtKey("helpscreen.copyright.padding.left"));
            copyright.setPosition(ScreenManager.getPositionAtKey("helpscreen.copyright.position"));
    
            copyright.setFont(getFont().derive(Font.STYLE_PLAIN, 14));
    
            add(copyright);
    
        }
    
        private Vector getVector() {
            Vector menuItems = new Vector();
            Hashtable currentElement = new Hashtable();
            Class classs = null;
            try {
                classs = Class.forName(this.getClass().getName());
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                System.err.println("Excecao HelpScreen 2 " + e.getClass() + " - " + e.getMessage());
                e.printStackTrace();
            }
            InputStream stream = classs.getResourceAsStream("/fraseologia.properties");
            PropertiesUtil properties = new PropertiesUtil();
            try {
                properties.load(stream);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.err.println("Excecao HelpScreen 3 " + e.getClass() + " - " + e.getMessage());
                e.printStackTrace();
            }
            currentElement.put("title", "1 " + ((String) properties.getProperties().get("pergunta1")).toUpperCase());
            menuItems.addElement(currentElement);
    
            currentElement = new Hashtable();
            currentElement.put("title", "2 " + ((String) properties.getProperties().get("pergunta2")).toUpperCase());
            menuItems.addElement(currentElement);
    
            currentElement = new Hashtable();
            currentElement.put("title", "3 " + ((String) properties.getProperties().get("pergunta3")).toUpperCase());
            menuItems.addElement(currentElement);
    
            currentElement = new Hashtable();
            currentElement.put("title", "4 " + ((String) properties.getProperties().get("pergunta4")).toUpperCase());
            menuItems.addElement(currentElement);
    
            currentElement = new Hashtable();
            currentElement.put("title", "5 " + ((String) properties.getProperties().get("pergunta5")).toUpperCase());
            menuItems.addElement(currentElement);
    
            currentElement = new Hashtable();
            currentElement.put("title", "6 " + ((String) properties.getProperties().get("pergunta6")).toUpperCase());
            menuItems.addElement(currentElement);
    
            currentElement = new Hashtable();
            currentElement.put("title", "7 " + ((String) properties.getProperties().get("pergunta7")).toUpperCase());
            menuItems.addElement(currentElement);
    
            currentElement = new Hashtable();
            currentElement.put("title", "8 " + ((String) properties.getProperties().get("pergunta8")).toUpperCase());
            menuItems.addElement(currentElement);
            //
            // currentElement = new Hashtable();
            // currentElement.put("title", "Cielo Mobile " + ServerRequests.version);
            // currentElement.put("text", "© Todos os direitos reservados");
            // menuItems.addElement(currentElement);
    
            return menuItems;
        }
    
        private ListField initCallbackListening() {
            callback = new ListHelpScreen();
            ListField listField = new ListField() {
    
                protected boolean navigationClick(int status, int time) {
                    // TODO melhorar essa logica
                    if (this.getSelectedIndex() < 8) {
                        UiApplication.getUiApplication().pushScreen(new AnswersScreen(this.getSelectedIndex()));
                    }
    
                    return true;
                }
            };
            listField.setCallback(callback);
            listField.setFont(this.getFont().derive(Font.STYLE_PLAIN, 16));
    
            // listField.setRowHeight(-3);
            return listField;
        }
    
        private class ListHelpScreen implements ListFieldCallback {
            private int lastIndex = 0;
    
            public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
    
                Hashtable currentCellInformations = ((Hashtable) content.elementAt(index));
    
                Bitmap image = null;
                if (index == listField.getSelectedIndex()) {
                    image = Bitmap.getBitmapResource(ScreenManager.getStringProperty("helpscreen.listfieldcallback.image.hint"));
                } else {
                    image = Bitmap.getBitmapResource(ScreenManager.getStringProperty("helpscreen.listfieldcallback.image"));
                }
    
                graphics.drawBitmap(0, y, image.getWidth(), image.getHeight(), image, 0, 0);
    
                String text = (String) currentCellInformations.get("title");
                graphics.setColor(Color.WHITE);
                graphics.drawText(text, ScreenManager.getPositionAtKey("helpscreen.listfieldcallback.inicialoffset.x"),
                        ScreenManager.getPositionAtKey("helpscreen.listfieldcallback.inicialoffset.y") + y);
                 listField.invalidate(lastIndex);
                lastIndex = index;
            }
    
            public Object get(ListField listField, int index) {
                return content.elementAt(index);
            }
    
            public int getPreferredWidth(ListField listField) {
                return ScreenManager.getPositionAtKey("helpscreen.listfieldcallback.preferredwidth");
            }
    
            public int indexOfList(ListField listField, String prefix, int start) {
                return content.indexOf(prefix, start);
            }
        }
    }
    

    Could you help me please with other alternatives?

    Thanks in advance.

    It was the solution for me

    ListField listField = new ListField() {
                private int lastIndex = 0;
    
                public int moveFocus(int amount, int status, int time) {
                    lastIndex = getSelectedIndex();
                    invalidate(lastIndex);
                    return super.moveFocus(amount, status, time);
                }
    

    Thank you!!!

Maybe you are looking for

  • Very proud new owner of the Qosmio G10

    Hi, just thought id' say hello, like a new owner Qosmiao G10, I run an it company in are *, UK and we are a Dell, HP and Microsoft Training Center. I've had loads of laptops over the years, got cela today and wow its amazing! I have a small form of M

  • VIXIA HF R600 live stream

    Is their anyway I could connect my VIXIA HF R600 to my laptop 10 Windows and display the cameras?

  • How to choose the applicable fix

    my computer crashed and recovery gives me two patches to download, but I have to choose one and the right one. If not who will damage my system... so, how can I know that to download

  • General questions LaserJet P1102w

    I'm considering buying a LaserJet P1102w. Before I do, I want to ask you a few questions: Can we create an ad - hoc network? Can we create both an ad - hoc network & join my current wireless network? Are there known issues with Xubuntu 12.10 and OS X

  • Office Jet Pro 8600, how to install the full features of MAC OS x 10.8 software.

    Must be able to use all the features of SCANNING (double-sided), but can't seem to find a COMPLETE package of software for OS 10.8 Mountain Lion