2012-08-28 38 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!=