想把activity中接收数据的变量intRate传值给fragment,但总是会出现错误,下面将代码和错误贴出来
activity中用broadcastReceiver已经成功接收到数据并将数据的类型转换成int
intRate = Integer.parseInt(stringRate);
然后写了两个方法,方便在fragment中调用
public int getIntRate(){
return intRate;
}
public void setIntRate(int rate){
this.intRate = rate;
}
在fragment中
private RateActivity mRateActivity;
在onCreateView中
int intRate = mRateActivity.getIntRate();
运行程序,就会出现如下错误:
java.lang.NullPointerException:Attempt to invoke virtual method 'int com.example.RateActivity.getIntRate()' on a null object references at ...