My app is getting an android.view.InflateException: Binary XML file line #1: Error inflating class fragment -


i'm creating app present user list of movies in gridview. i'm using api themoviedb.org. when run app doesn't start @ , i'm getting error in logcat. please explain how fix issue:

07-13 21:50:56.954: e/androidruntime(25898): java.lang.runtimeexception: unable start activity componentinfo{com.projmobileapp.pmdbadd.pmdb/com.projmobileapp.pmdbadd.pmdb.mainactivity}: android.view.inflateexception: binary xml file line #1: error inflating class fragment 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2693) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2758) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.activitythread.access$900(activitythread.java:177) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.activitythread$h.handlemessage(activitythread.java:1448) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.os.handler.dispatchmessage(handler.java:102) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.os.looper.loop(looper.java:145) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.activitythread.main(activitythread.java:5942) 07-13 21:50:56.954: e/androidruntime(25898):    @ java.lang.reflect.method.invoke(native method) 07-13 21:50:56.954: e/androidruntime(25898):    @ java.lang.reflect.method.invoke(method.java:372) 07-13 21:50:56.954: e/androidruntime(25898):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1400) 07-13 21:50:56.954: e/androidruntime(25898):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1195) 07-13 21:50:56.954: e/androidruntime(25898): caused by: android.view.inflateexception: binary xml file line #1: error inflating class fragment 07-13 21:50:56.954: e/androidruntime(25898):    @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:770) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.view.layoutinflater.inflate(layoutinflater.java:483) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.view.layoutinflater.inflate(layoutinflater.java:415) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.view.layoutinflater.inflate(layoutinflater.java:366) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v7.app.appcompatdelegateimplv7.setcontentview(appcompatdelegateimplv7.java:249) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:106) 07-13 21:50:56.954: e/androidruntime(25898):    @ com.projmobileapp.pmdbadd.pmdb.mainactivity.oncreate(mainactivity.java:15) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.activity.performcreate(activity.java:6289) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1119) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2646) 07-13 21:50:56.954: e/androidruntime(25898):    ... 10 more 07-13 21:50:56.954: e/androidruntime(25898): caused by: java.lang.nullpointerexception: attempt length of null array 07-13 21:50:56.954: e/androidruntime(25898):    @ java.util.collections.addall(collections.java:2582) 07-13 21:50:56.954: e/androidruntime(25898):    @ com.projmobileapp.pmdbadd.pmdb.mainactivityfragment$movieadapter.<init>(mainactivityfragment.java:171) 07-13 21:50:56.954: e/androidruntime(25898):    @ com.projmobileapp.pmdbadd.pmdb.mainactivityfragment.oncreateview(mainactivityfragment.java:48) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v4.app.fragment.performcreateview(fragment.java:1789) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:924) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1116) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v4.app.fragmentmanagerimpl.addfragment(fragmentmanager.java:1218) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v4.app.fragmentmanagerimpl.oncreateview(fragmentmanager.java:2170) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v4.app.fragmentactivity.oncreateview(fragmentactivity.java:300) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v7.app.appcompatdelegateimplv7.callactivityoncreateview(appcompatdelegateimplv7.java:838) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v7.app.appcompatdelegateimplv11.callactivityoncreateview(appcompatdelegateimplv11.java:34) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v7.app.appcompatdelegateimplv7.oncreateview(appcompatdelegateimplv7.java:826) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.support.v4.view.layoutinflatercompathc$factorywrapperhc.oncreateview(layoutinflatercompathc.java:44) 07-13 21:50:56.954: e/androidruntime(25898):    @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:732) 07-13 21:50:56.954: e/androidruntime(25898):    ... 19 more 07-13 21:50:56.954: v/applicationpolicy(864): isapplicationstateblocked userid 0 pkgname com.projmobileapp.pmdbadd.pmdb 07-13 21:50:56.954: w/activitymanager(864):   force finishing activity com.projmobileapp.pmdbadd.pmdb/.mainactivity 07-13 21:50:56.954: d/focusedstackframe(864): set : 0 07-13 21:50:56.964: i/process(25898): sending signal. pid: 25898 sig: 9 

here's code:

mainactivityfragment

