I'm just starting with programming Android apps and was working through the developers guide on android.com. When trying to display a text on a second activity
it says it cannot resolve the symbol EXTRA_MESSAGE
as you can see here:
As far as I can tell I did every step like the guide says. I also tried copy and pasting everything but it still doesn't work. What am I missing?
You're doing a static import of extra message from some random class in MainActivity. That's wrong, don't do that. Define EXTRA_MESSAGE as a public final static String, with whatever value you want (I'd suggest "message") in your MainActivity.
There is two ways of solving it.
1) Use same static variable (Its a dirty way). At DisplayMessageActivity
use android.provider.AlarmClock.EXTRA_MESSAGE
.
2) This approach I recommend you. Create public static final String field at MainActivity
, remove android.provider.AlarmClock.EXTRA_MESSAGE
, and use MainAcitivity
field at both classes. Content of this variable does not matter as long as it is unique extra key.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.