android - Unfortunately Your application has stopped -
i trying switch 1 activity other using intents, first activity running when second activity starts app gets stopped. have attached code this.
manifest :
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sampleapp" android:versioncode="1" android:versionname="1.0" > ... <application ... <activity android:name="com.example.sampleapp.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> <activity android:name="com.example.sampleapp.welwithname" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.welwithname" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> ... </application> </manifest>
this default activity. tried string , send next activity.here xml , activity. activity code:
public class mainactivity extends activity { public final static string extra_message = "com.example.sampleapp.message"; string tempname; button submit; edittext name; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); submit= (button)findviewbyid(r.id.button1); submit.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { intent intent = new intent(mainactivity.this,welwithname.class); edittext edittext = (edittext) findviewbyid(r.id.getname); string message = edittext.gettext().tostring(); intent.putextra(extra_message, message); startactivity(intent); } }); } }
second activity:
this activity gets string activity 1 , print value..heres xml , activity activity code:
public class welwithname extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.welwithname); intent intent = getintent(); string message = intent.getstringextra(mainactivity.extra_message); // create text view textview textview = (textview)findviewbyid(r.id.textview1); textview.settextsize(40); textview.settext("welcome" + message + "!!!" ); button sq = (button)findviewbyid(r.id.sq); button exit = (button)findviewbyid(r.id.exit); sq.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent main = new intent(welwithname.this,mainscreen.class); startactivity(main); } }); // set text view activity layout setcontentview(textview); } ... }
what changes should made in code make run?
<activity android:name="com.example.sampleapp.welwithname"
isn't class called welwithname
?
capitalise 'w' in activity name in androidmanifest.xml
you not going developer long if not read console / logcat output when come across crash.
if read logcat saying "cannot find activity welwithname, have declared in manifest?" , answer , stackoverflow happier place
Comments
Post a Comment