package com.projmobileapp.pmdbadd.pmdb;  import android.content.context; import android.os.asynctask; import android.os.bundle; import android.support.v4.app.fragment; import android.util.log; import android.view.layoutinflater; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.gridview; import android.widget.imageview;  import com.squareup.picasso.picasso;  import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.net.httpurlconnection; import java.net.url; import java.util.arraylist; import java.util.collections; import java.util.list;  public class mainactivityfragment extends fragment {     //arrayadapter<string> mmovieadapter;     string[] movieid,movietitle,movieoverview,moviereleasedate,movieposterpath,movievoteaverage;     public mainactivityfragment() {     }      movieadapter mmovieadapter;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          view rootview = inflater.inflate(r.layout.fragment_main, container, false);          mmovieadapter = new movieadapter(getactivity());         gridview listview = (gridview) rootview.findviewbyid(r.id.gridview_movie);         listview.setadapter(mmovieadapter);         updatemovie();         return rootview;     }      public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         sethasoptionsmenu(true);     }      @override     public void oncreateoptionsmenu(menu menu, menuinflater inflater) {         // inflate menu; adds items action bar if present.         inflater.inflate(r.menu.mainactivityfragment, menu);     }      @override     public boolean onoptionsitemselected(menuitem item) {         int id = item.getitemid();         if (id == r.id.action_refresh) {             updatemovie();             return true;         }         return super.onoptionsitemselected(item);     }      private void updatemovie() {         fetchmovietask movietask = new fetchmovietask();         movietask.execute();     }      class fetchmovietask extends asynctask<void, void, list<string>> {         private final string log_tag = fetchmovietask.class.getsimplename();          @override         protected list<string> doinbackground(void... params) {             httpurlconnection urlconnection = null;             bufferedreader reader = null;              // contain raw json response string.             string moviejsonstr = null;              try {                 url url = new url("http://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=insertapikeyhere");                  urlconnection = (httpurlconnection) url.openconnection();                 urlconnection.setrequestmethod("get");                 urlconnection.connect();                  // read input stream string                 inputstream inputstream = urlconnection.getinputstream();                 stringbuffer buffer = new stringbuffer();                 if (inputstream == null) {                     // nothing do.                     return null;                 }                 reader = new bufferedreader(new inputstreamreader(inputstream));                  string line;                 while ((line = reader.readline()) != null) {                      buffer.append(line + "\n");                 }                  if (buffer.length() == 0) {                     // stream empty.  no point in parsing.                     return null;                 }                 moviejsonstr = buffer.tostring();              } catch (ioexception e) {                 log.e(log_tag, "error ", e);                 return null;             } {                 if (urlconnection != null) {                     urlconnection.disconnect();                 }                 if (reader != null) {                     try {                         reader.close();                     } catch (final ioexception e) {                         log.e(log_tag, "error closing stream", e);                     }                 }             }             try {                 return getmoviedatafromjson(moviejsonstr);             } catch (jsonexception j) {                 log.e(log_tag, "json error", j);             }             return null;         }          private list<string> getmoviedatafromjson(string forecastjsonstr)                 throws jsonexception {             jsonobject moviejson = new jsonobject(forecastjsonstr);             jsonarray moviearray = moviejson.getjsonarray("results");             list<string> urls = new arraylist<>();             (int = 0; < moviearray.length(); i++) {                 jsonobject movie = moviearray.getjsonobject(i);                 urls.add("http://image.tmdb.org/t/p/w185" + movie.getstring("poster_path"));             }             return urls;         }             @override         protected void onpostexecute(list<string> strings) {             mmovieadapter.replace(strings);         }     }      class movieadapter extends baseadapter {         private final string log_tag = movieadapter.class.getsimplename();         private final context context;         private final list<string> urls = new arraylist<string>();          public movieadapter(context context) {             this.context = context;             collections.addall(urls, movieposterpath);         }          @override         public view getview(int position, view convertview, viewgroup parent) {             if (convertview == null) {                 convertview = new imageview(context);             }             imageview imageview = (imageview) convertview;               string url = getitem(position);              log.e(log_tag, " url " + url);              picasso.with(context).load(url).into(imageview);              return convertview;         }          @override         public int getcount() {             return urls.size();         }          @override         public string getitem(int position) {             return urls.get(position);         }          @override         public long getitemid(int position) {             return position;         }         public void replace(list<string> urls) {             this.urls.clear();             this.urls.addall(urls);             notifydatasetchanged();         }     } } 

the problem movieposterpath. maybe can initialize empty array. example: string[] moveposterpath = new string[0];


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -