java - android.webkit.WebView cannot be cast to android.widget.Button -
i working on gui inside of app. had crappy contained of basic stuff test java functions in. after had functions , running redisgned gui using graphical editor in eclipse. next time ran app had android.webkit.webview cannot cast android.widget.button in logcat. didn't change in java , declarations in gui same far can tell. can revert gui crappy version doesn't me much. hope on here can me find problem. have posted xml, java, , logcat.
05-09 13:25:19.756: e/androidruntime(10424): fatal exception: main 05-09 13:25:19.756: e/androidruntime(10424): java.lang.runtimeexception: unable start activity componentinfo{com.example.dcc/com.example.dcc.actionitem}: java.lang.classcastexception: android.webkit.webview cannot cast android.widget.button 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.activitythread.access$600(activitythread.java:130) 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 05-09 13:25:19.756: e/androidruntime(10424): @ android.os.handler.dispatchmessage(handler.java:99) 05-09 13:25:19.756: e/androidruntime(10424): @ android.os.looper.loop(looper.java:137) 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.activitythread.main(activitythread.java:4745) 05-09 13:25:19.756: e/androidruntime(10424): @ java.lang.reflect.method.invokenative(native method) 05-09 13:25:19.756: e/androidruntime(10424): @ java.lang.reflect.method.invoke(method.java:511) 05-09 13:25:19.756: e/androidruntime(10424): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 05-09 13:25:19.756: e/androidruntime(10424): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 05-09 13:25:19.756: e/androidruntime(10424): @ dalvik.system.nativestart.main(native method) 05-09 13:25:19.756: e/androidruntime(10424): caused by: java.lang.classcastexception: android.webkit.webview cannot cast android.widget.button 05-09 13:25:19.756: e/androidruntime(10424): @ com.example.dcc.actionitem.oncreate(actionitem.java:54) 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.activity.performcreate(activity.java:5008) 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 05-09 13:25:19.756: e/androidruntime(10424): @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 05-09 13:25:19.756: e/androidruntime(10424): ... 11 more <gridlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:columncount="4" > <linearlayout android:layout_width="212dp" android:layout_height="match_parent" android:layout_column="0" android:layout_columnspan="3" android:layout_gravity="left" android:layout_row="0" android:orientation="vertical" > <button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button1_name" android:drawableright="@drawable/news"/> <button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button2_name" /> <button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button3_name" android:drawableright="@drawable/cal"/> <button android:id="@+id/button4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button4_name" android:drawableright="@drawable/mail"/> <button android:id="@+id/button5" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button5_name" android:drawableright="@drawable/gallery" /> <button android:id="@+id/button6" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button6_name" android:drawableright="@drawable/report" /> <button android:id="@+id/button7" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button7_name" android:drawableright="@drawable/ep" /> <button android:id="@+id/button8" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button8_name" android:drawableright="@drawable/directory" /> </linearlayout> <gridlayout android:id="@+id/a" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_column="1" android:layout_columnspan="2" android:layout_gravity="left" android:layout_row="0" android:columncount="2" > </gridlayout> <imageview android:id="@+id/imageview1" android:layout_width="10dp" android:layout_height="fill_parent" android:layout_column="2" android:layout_gravity="left" android:layout_row="0" android:background="@drawable/black" tools:ignore="contentdescription" /> <scrollview android:id="@+id/scrollview1" android:layout_width="238dp" android:layout_height="fill_parent" android:layout_column="3" android:layout_gravity="left|top" android:layout_row="0" android:background="@android:color/black" > <linearlayout android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="vertical" > <textview android:id="@+id/feedtitle" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <textview android:id="@+id/feeddescribtion" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <textview android:id="@+id/feedpubdate" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <textview android:id="@+id/feedlink" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autolink="web" /> <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="594dp" > </listview> <textview android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="waiting" /> </linearlayout> </scrollview> <webview android:id="@+id/webview1" android:layout_width="830dp" android:layout_height="555dp" android:layout_column="3" android:layout_gravity="right|bottom" android:layout_row="0" /> <button android:id="@+id/email_button1" android:layout_width="585dp" android:layout_height="114dp" android:layout_column="3" android:layout_gravity="center_horizontal|top" android:layout_row="0" android:text="submit action item now" /> <textview android:id="@+id/actionview" android:layout_width="243dp" android:layout_height="113dp" android:layout_column="3" android:layout_gravity="right|top" android:layout_row="0" android:text="loading" /> </gridlayout> package com.example.dcc; import java.io.ioexception; import java.net.malformedurlexception; import java.net.url; import javax.xml.parsers.parserconfigurationexception; import javax.xml.parsers.saxparser; import javax.xml.parsers.saxparserfactory; import org.xml.sax.inputsource; import org.xml.sax.saxexception; import org.xml.sax.xmlreader; import android.app.listactivity; import android.content.intent; import android.net.uri; import android.os.asynctask; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.webkit.websettings; import android.webkit.webview; import android.webkit.webviewclient; import android.widget.arrayadapter; import android.widget.button; import android.widget.listview; import android.widget.textview; public class actionitem extends listactivity implements onclicklistener { // create buttons globally available methods public static rssfeed myrssfeed = null; private button btnemail = null; static webview webview; button newsb; button loginb; button calb; button mailb; button photob; button reportb; button actionb; button directoryb; string currentitem; textview thisaction; int currentlocation; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.action_item); btnemail = (button) findviewbyid(r.id.email_button1); newsb = (button) findviewbyid(r.id.button1); loginb = (button) findviewbyid(r.id.button2); calb = (button) findviewbyid(r.id.button3); mailb = (button) findviewbyid(r.id.button4); photob = (button) findviewbyid(r.id.button5); reportb = (button) findviewbyid(r.id.button6); actionb = (button) findviewbyid(r.id.button7); directoryb = (button) findviewbyid(r.id.button8); thisaction = (textview) findviewbyid(r.id.actionview); newsb.setonclicklistener(this); loginb.setonclicklistener(this); calb.setonclicklistener(this); mailb.setonclicklistener(this); photob.setonclicklistener(this); reportb.setonclicklistener(this); actionb.setonclicklistener(this); directoryb.setonclicklistener(this); btnemail.setonclicklistener(this); new mytask().execute(); // portion of oncreate dedicated running webview // webpage: http://creflodollarministries.org/ // main webpage: http://www.virtualdiscoverycenter.net webview = (webview) findviewbyid(r.id.webview1); webview.setwebviewclient(new webviewclient()); webview.loadurl("http://www.virtualdiscoverycenter.net"); websettings websettings = webview.getsettings(); websettings.setjavascriptenabled(true); uri data = getintent().getdata(); if (savedinstancestate == null) { string url = getintent().getdatastring(); // url. webview.loadurl(url); } } private class mytask extends asynctask<void, void, void> { @override protected void doinbackground(void... arg0) { try { url rssurl = new url( "http://www.virtualdiscoverycenter.net/feed/");// http://www.virtualdiscoverycenter.net/feed/ saxparserfactory mysaxparserfactory = saxparserfactory .newinstance(); saxparser mysaxparser = mysaxparserfactory.newsaxparser(); xmlreader myxmlreader = mysaxparser.getxmlreader(); rsshandler myrsshandler = new rsshandler(); myxmlreader.setcontenthandler(myrsshandler); inputsource myinputsource = new inputsource(rssurl.openstream()); myxmlreader.parse(myinputsource); myrssfeed = myrsshandler.getfeed(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (parserconfigurationexception e) { e.printstacktrace(); } catch (saxexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return null; } @override protected void onpostexecute(void result) { if (myrssfeed != null) { textview feedtitle = (textview) findviewbyid(r.id.feedtitle); textview feeddescribtion = (textview) findviewbyid(r.id.feeddescribtion); textview feedpubdate = (textview) findviewbyid(r.id.feedpubdate); textview feedlink = (textview) findviewbyid(r.id.feedlink); feedtitle.settext(myrssfeed.gettitle()); feeddescribtion.settext(myrssfeed.getdescription()); feedpubdate.settext(myrssfeed.getpubdate()); feedlink.settext(myrssfeed.getlink()); arrayadapter<rssitem> adapter = new arrayadapter<rssitem>( getapplicationcontext(), android.r.layout.simple_list_item_1, myrssfeed.getlist()); setlistadapter(adapter); thisaction.settext(myrssfeed.getitem(0).gettitle()); } else { textview textempty = (textview) findviewbyid(android.r.id.empty); textempty.settext("no feed found!"); } super.onpostexecute(result); } } @override protected void onlistitemclick(listview l, view v, int position, long id) { // uri feeduri = uri.parse(myrssfeed.getitem(position).getlink()); // intent myintent = new intent(intent.action_view, feeduri); // startactivity(myintent); string url = myrssfeed.getitem(position).getlink(); currentitem = myrssfeed.getitem(position).gettitle(); currentlocation = position; thisaction.settext(currentitem); webview.loadurl(url); } public void sendemail(view v) { // following code implementation of email client intent = new intent(android.content.intent.action_send); i.settype("text/plain"); string[] address = { "bevins2012@hotmail.com" }; i.putextra(android.content.intent.extra_email, address); i.putextra(android.content.intent.extra_subject, myrssfeed.getitem(currentlocation).getdescription()); i.putextra(android.content.intent.extra_text, "action item dcc app."); startactivityforresult((intent.createchooser(i, "email")), 1); } public void onclick(view v) { // switch listens , click actions in app // each case button in menu. switch (v.getid()) { case r.id.button1: startactivity(new intent(this, androidrssreader.class)); break; case r.id.button2: startactivity(new intent(this, mainactivity.class)); break; case r.id.button3: startactivity(new intent(this, mainactivity.class)); break; case r.id.button4: startactivity(new intent(this, emailmain.class)); break; case r.id.button5: startactivity(new intent(this, customizedlistview.class)); break; case r.id.button6: startactivity(new intent(this, launchactivity.class)); break; case r.id.button7: startactivity(new intent(this, actionitem.class)); break; case r.id.button8: startactivity(new intent(this, mainactivity.class)); finish(); break; case r.id.email_button1: // calling sendemail activity class sendemail(v); break; } } }
perhaps auto-generated r class messed up. try clean , rebuild project using project > clean... in eclipse.
Comments
Post a Comment