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
Posts: 19
Registered: ‎05-25-2011
My Device: All
My Carrier: Developer

Application run on simulater but not in mobile

Hi,

Que-1

My application is give below based on blackberry os4.6.1 . i have not use code signing but application is working fine & value has been stored in persistent object that can be access any time. but when i try to install on blackberry mobile 8900 then face an error "Attempts unable to access secure api". how to resolve this error?

Que-2

To resolving this error i have purchased code signing key & install successfully in my pc. but when i install same application with the signing autority of .cod file on same mobile then also facing same error.

 

Please resolve as so possible.

Thanks

Ankit Saini

 

/*
 * MyApp.java
 *
 * © <your company here>, 2003-2008
 * Confidential and proprietary.
 */

package demos;



import net.rim.device.api.ui.UiApplication;

/**
 * This class extends the UiApplication class, providing a
 * graphical user interface.
 */
public class MyApp extends UiApplication
{
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MyApp theApp = new MyApp();      
        theApp.enterEventDispatcher();
    }
   

    /**
     * Creates a new MyApp object
     */
    public MyApp()
    {       
        // Push a screen onto the UI stack for rendering.
        pushScreen(new MyScreen());
    }   
}

/*
 * MyScreen.java
 *
 * © <your company here>, 2003-2008
 * Confidential and proprietary.
 */

package demos;


import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
class MyScreen extends MainScreen implements FieldChangeListener {
    class1 mOptions = new class1();
    BasicEditField mUrl = new BasicEditField("Url:","www");
    ButtonField mLoad = new ButtonField("Load settings",
              ButtonField.CONSUME_CLICK);
    ButtonField mSave = new ButtonField("Save settings",
                   ButtonField.CONSUME_CLICK);
    public MyScreen() {
            add(mUrl);
     mUrl.setChangeListener(this);
          HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
        add(hfm);
      hfm.add(mLoad);
        mLoad.setChangeListener(this);
         hfm.add(mSave);
        mSave.setChangeListener(this);
         //loadSettings();
    }
    private void saveSettings() {
      mOptions.setUrl(mUrl.getText());
    }
    private void loadSettings() {
       mUrl.setText(mOptions.getUrl());
    }
 public void fieldChanged(Field field, int context) {
           if (field == mLoad) {
                  loadSettings();
        } else if (field == mSave) {
                   saveSettings();
        }              
       }
}
/*
 * class1.java
 *
 * © <your company here>, 2003-2008
 * Confidential and proprietary.
 */

package demos;


import net.rim.device.api.collection.util.LongHashtableCollection;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
class class1 {
    private PersistentObject mStore;
    private LongHashtableCollection mSettings;
    private long KEY_URL = 0;
    public class1() {
      // "AppSettings" = 0x71f1f00b95850cfeL
         mStore = PersistentStore.getPersistentObject(0x71f1f00b95850cfeL);
    }
    public String getUrl() {
          Object result = get(KEY_URL);
          return (null != result) ? (String) result : null;
    }
    public void setUrl(String url) {
           set(KEY_URL, url);
    }
    private void set(long key, Object value) {
        synchronized (mStore) {
                mSettings = (LongHashtableCollection) mStore.getContents();
                    if (null == mSettings) {
                       mSettings = new LongHashtableCollection();
             }
              mSettings.put(key, value);
             mStore.setContents(mSettings);
                 mStore.commit();
       }
    }
    private Object get(long key) {
     synchronized (mStore) {
                mSettings = (LongHashtableCollection) mStore.getContents();
                    if (null != mSettings && mSettings.size() != 0) {
                      return mSettings.get(key);
             } else {
                       return null;
                   }
      }
    }
}


Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Application run on simulator but not in mobile

The only time I have seen this error is when a non signed version of the app was installed on the device.  So check that you have signed the app completely and that you install that version.  If you run the Signing Tool, and point it at a cod file, it will tell you if it is signed or not. 

Contributor
Posts: 19
Registered: ‎05-25-2011
My Device: All
My Carrier: Developer

Re: Application run on simulator but not in mobile

hi,

My previous problem "Application run on simulator but not in mobile" has been resolved. but

when i click on load button then saved value is highlited. but could not identify where is store  my values.

the problem is that i am unable to manage stored values in object. so pls tell me how to manage these values.

when i try to store, PersistentObject and LongHashtableCollection object's values in vector with casting then face exception.

so please tell me:

1- should i store my values in vector or not? if yes so how

2-  have you another option to manage object's values.

actully i have knowledge to manage database values by usisng java.utill framwork but unable to manage persistent object types values.please sudjest me right way to work with persistent key & object.

 

 

 

 

