[英]Android Studio cannot resolve symbol
I'm just starting with programming Android apps and was working through the developers guide on android.com. 我只是从编写Android应用程序开始,正在研究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: 尝试在第二个
activity
上显示文本时,它说它无法解析符号EXTRA_MESSAGE
如下所示:
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. 您正在从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.
将EXTRA_MESSAGE定义为公共最终静态String,并在MainActivity中使用所需的任何值(我建议“ message”)。
There is two ways of solving it. 有两种解决方法。
1) Use same static variable (Its a dirty way). 1)使用相同的静态变量(这是一种肮脏的方式)。 At
DisplayMessageActivity
use android.provider.AlarmClock.EXTRA_MESSAGE
. 在
DisplayMessageActivity
使用android.provider.AlarmClock.EXTRA_MESSAGE
。
2) This approach I recommend you. 2)我推荐您这种方法。 Create public static final String field at
MainActivity
, remove android.provider.AlarmClock.EXTRA_MESSAGE
, and use MainAcitivity
field at both classes. 在
MainActivity
创建公共静态最终String字段,删除android.provider.AlarmClock.EXTRA_MESSAGE
,并在两个类上都使用MainAcitivity
字段。 Content of this variable does not matter as long as it is unique extra key. 只要是唯一的额外键,此变量的内容就无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.