I'm trying to parse an xml file and extract data from it to display in my android app.
The xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<record>
<study id="1">
<topic>SAX Parser</topic>
<content>Learn how to parse XML using SAXParser</content>
<author>Pete Houston</author>
<date>02-Oct-2011</date>
</study>
The file is stored in res/raw folder. The android activity calls a function which tries to read the xml file and parses it to retrieve data,which is then stored into an object of type Study (defined by me). This object is then returned by the function.
The skeleton structure of my code is given below:
public class XmlParserActivity extends Activity {
Study study=null;
protected void onCreate(Bundle savedInstanceState) {
//...android code and some variable initializations
try{
study = parseXml(getResources().openRawResource(R.raw.record));
}catch(Exception e){
e.printStackTrace();
finish();
}
}
public Study parseXml(InputStream is){
//code for parsing the input stream
return study;
}
When I launch the app in an emulator it crashes and produces android.content.res.ResourcesNotFoundException. Is there something wrong with the way I am accessing the xml file? Or do I need to set some permissions in the AndroidManifest.xml file? I have searched this site and other sites but have not found a satisfactory solution to my problem. Any guidance will be deeply appreciated.
logcat messages:
01-09 15:49:55.801: I/Process(1152): Sending signal. PID: 1152 SIG: 9
01-09 15:50:04.174: E/Trace(1198): error opening trace file: No such file or directory(2)
01-09 15:50:04.992: W/ResourceType(1198): No package identifier when getting value for resource number 0x00000001
01-09 15:50:05.002: D/AndroidRuntime(1198): Shutting down VM
01-09 15:50:05.002: W/dalvikvm(1198): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-09 15:50:05.012: E/AndroidRuntime(1198): FATAL EXCEPTION: main
01-09 15:50:05.012: E/AndroidRuntime(1198): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidxmlparser/com.example.androidxmlparser.XmlParserActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x1
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.os.Looper.loop(Looper.java:137)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 15:50:05.012: E/AndroidRuntime(1198): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 15:50:05.012: E/AndroidRuntime(1198): at java.lang.reflect.Method.invoke(Method.java:511)
01-09 15:50:05.012: E/AndroidRuntime(1198): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 15:50:05.012: E/AndroidRuntime(1198): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 15:50:05.012: E/AndroidRuntime(1198): at dalvik.system.NativeStart.main(Native Method)
01-09 15:50:05.012: E/AndroidRuntime(1198): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.content.res.Resources.getText(Resources.java:229)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.widget.TextView.setText(TextView.java:3620)
01-09 15:50:05.012: E/AndroidRuntime(1198): at com.example.androidxmlparser.XmlParserActivity.onCreate(XmlParserActivity.java:34)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.Activity.performCreate(Activity.java:5008)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-09 15:50:05.012: E/AndroidRuntime(1198): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
01-09 15:50:05.012: E/AndroidRuntime(1198): ... 11 more
You're trying to access a string resource that cannot be found.
As Matt Taylor suggests, you should check line 34 of your activity, and find which string resource is wrong.
Further to fiddler's comment on your question, I've just seen what I think is the problem:
Your xml file just needs to contain:
<study id="1">
<topic>SAX Parser</topic>
<content>Learn how to parse XML using SAXParser</content>
<author>Pete Houston</author>
<date>02-Oct-2011</date>
</study>
And you access it using:
getResources().openRawResource(R.raw.<xml file name (without.xml)>);
For example, if it was called xmldata.xml you'd use R.raw.xmldata
Related
The code in my book created a NPE for me to see. But, when I open the logcat in ddms, I cannot see all the errors (it says 11 more). How do I see all the exceptions ? Please see the photo below -
EDIT - Image for full trace posted. Also posting text of trace by copy pasting.
Image -
D/QuizActivity(836): onCreate(Bundle) called
D/AndroidRuntime(836): Shutting down VM
W/dalvikvm(836): threadid=1: thread exiting with uncaught exception (group=0x41465700)
E/AndroidRuntime(836): FATAL EXCEPTION: main
E/AndroidRuntime(836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.geoquiz/com.bignerdranch.android.geoquiz.QuizActivity}: java.lang.NullPointerException
E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
E/AndroidRuntime(836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
E/AndroidRuntime(836): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime(836): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(836): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(836): at android.app.ActivityThread.main(ActivityThread.java:5103)
E/AndroidRuntime(836): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(836): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime(836): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(836): Caused by: java.lang.NullPointerException
E/AndroidRuntime(836): at com.bignerdranch.android.geoquiz.QuizActivity.updateQuestion(QuizActivity.java:47)
E/AndroidRuntime(836): at com.bignerdranch.android.geoquiz.QuizActivity.onCreate(QuizActivity.java:111)
E/AndroidRuntime(836): at android.app.Activity.performCreate(Activity.java:5133)
E/AndroidRuntime(836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
E/AndroidRuntime(836): ... 11 more
You dont usually need the whole stack trace, the main thing to look for is "caused by" message and the class(TAG) which is causing the exception
Use try catch block and Java Doc
printStackTrace to see the full stack trace.
try {
// Expected Exception Rasing Line
} catch (Exception e) {
e.printStackTrace();
}
I am getting the error below when I try to login through facebook plugin for Android.
The app basically crashes "stopped", Any ideas will be appreciated.
ERROR/AndroidRuntime(2008): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {xxx/com.facebook.LoginActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x7f060012
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2742)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f060012
at android.content.res.Resources.getText(Resources.java:230)
at android.content.res.Resources.getString(Resources.java:314)
at android.content.Context.getString(Context.java:327)
at com.facebook.widget.WebDialog.onCreate(WebDialog.java:189)
at android.app.Dialog.dispatchOnCreate(Dialog.java:355)
at android.app.Dialog.show(Dialog.java:260)
at com.facebook.AuthorizationClient$WebViewAuthHandler.tryAuthorize(AuthorizationClient.java:471)
at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:214)
at com.facebook.AuthorizationClient.tryNextHandler(AuthorizationClient.java:193)
at com.facebook.AuthorizationClient.authorize(AuthorizationClient.java:121)
at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:102)
at com.facebook.LoginActivity.onResume(LoginActivity.java:113)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
at android.app.Activity.performResume(Activity.java:5182)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
... 12 more
i kinda resolved it, i deleted the app_id string. turns out facebook plugin doesn't use that.
I've made my Android app tablet optimized and I followed the tutorial here:
Everything is great, but I am trying to select an item (say, the 1st item) with a button in the ActionBar.
I tried this answer to use performItemClick but on I've got error reports of java.lang.IllegalStateException
in android.support.v4.app.ListFragment.ensureList, java.lang.IllegalStateException: Content view not yet created, and java.lang.NullPointerException
in android.content.ComponentName.<init>
I've tried checking if the ListView is null and still get the error reports on the Play Store. How do I properly select an item in my list programmatically?
Update to add logcat and the code is virtually identical to the tutorials in the links:
Logcat A:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:69)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2606)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1045)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:592)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:149)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17273)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Logcat B:
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2874)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:86)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:779)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Update 2
And here is the code that is causing the problem:
if (mListFragment.listView != null) {
mListFragment.listView.performItemClick(mListFragment.listView.getAdapter().getView(position, null, null), position, mListFragment.listView.getAdapter().getItemId(position));
}
I'm able to play the you tube video only once i used the below link.
Video plays only once in Webview of Android
but my question is in that with in Chrome Client they asked to add below line
#Override public void onPrepared(MediaPlayer mp) {
customViewCallback.onCustomViewHidden();
}
to show video more than once but no luck. getting crash for that. below is the details of crash
any links or sample code helps me a lot thanks in advance
01-09 11:25:27.999: ERROR/MediaPlayer(3833): <!>android.media.MediaPlayer 732<!> IOException: java.io.FileNotFoundException: No content provider: http://r2---sn-ci5gup-cage.c.youtube.com/videoplayback?itag=18&yms=LMB29RrCiYc&gcr=in&fexp=906373%2C922206%2C901054%2C916624%2C920704%2C912806%2C928001%2C922403%2C922405%2C929901%2C913605%2C929104%2C929110%2C913546%2C913556%2C908493%2C908496%2C920201%2C913302%2C919009%2C911116%2C926403%2C901451%2C902556&app=youtube_mobile&newshard=yes&ratebypass=yes&cp=U0hUTFdOT19GTENONF9PSFNJOkpKQTU0VXFabVZh&ms=au&mv=m&el=watch&expire=1357731812&ip=223.239.139.176&key=yt1&sver=3&id=538eced585584e54&source=youtube&ipbits=8&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&mt=1357710850&signature=71FD38C03ABA06281CFF021A543051861ED0FEC3.A1F7E9E860349E8D3240D8156346C344FFA08731&dnc=1&upn=5y6eEl8pixM
01-09 11:25:28.009: ERROR/MediaPlayerService(1507): [MediaPlayerService::Client::setDataSource]player type = 4
01-09 11:25:29.069: ERROR/QCvdec(1507): Setparameter: unknown param 2130706451
01-09 11:25:31.099: ERROR/QCvdec(1507): Omx Flush issued when vdec is not initialized yet.
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): FATAL EXCEPTION: main
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): java.lang.NullPointerException
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.webkit.HTML5VideoViewProxy$VideoPlayer$2.surfaceDestroyed(HTML5VideoViewProxy.java:322)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.SurfaceView.reportSurfaceDestroyed(SurfaceView.java:596)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.SurfaceView.updateWindow(SurfaceView.java:490)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:215)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.View.dispatchDetachedFromWindow(View.java:6169)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2201)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2187)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.ViewGroup.removeView(ViewGroup.java:2135)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.webkit.HTML5VideoViewProxy$VideoPlayer$1.onCustomViewHidden(HTML5VideoViewProxy.java:160)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at com.android.rmtest.SocialMedia$chromeClient.onPrepared(SocialMedia.java:155)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.widget.VideoView$2.onPrepared(VideoView.java:298)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1313)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.os.Looper.loop(Looper.java:130)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.app.ActivityThread.main(ActivityThread.java:3737)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at java.lang.reflect.Method.invoke(Method.java:507)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:660)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at dalvik.system.NativeStart.main(Native Method)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): [Blue Error Handler] Make Debugging Report file for main
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): java.lang.NullPointerException
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.webkit.HTML5VideoViewProxy$VideoPlayer$2.surfaceDestroyed(HTML5VideoViewProxy.java:322)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.SurfaceView.reportSurfaceDestroyed(SurfaceView.java:596)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.SurfaceView.updateWindow(SurfaceView.java:490)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:215)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.View.dispatchDetachedFromWindow(View.java:6169)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2201)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2187)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.view.ViewGroup.removeView(ViewGroup.java:2135)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.webkit.HTML5VideoViewProxy$VideoPlayer$1.onCustomViewHidden(HTML5VideoViewProxy.java:160)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at com.android.rmtest.SocialMedia$chromeClient.onPrepared(SocialMedia.java:155)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.widget.VideoView$2.onPrepared(VideoView.java:298)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1313)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.os.Looper.loop(Looper.java:130)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at android.app.ActivityThread.main(ActivityThread.java:3737)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at java.lang.reflect.Method.invoke(Method.java:507)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:660)
01-09 11:25:31.139: ERROR/AndroidRuntime(3833): at dalvik.system.NativeStart.main(Native Method)
I have the following layout:
<TextView
android:id = "#+id/HRNoninTextBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/exitbtn"
android:text="Heart Rate"
android:textSize = "20sp"/>
<EditText
android:id="#+id/labelNoninHeartRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:layout_alignParentRight="true">
</EditText>
from the code i refer to these views, form my activity, in this way:
TextView tvHr= (TextView)findViewById(R.id.HRNoninTextBox);
EditText etHr = (EditText)findViewById(R.id.labelNoninHeartRate);
the first one does not produce any error, while the second statement produce the following error:
01-09 13:24:57.599: W/dalvikvm(28816): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
01-09 13:24:57.619: E/AndroidRuntime(28816): FATAL EXCEPTION: main
01-09 13:24:57.619: E/AndroidRuntime(28816): java.lang.RuntimeException: Unable to start activity ComponentInfo{aid.assistant233/aid.assistant233.AidAssistant233Activity}: java.lang.ClassCastException: android.widget.TextView
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.os.Looper.loop(Looper.java:130)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.main(ActivityThread.java:3691)
01-09 13:24:57.619: E/AndroidRuntime(28816): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 13:24:57.619: E/AndroidRuntime(28816): at java.lang.reflect.Method.invoke(Method.java:507)
01-09 13:24:57.619: E/AndroidRuntime(28816): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
01-09 13:24:57.619: E/AndroidRuntime(28816): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
01-09 13:24:57.619: E/AndroidRuntime(28816): at dalvik.system.NativeStart.main(Native Method)
01-09 13:24:57.619: E/AndroidRuntime(28816): Caused by: java.lang.ClassCastException: android.widget.TextView
01-09 13:24:57.619: E/AndroidRuntime(28816): at aid.assistant233.AidAssistant233Activity.onCreate(AidAssistant233Activity.java:331)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-09 13:24:57.619: E/AndroidRuntime(28816): ... 11 more
Where may be the problem?
Step1 : you can clean/build your project as everyone said . but If you are not getting your issue solve by clean/build then check my step2 for it.
Step:2:
I am not Sure But Can you please check your xml file once again?
this also could be happen if You've two elements with the same ID:
<TextView android:text="Hello Ahmedabad:"
android:id="#+id/txtahmedabad"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/txtahmedabad"
android:text="">
</EditText>
if this is so then Give them different IDs -
it could picking the first one (the TextView) which obviously can't be cast to an EditText.
Hope it will some how help you.