Developer
Posts: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone

Re: Application run on simulator but not in mobile

Can you please describe the exception that you facing and please past some code snippet here so we can help you better?.

Highlighted
New Developer
Posts: 16
Registered: ‎06-02-2011
My Device: Curce 9300
My Carrier: Vodafone

Re: Application run on simulator but not in mobile

You can store your own values/object into persistent store.

 

Note: Whatever instance/object you want to persiste/store, that should have implemented interface net.rim.device.api.util.Persistable.

 

You can create your own class e.g. "class Employee implements Persistable{}" and same class object you can save and retrive from persistent store.

Contributor
Posts: 19
Registered: ‎05-25-2011
My Device: All
My Carrier: Developer

Re: Application run on simulator but not in mobile

As per above given example my values/object is stored in persistent store(flash memory).

 

As per your second response i implement interface but how to identify object tyes values or unable to casting as like we can take object value in arraylist & can identify by index position but could not done with persistent store. can you provide me a sample code.

 

As per your third response i can create a class & implement persistable {} but when i save value at once so only can retrieve only same value by load click button. but when i save again new value then unable to retrieve previous value.

problem is that i am unable to manage persistent store values. please provide me a sample code where i can store multiple values & can retrieve specific value.

 

Thanks

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Application run on simulator but not in mobile

I suspect this tutorial might help you with this problem.

 

http://supportforums.blackberry.com/t5/Java-Development/Storing-persistent-data/ta-p/442747

Contributor
Posts: 19
Registered: ‎05-25-2011
My Device: All
My Carrier: Developer

Re: Application run on simulator but not in mobile

Hi,

Thanks a lot for your response. i got the way to work with persistent store but have some dought due to one error in your given application. i try to compile the code but face error on this line

"public MusicStores£() {super(Locale.get(0x0), 0xdca80bb79f102d58L, ids, offsets, Resource.getResourceClass().getResource("MusicStores£.bin")); }"

 

Resource class do not accept getResoucesClass() method. i tried to modify this code but unable to do.

if this application could be run so my issue can be resolved completely. i am still waiting for your response.

 

Thanks

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Application run on simulator but not in mobile

The tutorial is actually supplied by RIM.  You are supposed to follow the instructions and modify the incomplete example to the complete one.  If you have any problems with this, look at the complete (finished) one and see where you have gone wrong.  Once you have finished this exercise, you apply the same logic to your own application. 

 

In this case, the line that you suggest is getting an error is in fact not in the actual source.  I've never seen it, but I understand that there is some building of the resource files as part of the project.  I suspect you might see this problem if you have not included the resource file in your project or not included it correctly. 

 

If this is the case, then you might find the following source useful.  I have removed the resource references in it, so this source will compile without needing a resource file. This is the incomplete version.  You should remove the resource files (*.rr* file) if you have added them to your project and replace your version with this, and it should compile. 

 

Compare this to the version you have, to see what I have changed. 

 

/**
 * MusicStores.java
 * Copyright (C) 2001-2003 Research In Motion Limited. All rights reserved.
 * Altered to remove resource usage.
 */

package com.rim.samples.music_stores;

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.system.*;
import net.rim.device.api.util.*;
import java.util.*;
import net.rim.device.api.i18n.*;

public class MusicStores extends UiApplication {


                //define variables for user interface fields
                private AutoTextEditField namefield;
                private AutoTextEditField addressfield;
                private EditField phonefield;
                private EditField specialtyfield;

                //define variables for persistent data and the object
                //in which this data is stored
                private static Vector _data;
                private static PersistentObject store;

                //create a Save menu item for users to save the music store
                //information that they have entered
                private MenuItem saveItem = new MenuItem(
                                "Save", 110, 10) {
                        public void run() {

                                //create a new StoreInfo object
                                //...

                                //set StoreInfo elements by retrieving text that user entered
                                //...

                                //add the new StoreInfo object to the Vector
                                //...

                                //add the Vector of StoreInfo objects to the persistent store
                                //...

                                //display a dialog box that indicates that data was
                                //saved successfully
                                Dialog.inform("Success");

                                //reset the UI fields to empty
                                namefield.setText(null);
                                addressfield.setText(null);
                                phonefield.setText("");
                                specialtyfield.setText("");
                        }
                };


                //create a Get menu item for users to retrieve information about the
                //last music store that they added
                private MenuItem getItem = new MenuItem("Get", 110, 11) {
                    public void run() {
                        //...
                    }
                };


        //and to the PersistentObject
        static {

                //retrieve a reference to a PersistentObject
                //...

                //set the contents of the PersistentObject to a new Vector
                //if it is empty
                synchronized (store) {
                    //...
                }

                //retrieve the contents of the PersistentObject
                //and store in a Vector
                //...
        }

