【问题标题】:Null pointer while using Persistent Store in blackberry在黑莓中使用持久存储时的空指针
【发布时间】:2018-08-03 18:30:32
【问题描述】:

我用这些来存储数据:

value="1";  
FieldChangeListener listenerslider = new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {

        synchronized(store) {
            store.setContents(value); 
            store.commit();
        } 

        Dialog.inform("Success!");
    }
};

这些是用来获取数据的

synchronized(store) {
    String currentinfo = (String)store.getContents(); 
    if(currentinfo == null) {
        Dialog.inform("error");
    } 
    else {
        edtplasmasodium.setText(currentinfo);   
    }
}

// 这两个我都用过

  static PersistentObject store;
  static {
       store = PersistentStore.getPersistentObject( 0xa1a569278238dad2L );
  }

为什么?我在二等舱中获取数据时得到空指针,或者我应该使用真实设备来测试该功能吗?

【问题讨论】:

  • 您能否在商店之后立即进行“提取”以证明其正常运行。
  • currentinfo 显示为空
  • 更改为 if(currentinfo.equals(null))
  • 干草感谢@TheLittleNaruto 我将其更改为 if(currentinfo.equals(null)) 并完成:)
  • 我不明白问题出在哪里。您是说currentinfo 永远为空是一个问题(意外结果)吗?或者,您只是想决定当它为空时该怎么做?

标签: blackberry persistent


【解决方案1】:

更改if(currentinfo==null)

if(currentinfo.equals(null))

【讨论】:

  • 什么?这个答案对这里有什么帮助?如果currentInfo 为空,那么您的建议将引发异常。
  • 其实不为null,String的情况下比较的方式不对。 @Nate 我希望你能理解。
  • 我想我不明白。 OP 说它为空,我仍然看不到这个答案如何阻止它为空,并且只有在它真的 is 为空时才会使他的程序崩溃。
  • @Nate - 我们两个人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-30
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多