2012-08-28 56 views
0

我想比较db4o和JSON中的对象。如果在JSON中不存在,我应该删除db4o中的对象。比较两个字段的错误

我有一个问题与if:

if(tratdb4o.getMedication()==tratJson.getMedication() 

我登录了两个字符串变量又都是相同的,但不进入如果改变igual的价值。

有人知道为什么吗?的

for (int i=0;it2.hasNext();i++) { 
    objetoDb4o=it2.next(); 
    tratdb4o=(Tratam)objetoDb4o; 
    for (int j=0;it.hasNext();j++) { 
     objetoJson = it.next(); 
     tratJson = (Tratam)objetoJson; 
     Log.d(TAG,"Comparing "+tratdb4o.getMedication()+" of db4o "+ tratJson.getMedication() +" of JSON"); 

     if(tratdb4o.getMedication()==tratJson.getMedication() 
      igual true; 
     } 

     if (igual==false){ 
      db4oHelper.db().delete(tratdb4o); 
      db4oHelper.listResult();  
     } 
     igual=false; 
     it=listaendb4o.iterator(); 
    } 
} 
+0

你能发布错误吗? – Ami

回答

1

代替

tratdb4o.getMedication()==tratJson.getMedication() 

tratdb4o.getMedication().equals(tratJson.getMedication()) 
+0

或可能'equalsIgnoreCase'如果你不关心大写字母 –

+0

Idon't知道为什么..但现在的作品! Thankyou @jeet –

1

字符串你不使用 “==”

tratdb4o.getMedication().equals(tratJson.getMedication()); 

但检查你仍然可以使用notequals!=