        public static void main(String[] args) {
                MusicStores app = new MusicStores();
                app.enterEventDispatcher();
        }


        //create a class for a new object type that can persist
        //this class must implement Persistable
        //each object contains information about one music store:
        //name, address, phone number, and musical specialty
        private static final class StoreInfo implements Persistable {

                //define Vector to store data for a single music store
                //...


                //define constant fo reach field in music store object
                //...

                //in the StoreInfo constructor, add a Vector
                //with four empty elements
                public StoreInfo()
                {
                    //...
                }

                //create a method to retrieve a Vector element
                //...

                //create a method to set a Vector element
                //...
        }


        public MusicStores()
        {
                //create a main screen for the application
                MainScreen mainScreen = new MainScreen();

                //set the main screen title
                mainScreen.setTitle(new LabelField("Favorite Music Stores"));

                //create fields in which users can enter information about
                //a music store: store name, address, phone number, and musical specialty
                namefield = new AutoTextEditField("Store Name: ", "");
                addressfield = new AutoTextEditField("Store Address: ", "");
                phonefield = new EditField("Phone Number: ", "", Integer.MAX_VALUE,
                                                BasicEditField.FILTER_PHONE);
                specialtyfield = new EditField("Music Type: ", "",
                                Integer.MAX_VALUE, BasicEditField.FILTER_DEFAULT);


                //add UI fields to the screen and display the screen
                mainScreen.add(namefield);
                mainScreen.add(addressfield);
                mainScreen.add(phonefield);
                mainScreen.add(specialtyfield);

                mainScreen.addMenuItem(saveItem);
                mainScreen.addMenuItem(getItem);

                pushScreen(mainScreen);
    }
}

 

Contributor
Posts: 19
Registered: ‎05-25-2011
My Device: All
My Carrier: Developer

Re: Application run on simulator but not in mobile

Dear Sir,

Sorry to  say but you have left the concept of persistent.

just leave that & please focus on this application and please resolve my issues.

when i save value like NAME: a & NUMBER: 3. it saved in persistent object & when i get values then show NAME: a & NUMBER: 3. now we change values NAME: b & NUMBER: 5 then save. now we get the values then shows

NAME: b & NUMBER: 5.

The mean of my whole description is only that when i get the values then show only saved on lastly like b & 5.

I am unable to retrieve the previous values. for doing this i tried to use arrays but unable to casting with persistent object or vector.

finally i want retrieve all values what i have saved from persistent object and display of it's index possition.

please give me demo or any solution.

 

Thanks

 

package mypackage;
import java.util.Vector;
import javax.microedition.lcdui.List;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class SettingStores extends MainScreen {
    private EditField namefield;
    private EditField numberfield;
    private static Vector _data;
    private static PersistentObject store;
    static {
        store = PersistentStore.getPersistentObject (0xdec6a67096f833cL);
        synchronized (store) {
        if (store.getContents() == null) {
        store.setContents(new Vector());
        store.commit();
        }
        }
        _data = new Vector();
        _data = (Vector) store.getContents();
    }
    public SettingStores() {
        setTitle(new LabelField("Sample Application"));
        namefield = new EditField("Name: ", "");
        numberfield = new EditField("Number: ", "");
        add(namefield);
        add(numberfield);
        addMenuItem(saveItem);
        addMenuItem(getItem);
    }
    private MenuItem saveItem = new MenuItem("Save", 110, 10) {
        public void run() {
        StoreInfo info = new StoreInfo();
        info.setElement(StoreInfo.NAME, namefield.getText());
        info.setElement(StoreInfo.NUMBER, numberfield.getText());
        System.out.println("the value of name:"+ StoreInfo.NUMBER);
        _data.addElement(info);
        synchronized (store) {
        store.setContents(_data);
        store.commit();
        }
        Dialog.inform("Success!");
    }
    };
    private MenuItem getItem = new MenuItem("Get", 110, 11) {
        public void run() {
        synchronized (store) {
        _data = (Vector) store.getContents();
        if (!_data.isEmpty()) {
        StoreInfo info = (StoreInfo) _data.lastElement();
        namefield.setText(info.getElement(StoreInfo.NAME));
        numberfield.setText(info.getElement(StoreInfo.NUMBER));
        }
        }
        }
    };
    }
package mypackage;
import java.util.Vector;
import net.rim.device.api.util.Persistable;
class StoreInfo implements Persistable {
    private Vector _elements;
    public static final int NAME = 0;
    public static final int NUMBER = 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);
    }
    }