简体   繁体   English

Android Studio(1.5.1)-错误:找不到符号类/应用程序将无法运行

[英]Android Studio (1.5.1) — Error: cannot find symbol class / App won't run

I'm working on my first Android application. 我正在开发我的第一个Android应用程序。 It's a very simple farenheit/celsius converter, and all of my IDs, methods, and buttons/text fields are perfectly copied out. 这是一个非常简单的Farenheit / Cels转换器,我的所有ID,方法和按钮/文本字段都被完美地复制了出来。 I triple checked. 我三重检查。 (I'm following instructions from a video my professor posted.) However, I'm having difficulty trying to get Android Studio to run the application. (我正在按照我的教授发布的视频中的说明进行操作。)但是, 我很难让Android Studio运行该应用程序。

I've found plenty of questions similar to this one and many of them suggest synchronizing the gradle files . 我发现很多与此问题类似的问题,其中许多问题建议同步gradle文件 So I did. 所以我做了。 I'm still getting these same error messages: 我仍然收到这些相同的错误消息:

在此处输入图片说明


Here is the app information: 这是应用程序信息:

在此处输入图片说明

Code from app/res/layout/content_test.xml: 来自app / res / layout / content_test.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="john.testapplication.TestActivity"
    tools:showIn="@layout/activity_test">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/temperatureEditText"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:hint="Enter Temperature" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/temperatureEditText"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/radioGroup">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="From Celsius to Farenheit"
            android:id="@+id/toFarenheitRadioButton"
            android:checked="false" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="From Farenheit to Celsius"
            android:id="@+id/toCelsiusRadioButton"
            android:checked="false" />
    </RadioGroup>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Convert"
        android:id="@+id/convertButton"
        android:layout_below="@+id/radioGroup"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="convert" />
</RelativeLayout>

Code from app/res/layout/activitytest.xml: ( I thought I was using Relative Layout , I don't know if this has anything to do with my problem ) 来自app / res / layout / activitytest.xml的代码:( 我以为我正在使用Relative Layout ,我不知道这是否与我的问题有关

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="john.testapplication.TestActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_test" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

Again, I was building this app from a video my instructor gave me, so I'm willing to bet it has something to do with my version of Android Studio or settings on my computer as opposed to code itself. 再说一次,我是根据老师给我的视频制作这个应用程序的,所以我敢打赌它与我的Android Studio版本或计算机上的设置有关,而与代码本身无关。

Okay, with some help from someone on this site, I found a solution. 好的,在此站点的某人的帮助下,我找到了解决方案。 Apparently in TestActivity.xml, I forgot to import these: 显然在TestActivity.xml中,我忘了导入这些:

import android.widget.EditText;
import android.widget.RadioButton;

Fixed everything. 修复了所有问题。 I had assumed it was already all imported. 我以为它已经全部进口了。 Thanks to Eugen Pechanec for the helpful tips. 感谢Eugen Pechanec的有用提示。

Make sure you are importing the correct libraries. 确保您导入了正确的库。 Also once correctly imported 也可以一次正确导入

initialize radioButtons :
RadioButton rd;

In the onCreate method: onCreate方法中:

rd = (RadioButton)findViewById(R.id.radioButton);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM