android - ResourceNotFoundException though there is a resource -
i'm trying create spinner non-selectable text displayed when dropdown not displayed "--select option--
". have created custom spinner adapter , layout file textview
"--select option--
" using second answer of so post.
i'm getting 6912-6912/com.examp.three e/androidruntime﹕ fatal exception: main android.content.res.resources$notfoundexception: resource id #0x7f04004e
exception though have passed layout file constructor.
what doing wrong?
i debugged app , value getnothingselectedlayout
2130968654
. kept break point @ return layoutinflater.inflate(nothingselectedlayout, parent, false);
. value of getnothingselectedlayout
still same. after point, when press f8, goes choreographer.class
before crashing
like @kumar ranjan said in comments of answer, checked r.java
class resource id error log said not there. found id assigned support_simple_spinner_dropdown_item
in r.java
file. found resource id #0x7f04004e
shown in error log in r.java
file
here's code:
arrayadapter<string> adapterbankname = new arrayadapter (checkamountactivity.this, android.r.layout.simple_spinner_dropdown_item, paymentmode) { public view getdropdownview(int position, view convertview, viewgroup parent) { view v = super.getdropdownview(position, convertview, parent); ((textview) v).setgravity(gravity.center); ((textview) v).settextcolor(color.black); return v; } }; spinnerbankname.setadapter(new ndspinner(adapterbankname, r.layout.spinnertitle, getapplicationcontext())); //the constructor of ndspinner class
this ndspinner class:
public class ndspinner implements spinneradapter, listadapter { protected static final int = 1; protected spinneradapter adapter; protected context context; protected int nothingselectedlayout; protected int nothingselecteddropdownlayout; protected layoutinflater layoutinflater; string item; public ndspinner( spinneradapter spinneradapter, int nothingselectedlayout, context context) { this(spinneradapter, nothingselectedlayout, -1, context); } public ndspinner(spinneradapter spinneradapter, int nothingselectedlayout, int nothingselecteddropdownlayout, context context) { this.adapter = spinneradapter; this.context = context; this.nothingselectedlayout = nothingselectedlayout; this.nothingselecteddropdownlayout = nothingselecteddropdownlayout; layoutinflater = layoutinflater.from(context); } @override public final view getview(int position, view convertview, viewgroup parent) { // provides view selected item in spinner, not // dropdown (unless dropdownview not set). if (position == 0) { return getnothingselectedview(parent); } return adapter.getview(position - extra, null, parent); // re-use // convertview if possible. } /** * view show in spinner nothing selected * override dynamic... e.g. "37 options found" * * @param parent * @return */ protected view getnothingselectedview(viewgroup parent) { return layoutinflater.inflate(nothingselectedlayout, parent, false); } @override public view getdropdownview(int position, view convertview, viewgroup parent) { // android bug! http://code.google.com/p/android/issues/detail?id=17128 - // spinner not support multiple view types if (position == 0) { return nothingselecteddropdownlayout == -1 ? new view(context) : getnothingselecteddropdownview(parent); } // re-use convertview if possible, use settag... return adapter.getdropdownview(position - extra, null, parent); } /** * override dynamic... example, "pick favorite * of these 37". * * @param parent * @return */ protected view getnothingselecteddropdownview(viewgroup parent) { return layoutinflater.inflate(nothingselecteddropdownlayout, parent, false); } @override public int getcount() { int count = adapter.getcount(); return count == 0 ? 0 : count + extra; } @override public object getitem(int position) { return position == 0 ? null : adapter.getitem(position - extra); } @override public int getitemviewtype(int position) { return 0; } @override public int getviewtypecount() { return 1; } @override public long getitemid(int position) { return position >= ? adapter.getitemid(position - extra) : position - extra; } @override public boolean hasstableids() { return adapter.hasstableids(); } @override public boolean isempty() { return adapter.isempty(); } @override public void registerdatasetobserver(datasetobserver observer) { adapter.registerdatasetobserver(observer); } @override public void unregisterdatasetobserver(datasetobserver observer) { adapter.unregisterdatasetobserver(observer); } @override public boolean areallitemsenabled() { return false; } @override public boolean isenabled(int position) { return position != 0; // don't allow 'nothing selected' // item picked. } }
this spinnertitle.xml
<?xml version="1.0" encoding="utf-8"?> <textview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="?android:attr/spinneritemstyle" android:singleline="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:gravity="center" android:background="@drawable/button_custom" android:padding="5dp" android:layout_margin="5dp" android:textsize="18sp" android:text="vehicle type" />
this error in logcat:
01-21 12:35:10.740 8658-8658/com.examp.three e/androidruntime﹕ fatal exception: main android.content.res.resources$notfoundexception: resource id #0x7f04004e @ android.content.res.resources.getvalue(resources.java:1033) @ android.content.res.resources.loadxmlresourceparser(resources.java:2179) @ android.content.res.resources.getlayout(resources.java:872) @ android.view.layoutinflater.inflate(layoutinflater.java:394) @ com.examp.three.adapter.ndspinner.getnothingselectedview(ndspinner.java:59) @ com.examp.three.adapter.ndspinner.getview(ndspinner.java:45) @ android.widget.absspinner.onmeasure(absspinner.java:194) @ android.widget.spinner.onmeasure(spinner.java:440) @ android.view.view.measure(view.java:15775) @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:681) @ android.widget.relativelayout.onmeasure(relativelayout.java:461) @ android.view.view.measure(view.java:15775) @ android.widget.scrollview.measurechildwithmargins(scrollview.java:1228) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.widget.scrollview.onmeasure(scrollview.java:321) @ android.view.view.measure(view.java:15775) @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:681) @ android.widget.relativelayout.onmeasure(relativelayout.java:461) @ android.view.view.measure(view.java:15775) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4942) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.support.v7.internal.widget.contentframelayout.onmeasure(contentframelayout.java:124) @ android.view.view.measure(view.java:15775) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4942) @ android.support.v7.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:444) @ android.view.view.measure(view.java:15775) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4942) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.view.view.measure(view.java:15775) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4942) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1411) @ android.widget.linearlayout.measurevertical(linearlayout.java:698) @ android.widget.linearlayout.onmeasure(linearlayout.java:588) @ android.view.view.measure(view.java:15775) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4942) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2193) @ android.view.view.measure(view.java:15775) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2213) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1291) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1486) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1181) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4943) @ android.view.choreographer$callbackrecord.run(choreographer.java:776) @ android.view.choreographer.docallbacks(choreographer.java:579) @ android.view.choreographer.doframe(choreographer.java:548) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:762) @ android.os.handler.handlecallback(handler.java:800) @ android.os.handler.dispatchmessage(handler.java:100) @ android.os.looper.loop(looper.java:194) @ android.app.activitythread.main(activitythread.java:5391) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) @ dalvik.system.nativestart.main(native method)
try cleaning project , rebuilding it.
Comments
Post a Comment