2

如果我有以下功能:

        public class Product {

    public String barCode;
    public String name;
    public Category category;
    public double price;
    public Store store;
    WebService ws = new WebService();

    public product getProduct(String barcode) {

        final Product p = new Product();
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Product");
        query.getInBackground("XxfqN425pK", new GetCallback<ParseObject>() {
            public void done(ParseObject object, ParseException e) {
                if (e == null) {
                    Log.d("((((( name )))))", name);

                    String name1 = "p=" + object.getString("product_name");
                    p.name = name1;

                } else {
                    p.name = "erro" + e.getMessage();

                }
            }
        });
        return p;

    }

    public Product get() {
        return this;
    }

}

尽管语句显示名称的值,为什么p.name来自getProduct()调用始终为空Log

在哪里调用函数:

类 getProduct 扩展 AsyncTask {

@Override
protected Product doInBackground(Void... arg0) {
    Product p = new Product();
    return p.getProduct("");
}

@Override
protected void onPostExecute(Product result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);
    Log.d("Product name >>>", result.name + "--");
}

}

4

0 回答 0