android - Views in Fragment are null -


im still working on android app. im facing problem:

code:

package smoca.ch.kreagen.fragments;  import android.content.context; import android.os.bundle; import android.support.annotation.nullable; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview;  import io.realm.realm; import io.realm.realmquery; import smoca.ch.kreagen.r; import smoca.ch.kreagen.models.idea;  public class singleideafragment extends fragment{     private textview title;     private textview owner;     private textview description;     private realm realm;     private idea idea;      @nullable     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view layout = inflater.inflate(r.layout.single_idea_fragment_layout, container, false);  // inflate layout fragment          idea = getsingleidea(getactivity().getbasecontext());          title = (textview) container.findviewbyid(r.id.singleideatitle);         owner = (textview) container.findviewbyid(r.id.singleideaowner);         description = (textview) container.findviewbyid(r.id.singleideadescription);          title.settext(idea.gettitle());         owner.settext(idea.getownerid());         description.settext(idea.gettext());          return layout;     }      public idea getsingleidea(context ctx) {         realm = realm.getinstance(ctx);         realmquery<idea> ideaquery = realm.where(idea.class);         idea = ideaquery.findfirst();         return idea;     } } 

error:

java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.textview.settext(java.lang.charsequence)' on null object reference @ smoca.ch.kreagen.fragments.singleideafragment.oncreateview(singleideafragment.java:35)

i know, problem textviews (title, owner, description) null.. dont know why. assigned them textview's layout, referencing id's.

what doing wrong?

thanks & greetings john

when called inflater.inflate, specified third parameter, attachtoroot, false. means gets returned inflater view r.layout.single_idea_fragment_layout. thus, findviewbyid should called on layout rather container

title = (textview) layout.findviewbyid(r.id.singleideatitle); owner = (textview) layout.findviewbyid(r.id.singleideaowner); description = (textview) layout.findviewbyid(r.id.singleideadescription); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -