java - The method getBytes() is undefined for the type TextView -


i'm attempting use following example add multiple records 1 ndefmessage when attempt - i'm getting error stating "the method getbytes() undefined type textview"

example: example

source:

public class viewcountry extends activity implements createndefmessagecallback,             onndefpushcompletecallback {     nfcadapter mnfcadapter;    // textview timetv;        private static final int message_sent = 1;        private long rowid;        private textview nametv;        private textview captv;        private textview codetv;         private textview timetv;          @override        public void oncreate(bundle savedinstancestate)         {           super.oncreate(savedinstancestate);           setcontentview(r.layout.view_country);            setupviews();           bundle extras = getintent().getextras();           rowid = extras.getlong(countrylist.row_id);         }         private void setupviews() {            nametv = (textview) findviewbyid(r.id.nametext);            captv = (textview) findviewbyid(r.id.captext);            timetv = (textview) findviewbyid(r.id.timeedit);            codetv = (textview) findviewbyid(r.id.codetext);            nametv = (textview) findviewbyid(r.id.nametext);             // check available nfc adapter             mnfcadapter = nfcadapter.getdefaultadapter(this);             if (mnfcadapter == null) {                 nametv = (textview) findviewbyid(r.id.nametext);                 nametv.settext("nfc not available on device.");                 timetv = (textview) findviewbyid(r.id.timeedit);                 timetv.settext("nfc not available on device.");             } else {                 // register callback set ndef message                 mnfcadapter.setndefpushmessagecallback(this, this);                 // register callback listen message-sent success                 mnfcadapter.setonndefpushcompletecallback(this, this);             }         }          @override         public ndefmessage createndefmessage(nfcevent event) {            string message1 = nametv.gettext().tostring();             string message2 = timetv.gettext().tostring();             byte[] textbytes1 = nametv.getbytes();             byte[] textbytes2 = timetv.getbytes();             ndefrecord textrecord1 = new ndefrecord(ndefrecord.tnf_well_known,                      message1.getbytes(), new byte[]{}, textbytes1);             ndefrecord textrecord2 = new ndefrecord(ndefrecord.tnf_well_known,                      message2.getbytes(), new byte[]{}, textbytes2);              //   string text = ("ssid");              ndefmessage msg = new ndefmessage(                     new ndefrecord[]{                             textrecord1,                             textrecord2,                                             ndefrecord.createapplicationrecord("com.nfc.linked")                       }                      */                      //,ndefrecord.createapplicationrecord("com.nfc.linked")                    );                    return msg;                }           /**          * implementation onndefpushcompletecallback interface          */         @override         public void onndefpushcomplete(nfcevent arg0) {             // handler needed send messages activity when             // callback occurs, because happens binder thread             mhandler.obtainmessage(message_sent).sendtotarget();         }            /** handler receives message onndefpushcomplete */         private final handler mhandler = new handler() {             @override             public void handlemessage(message msg) {                 switch (msg.what) {                 case message_sent:                     toast.maketext(getapplicationcontext(), "core device rules sent!", toast.length_long).show();                     break;                 }             }         };            @override         public void onnewintent(intent intent) {             // onresume gets called after handle intent             setintent(intent);         }            /**          * parses ndef message intent , prints textview          */         void processintent(intent intent) {             parcelable[] rawmsgs = intent.getparcelablearrayextra(                     nfcadapter.extra_ndef_messages);             // 1 message sent during beam             ndefmessage msg = (ndefmessage) rawmsgs[0];             // record 0 contains mime type, record 1 aar, if present             nametv.settext(new string(msg.getrecords()[0].getpayload()));         }             @override         public boolean oncreateoptionsmenu(menu menu) {             // if nfc not available, won't needing menu             if (mnfcadapter == null) {                 return super.oncreateoptionsmenu(menu);             }             menuinflater inflater = getmenuinflater();             inflater.inflate(r.menu.options, menu);             return true;         }            @override         public boolean onoptionsitemselected(menuitem item) {             switch (item.getitemid()) {                 case r.id.menu_settings:                     intent intent = new intent(settings.action_nfcsharing_settings);                     startactivity(intent);                     return true;                 default:                     return super.onoptionsitemselected(item);             }            }            @override        protected void onresume()        {           super.onresume();           new loadcontacts().execute(rowid);        }          private class loadcontacts extends asynctask<long, object, cursor>         {           databaseconnector dbconnector = new databaseconnector(viewcountry.this);            @override           protected cursor doinbackground(long... params)           {              dbconnector.open();              return dbconnector.getonecontact(params[0]);           }             @override           protected void onpostexecute(cursor result)           {              super.onpostexecute(result);               result.movetofirst();              // column index each data item              int nameindex = result.getcolumnindex("name");              int capindex = result.getcolumnindex("cap");              int codeindex = result.getcolumnindex("code");              int timeindex = result.getcolumnindex("time");               nametv.settext(result.getstring(nameindex));              captv.settext(result.getstring(capindex));              timetv.settext(result.getstring(timeindex));               codetv.settext(result.getstring(codeindex));               result.close();              dbconnector.close();           }        }           private void deletecontact()        {            alertdialog.builder alert = new alertdialog.builder(viewcountry.this);            alert.settitle(r.string.confirmtitle);            alert.setmessage(r.string.confirmmessage);             alert.setpositivebutton(r.string.delete_btn,              new dialoginterface.onclicklistener()              {                 public void onclick(dialoginterface dialog, int button)                 {                    final databaseconnector dbconnector =                        new databaseconnector(viewcountry.this);                     asynctask<long, object, object> deletetask =                       new asynctask<long, object, object>()                       {                          @override                          protected object doinbackground(long... params)                          {                             dbconnector.deletecontact(params[0]);                              return null;                          }                            @override                          protected void onpostexecute(object result)                          {                             finish();                           }                       };                     deletetask.execute(new long[] { rowid });                                }              }           );            alert.setnegativebutton(r.string.cancel_btn, null).show();        }      } 

that's because object of textview not have getbytes() method.

in code have nametv.getbytes(), try replacing message1.getbytes(). looks might want.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -