java - Attempt to invoke virtual method when passing variables -
i following mvp design pattern. call method in presenter view, executes async task network request. have debugged far , returns json string, when want pass method presenter view error:
attempt invoke virtual method 'android.view.view android.view.window.findviewbyid(int)' on null object reference
this code in the:
view:
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); }
presenter:
public void createconnection() { new networkrequest(new resultfromasync() { @override public void taskcompleted(string result) { mediatedactivity mediatedactivity = new mediatedactivity(); mediatedactivity.getresult(result); } }).execute(); }
xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="uk.co.bbc.avtestharnesssmp.mediatedactivity" android:background="#3498db"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="welcome" android:id="@+id/welcome_txtview" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:textcolor="#80ffffff" /> </relativelayout>
btw: error on line "mediatedactivity.getresult(result);" clarify trying send result taskcompleted getresult method within view.
does understand doing wrong?
Comments
Post a Comment