java - When I am running my first android app using Genymotion emulator its giving error unfortunately "app name" has stopped. Please help me -


i giving details of files below.please check them , let me know doing mistake due error "unfortunately "app name" has stopped" error coming when running first android app using android sdk. since beginner in android development please explain solution nicely.

my mainactivity.java file :

package com.example.sunny.myfirstapp; import android.app.activity; import android.os.bundle;  import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.textview;   public class mainactivity extends activity { textview textview; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     textview=(textview)findviewbyid(r.id.greetings_view); } public void showgreetings(view view) {     string message= "welcome app";     textview.settext(message); }   @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_main, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }      return super.onoptionsitemselected(item); } 

}

my activity_main.xml file follows:

  <relativelayout 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:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin"         tools:context=".mainactivity"      android:id="@+id/greetings_view">       <textview       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:text="greetings here"       android:id="@+id/greetings_view"        />      <button       android:layout_width="match_parent"       android:layout_height="wrap_content"       android:text="show greetings"       android:layout_below="@+id/greetings_view"       android:onclick="my button"      android:id="@+id/greetings_view"     />   </relativelayout> 

my androidmanifest.xml file :

 <?xml version="1.0" encoding="utf-8"?>   <manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.sunny.myfirstapp"    android:versioncode="1"    android:versionname="1.0" >  <uses-sdk     android:minsdkversion="5"     android:targetsdkversion="22" />  <application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.example.sunny.myfirstapp.mainactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> </application> 

my logcat :

        06-26 10:37:23.137  31265-31265/? d/dalvikvm﹕ late-enabling checkjni         06-26 10:37:24.013  31265-31265/com.example.sunny.myfirstapp d/androidruntime﹕ shutting down vm         06-26 10:37:24.021  31265-31265/com.example.sunny.myfirstapp w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0xa62be288)         06-26 10:37:24.025  31265-31265/com.example.sunny.myfirstapp e/androidruntime﹕ fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.example.sunny.myfirstapp/com.example.sunny.myfirstapp.mainactivity}: java.lang.classcastexception: android.widget.relativelayout cannot cast android.widget.textview 

just try , work

 package com.example.sunny.myfirstapp;      public class mainactivity extends activity {     textview textview;     @override     protected void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         textview=(textview)findviewbyid(r.id.greetings_view);          string message= "welcome app";         textview.settext(message);     }     } 

remove android:id="@+id/greetings_view" relative layout , given id in 2 places textview , relative layout

simple textview xml

<relativelayout 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:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >      <textview         android:id="@+id/greetings_view"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="" />  </relativelayout> 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -