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
New Contributor
windlessuser
Posts: 4
Registered: ‎09-17-2012
My Device: Torch 2

Unit testing is throwing this error: class net.rim.device.api.util.Persistable cannot access its superinterface net.rim.vm.Persistable

Hey guys, Kinda new here. I've been experiencing a problem that's just been driving me up the wall. 

 

I have a class that I'm trying to have persist. It implements net.rim.device.api.util.Persistable. Now for some reason, when I  do this:

 

Persistent Object store = PersistentStore.getPersistentObject(M3Session.ID);

 

 

the JVM spases out and complains that class net.rim.device.api.util.Persistable cannot access its superinterface net.rim.vm.Persistable...

 

I have no idea what I'm doing wrong. the net_rim_api.jar is in my class path as it should be, and I'm building my project using this ant script.

 

I'm using Intelij 11 Community edition as my IDE if that helps.

Thanks much for your time

Please use plain text.
New Contributor
windlessuser
Posts: 4
Registered: ‎09-17-2012
My Device: Torch 2

Re: Unit testing is throwing this error: class net.rim.device.api.util.Persistable cannot access its superinterface net.rim.vm.Persistable

This is the class that I'm having persist:

 

package com.transcel.m3.ir;

/**
 * Created with IntelliJ IDEA.
 * User: Marc Byfield
 * Date: 9/10/12
 * Time: 11:24 PM

 */

import net.rim.device.api.system.Application;
import net.rim.device.api.util.Persistable;
import net.rim.device.api.util.StringUtilities;

import java.util.Date;

public class M3Session implements Persistable {

    private String key;
    private long timeCreated;
    public final static long TIMEOUT = 1200000L;
    static String ApplicaitonID = Application.getApplication().getClass().getName();
    static String STORE_NAME = "session_store";
    public final static long ID = StringUtilities.stringHashToLong(ApplicaitonID + STORE_NAME);


    public String getKey() {
        return key;
    }

    public void setKey(final String key) {
        this.key = key;
        Date newTime = new Date();
        this.timeCreated = newTime.getTime();
    }

    public boolean equals(final Object o) {
        if (this == o) return true;
        if (!(o instanceof M3Session)) return false;

        final M3Session m3Session = (M3Session) o;

        return !(key != null ? !key.equals(m3Session.key) : m3Session.key != null);

    }

    public int hashCode() {
        return key != null ? key.hashCode() : 0;
    }

    public String toString() {
        return "M3Session{" +
                       "key='" + key + '\'' +
                       ", timeCreated=" + timeCreated +
                       '}';
    }

    public boolean isValid() {
        return key.length() != 0 && !hasExpired();

    }

    private boolean hasExpired() {
        Date newTime = new Date();
        return newTime.getTime() - this.timeCreated >= TIMEOUT;
    }

    public M3Session(final String key) {
        this.setKey(key);
    }
}

  And this is the class that's using it:


package com.transcel.m3.api;

/**
 * @Author Marc Byfield
 * Date: 9/10/12
 * Time: 11:05 AM
 */

import com.transcel.m3.ir.M3Session;
import com.transcel.m3.ir.User;
import com.transcel.m3.transport.M3Connector;
import com.transcel.m3.transport.Operations;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import org.json.me.JSONObject;

import java.io.IOException;
import java.util.Hashtable;


public class Authentication implements Runnable {

    private M3Session session;
    private static PersistentObject store;
    private User user;

    public Authentication(String user, String pass) {
        store = PersistentStore.getPersistentObject(M3Session.ID);
        this.user = new User(user, pass);
        session = (M3Session) store.getContents();
        if (session == null || !session.isValid()) {
            login(user, pass);
        }
    }

    public M3Session getSession() {
        return session;
    }


    private void login(String username, String pass) {

        Hashtable user = new Hashtable(2);
        user.put("username", username);
        user.put("password", pass);

        String result;
        try {
            result = M3Connector.sendRequest(Operations.LOGIN, user);
            JSONObject sessionJSON = new JSONObject(result);
            if (sessionJSON.has("session_key")) {
                session = new M3Session(sessionJSON.getString("session_key"));
                synchronized (store) {
                    store.setContents(session);
                    store.commit();
                }
            } else {
                synchronized (store) {
                    store.setContents(null);
                    store.commit();
                }
            }

        } catch (IOException ioe) {
            synchronized (store) {
                store.setContents(null);
                store.commit();
            }
        }
    }


    public void run() {
        if (!session.isValid())
            login(user.getPhoneNum(), user.getPass());
        try {
            wait(M3Session.TIMEOUT);
        } catch (InterruptedException ie) {
            this.login(user.getPhoneNum(), user.getPass());
        }
    }
}

 Hope this helps

Please use plain text.
New Contributor
windlessuser
Posts: 4
Registered: ‎09-17-2012
My Device: Torch 2

Re: Unit testing is throwing this error: class net.rim.device.api.util.Persistable cannot access its superinterface net.rim.vm.Persistable

Bump
Please use plain text.
New Contributor
windlessuser
Posts: 4
Registered: ‎09-17-2012
My Device: Torch 2

Re: Unit testing is throwing this error: class net.rim.device.api.util.Persistable cannot access its superinterface net.rim.vm.Persistable

bump

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Unit testing is throwing this error: class net.rim.device.api.util.Persistable cannot access its superinterface net.rim.vm.Persistable

Is this on the device, or on the simulator?

 

Please use plain text.
Trusted Contributor
ankitagrawal
Posts: 141
Registered: ‎02-15-2012
My Device: 9800

Re: Unit testing is throwing this error: class net.rim.device.api.util.Persistable cannot access its superinterface net.rim.vm.Persistable

Hi, 

     Please use following code for persistent store:

 


 

private static PersistentObject store;
private final static long persistentObjectIdForHashData = 0x18efc872d6238a19L;
private static Hashtable hTable;

public static void setDao(Hashtable _hdata)
{
if (_hdata != null)
{
store = PersistentStore.getPersistentObject(persistentObjectIdForHashData);
synchronized (store)
{
store.setContents(_hdata);
store.commit();
}
}
}

public static void removeDAO()
{
store = PersistentStore.getPersistentObject(persistentObjectIdForHashData);
if(store != null)
synchronized (store)
{
store.setContents(null);
store.commit();
}
}

public static Hashtable getDao()
{
store = PersistentStore.getPersistentObject(persistentObjectIdForHashData);
synchronized (store)
{
if (store.getContents() != null)
{
if(hTable == null)
hTable = new Hashtable();
hTable = (Hashtable)store.getContents();
}
}
return hTable;
}


 

Ankit

Please use plain text.