How to debug "expected android.widget.TextView but found java.lang.string" in Android? -
can please take @ code? trying build app personal school project. new android studio. have put simple app display spaces available in parking lot.
but trying open second activity screen when click on 1 of lots in listview screen. got error , have no way of solving it.
**mainactivity.java** <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <textview android:id="@+id/lotname" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <textview android:id="@+id/lotspaces" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/lotname"/> </relativelayout> **singlelotview.java** package com.example.sahan.smartpark; /** * created sahan on 2015-10-14. */ import android.app.activity; import android.content.intent; import android.os.bundle; import android.widget.textview; public class singlelotview extends activity{ //declare variables textview lotname; textview lotspaces; string[] lot_name; string[] lot_spaces; int position; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.singlelotview); // retrieve data mainactivity on listview item click intent = getintent(); // listview item click position position = i.getextras().getint("position"); // list of rank lotname = i.getstringarrayextra("lotname"); // list of country lotspaces = i.getstringarrayextra("lotspaces"); // list of population // locate textviews in singleitemview.xml lotname = (textview) findviewbyid(r.id.move_title); lotspaces = (textview) findviewbyid(r.id.move_title); // load text textviews followed position lotname.settext(lot_name[position]); lotspaces.settext(lot_spaces[position]); } } **moveadapter.java** package com.example.sahan.smartpark; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.imageview; import android.widget.textview; import java.util.arraylist; import java.util.list; /** * created sahan on 2015-10-12. */ public class moveadapter extends arrayadapter{ list list=new arraylist(); public moveadapter(context context, int resource) { super(context, resource); } static class datahandler { imageview poster; textview name; textview spaces; } public void add(object object){ super.add(object); list.add(object); } public int getcount(){ return this.list.size(); } @override public object getitem(int position) { return this.list.get(position); } @override public view getview(int position, view convertview, viewgroup parent) { view row; row=convertview; datahandler handler; if(convertview==null) { row=inflater.inflate(r.layout.second_layout,parent,false); handler=new datahandler(); handler.poster=(imageview)row.findviewbyid(r.id.move_poster); handler.name=(textview)row.findviewbyid(r.id.move_title); handler.spaces=(textview)row.findviewbyid(r.id.move_rating); row.settag(handler); } else { handler=(datahandler)row.gettag(); } movedataprovider dataprovider; dataprovider=(movedataprovider)this.getitem(position); handler.poster.setimageresource (dataprovider.getmove_poster_resource()); handler.name.settext(dataprovider.getlot_name()); handler.spaces.settext(dataprovider.getlot_spaces()); return row; } } **singletoview.xml** package com.example.sahan.smartpark; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.imageview; import android.widget.textview; import java.util.arraylist; import java.util.list; /** * created sahan on 2015-10-12. */ public class moveadapter extends arrayadapter{ list list=new arraylist(); public moveadapter(context context, int resource) { super(context, resource); } static class datahandler { imageview poster; textview name; textview spaces; } public void add(object object){ super.add(object); list.add(object); } public int getcount(){ return this.list.size(); } @override public object getitem(int position) { return this.list.get(position); } @override public view getview(int position, view convertview, viewgroup parent) { view row; row=convertview; datahandler handler; if(convertview==null) { row=inflater.inflate(r.layout.second_layout,parent,false); handler=new datahandler(); handler.poster=(imageview)row.findviewbyid(r.id.move_poster); handler.name=(textview)row.findviewbyid(r.id.move_title); handler.spaces=(textview)row.findviewbyid(r.id.move_rating); row.settag(handler); } else { handler=(datahandler)row.gettag(); } movedataprovider dataprovider; dataprovider=(movedataprovider)this.getitem(position); handler.poster.setimageresource (dataprovider.getmove_poster_resource()); handler.name.settext(dataprovider.getlot_name()); handler.spaces.settext(dataprovider.getlot_spaces()); return row; } } **strings.xml** <resources> <string name="app_name">smartpark</string> <string name="action_settings">settings</string> <string-array name="lot_name"> <item> parking lot a</item> <item> parking lot b</item> </string-array> <string-array name="lot_spaces"> <item>available: 225</item> <item>available: 107</item> </string-array> </resources>
the error on singlelotview.java code:
incompatible types - expected android.widget.textview found java.lang.string
lotname = i.getstringarrayextra("lotname");
should be:
lot_name = i.getstringarrayextra("lotname");
Comments
Post a Comment