java - Android setText 不适用于 TextView

标签 java android parse-platform

我尝试将 Textview 的值更改为我正在查询解析的某些信息,但由于某种原因 .setText 没有生效。

我尝试谷歌搜索,但 .getString 也不起作用。我对解析任何建议还很陌生?

我的代码如下:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

import org.w3c.dom.Text;

import java.util.List;


/**
* A simple {@link Fragment} subclass.
 */
public class productDetail extends Fragment {


public productDetail() {
    // Required empty public constructor
}






@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    final View theView = inflater.inflate(R.layout.fragment_product_detail, container, false);

    final TextView productNameLabel = (TextView) theView.findViewById(R.id.productNameTextView);
    final TextView productDetailsLabel = (TextView) theView.findViewById(R.id.productDetails);
    final TextView shippingFeeLabel = (TextView) theView.findViewById(R.id.shippingFee);
    final TextView productPriceLabel = (TextView) theView.findViewById(R.id.productPrice);
    final TextView productNumberOfReviewsLabel = (TextView) theView.findViewById(R.id.productNumberOfReviews);

    final String chosenProduct = getArguments().getString("productName");
    Log.i("AppInfo", chosenProduct);

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Inventory");
    query.whereEqualTo("productName", chosenProduct);
    query.getFirstInBackground(new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject parseObject, ParseException e) {
            if (parseObject == null) {

                Integer fee = parseObject.getInt("ShippingFee");
                Integer review = parseObject.getInt("numberOfReviews");
                String information = parseObject.get("information").toString();
                Integer price = parseObject.getInt("price");


                productNameLabel.setText(chosenProduct);
                productDetailsLabel.setText(String.valueOf(information));
                shippingFeeLabel.setText(String.valueOf(fee));
                productPriceLabel.setText(String.valueOf(price));
                productNumberOfReviewsLabel.setText(String.valueOf(entries));

            }

        }
    });




    // Inflate the layout for this fragment
    return theView;
}

}

最佳答案

如果输入了 if 语句中的所有内容,都会抛出 NullPointerException :)

将 if 语句更改为这样

if (parseObject != null)

或者也许你就是这个意思?

if (e == null) 

关于java - Android setText 不适用于 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34302138/

相关文章:

android - 如何从一个 Activity 中的 fragment 导航到另一个 Activity 中的 fragment ?

swift - 在 Swift 中检索对象的解析数组

cordova - Parse.com 推送通知未在 Android 后台显示

java - 有关数据库池和 connection.setReadOnly() 方法的行为

android - Android Studio EGL匹配错误?

线性布局的Android幻灯片动画

javascript - 即使数据库中不存在该用户,尝试查找用户时代码也不会返回错误

java - EMF/GMF/Papyrus - 设置显式和 ElementImpl - 代码外的属性

java - hibernate 不设置别名和 oracle 抛出 `ORA-00918: column ambiguously defined` 错误

java - Openshift 部署 F8 : Cannot access cluster for detecting mode: sun. security.validator.ValidatorException