Android first application String cannot be resolved or is not a field error -
i going through url -http://developer.android.com/training/basics/firstapp/creating-project.html , getting error extra_message cannot resolved or not field:
menifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.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> <activity android:name="com.example.myfirstapp.displaymessageactivity" android:label="@string/title_activity_display_message" android:parentactivityname="com.example.myfirstapp.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.example.myfirstapp.mainactivity" /> </activity> </application> </manifest>
mainactivity.java
package com.example.myfirstapp; import android.os.bundle; import android.view.view; import android.app.activity; import android.view.menu; import android.content.intent; import android.widget.edittext; public class mainactivity extends activity { public final static string extra_message = "com.example.myfirstapp.message"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } public void sendmessage(view view) { intent intent = new intent(this, displaymessageactivity.class); edittext edittext = (edittext) findviewbyid(r.id.edit_message); string message = edittext.gettext().tostring(); intent.putextra(extra_message, message); startactivity(intent); }
}
displaymessageactivity
package com.example.myfirstapp; import android.os.bundle; import android.view.view; import android.app.activity; import android.view.menu; import android.content.intent; import android.widget.edittext; import android.widget.textview; import android.app.activity; import android.view.menu; import android.view.menuitem; import android.support.v4.app.navutils; import android.annotation.targetapi; import android.os.build; public class displaymessageactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); intent intent = getintent(); string message = intent.getstringextra(mainactivity.extra_message); setcontentview(r.layout.activity_display_message); // create text view textview textview = new textview(this); textview.settextsize(40); textview.settext(message); // show button in action bar. setupactionbar(); } /** * set {@link android.app.actionbar}, if api available. */ @targetapi(build.version_codes.honeycomb) private void setupactionbar() { if (build.version.sdk_int >= build.version_codes.honeycomb) { getactionbar().setdisplayhomeasupenabled(true); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.display_message, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case android.r.id.home: // id represents home or button. in case of // activity, button shown. use navutils allow users // navigate 1 level in application structure. // more details, see navigation pattern on android design: // // navutils.navigateupfromsametask(this); return true; } return super.onoptionsitemselected(item); } }
please guide.
include in main activity class
public final static string extra_message = "com.example.myfirstapp.message";
this worked me https://www.androidpit.com/forum/632071/error-cannot-find-symbol-variable-extra-message-in-android-studio
Comments
Post a Comment