2013-10-10 38 views
0

任何人都可以帮我解释为什么函数getInBackground没有运行我想从android中解析数据。 这是我的类,它调用的fetchData(String themeId)的功能parseManipulate在android中解析getInBackground函数未运行

public class selectTheme extends Activity implements OnClickListener{ 

Button gBtn; 
Button rBtn; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.themeselection); 

    String themeid = "ECGo4oSKgU"; 
    ParseManipulate pm = new ParseManipulate(); 

    pm.fetchData(themeid); 


/*  gBtn = (Button)findViewById(R.id.greentheme); 
    rBtn = (Button)findViewById(R.id.redtheme); 

    gBtn.setOnClickListener(this); 
    rBtn.setOnClickListener(this); 
*/ 
} 

这是ParseManipulate class.compiler我fetchData()函数不运行功能getInBackground()函数和函数结尾跳到闭架

public class ParseManipulate { 

    public void fetchData(String ThemeId) 
    { 

    ParseQuery<ParseObject> pq = ParseQuery.getQuery("testThemes"); 

    pq.getInBackground(ThemeId, new GetCallback<ParseObject>(){ 

     @Override 
     public void done(ParseObject object, ParseException e) { 
      // TODO Auto-generated method stub 
      if(e == null) 
      { 
      // value = object.getString("ThemeName"); 
       Log.d("ParseObject", ""+object.getString("ThemeName")); 
      } 
      else 
      { 
      // Toast.makeText(getApplicationContext(), "error in data fetching", Toast.LENGTH_SHORT).show(); 
      } 
     } 

    }); 
    } 
} 
+0

从它的声音中,您正在使用调试器,并逐行扫描代码行。在这种情况下,代码将跳过getInBackground()调用的内容,因为代码将在异步操作完成时调用。根据查询的复杂性和互联网问题,在调用getInBackground()后,这可能是第二次或更多次。 –

+0

@TimothyWalters thanx bro我已经完成了这项工作:) –

回答

0
Instead of  

Log.d("ParseObject", ""+object.getString("ThemeName")); 

使用方法如下

Log.d("ParseObject", ""+object.fetchIfNeeded().getString("ThemeName")); 
相关问题