Android Studio找不到符号变量 [英] Android Studio cannot find symbol variable

查看:158
本文介绍了Android Studio找不到符号变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大约两天前,我安装了Android Studio,还安装了Java和JDK 1.8的最新版本(我认为是Java SE 8u101).我能够编辑代码,并且正在关注Android Studio官方网站上的教程.(此处:

所以您只需将android:id属性添加到activity_display_message.xml文件中,就可以了!哦,您实际上应该将其添加到有效位置的layout元素中.

I installed Android Studio about two days ago, I also installed the most updated version of Java and JDK 1.8 (I think it was Java SE 8u101). I am able to edit code and I'm following a tutorial from the official Android Studio website. (Here: https://developer.android.com/training/basics/firstapp/building-ui.html)

However, upon hitting run I've gotten the two following errors:

  1. Error:(24, 57) error: cannot find symbol variable activity_display_message

    Code for this:

    ViewGroup layout = (ViewGroup) findViewById(R.id.activity_display_message);

  2. Error:(33, 25) error: cannot find symbol variable EXTRA_MESSAGE

    Code for this:

    intent.putExtra(EXTRA_MESSAGE, message);

What might I be doing wrong? The emulator pops up and I can get to other apps on the phone but I just can't get my app to load. Should I have installed Java SE 8u102 instead?

I also got a second error message:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.

Any help is appreciated.

Below is my code for the first xml file, "activity_main.xml":

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage" />
</LinearLayout>

Below is my code for "activity_display_message.xml"

<?xml version="1.0" encoding="utf-8"?>
<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="com.example.appno1.DisplayMessageActivity">

</RelativeLayout>

解决方案

I think you might lose the last note in the tutorial.

so you just add android:id attribute to the activity_display_message.xml file and it will be ok!oh actually you should add into the layout element which is the valid location.

这篇关于Android Studio找不到符号变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