java试图在传递变量时调用虚拟方法
我遵循MVP设计模式。我从视图中调用Presenter中的一个方法,该方法对网络请求执行异步任务。到目前为止,我已经调试过了,它成功地将JSON作为字符串返回,但是当我想将它传递给一个方法,从演示者传递到视图时,我得到了以下错误:
尝试调用虚拟方法“安卓”。看法查看安卓。看法窗在空对象引用上的findViewById(int)
这是我的代码:
视图:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mediated);
TextView welcome_txt = (TextView) findViewById(R.id.welcome_txtview);
MediatedPresenter mediatedPresenter = new MediatedPresenter();
mediatedPresenter.createConnection();
}
public void getResult(String result)
{
TextView welcome_txt = (TextView) findViewById(R.id.welcome_txtview);
welcome_txt.setText(result);
}
主持人:
public void createConnection() {
new NetworkRequest(new ResultFromAsync() {
@Override
public void taskCompleted(String result) {
MediatedActivity mediatedActivity = new MediatedActivity();
mediatedActivity.getResult(result);
}
}).execute();
}
XML:
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools" 安卓:layout_width="match_parent"
安卓:layout_height="match_parent" 安卓:paddingLeft="@dimen/activity_horizontal_margin"
安卓:paddingRight="@dimen/activity_horizontal_margin"
安卓:paddingTop="@dimen/activity_vertical_margin"
安卓:paddingBottom="@dimen/activity_vertical_margin"
tools:context="uk.co.bbc.avtestharnesssmp.MediatedActivity"
安卓:background="#3498db">
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textAppearance="?安卓:attr/textAppearanceLarge"
安卓:text="Welcome"
安卓:id="@+id/welcome_txtview"
安卓:layout_alignParentTop="true"
安卓:layout_centerHorizontal="true"
安卓:textColor="#80ffffff" />
</RelativeLayout>
顺便说一句:我在这行“mediatedActivity.getResult(result);”上得到了错误信息为了澄清这一点,我试图将taskCompleted的结果发送到视图中的getResult方法中
有人知道我做错了什么吗
共 (0) 个答案