简体   繁体   English

旧版本的 Android Studio 项目无法编译 - 缺少变量声明

[英]older version of Android Studio project doesnt compile - lack of variables declaration

compilation errors gradle updated编译错误gradle 已更新

My teacher on uni gave me code to an app and my task is to add some funcionalities.我的 uni 老师给了我一个应用程序的代码,我的任务是添加一些功能。 The teacher claims that code is working, that there were no errors (that I do not need to fix the code, only update some older elements so that it works).老师声称代码正在运行,没有错误(我不需要修复代码,只需更新一些旧元素以使其正常工作)。

However, it doesn't compile.但是,它不会编译。 I updated gradle (this was the first error).我更新了 gradle(这是第一个错误)。 And now, there are a few errors: "error: cannot find symbol variable label_rightAnswers", "error: cannot find symbol variable failed_level" etc. I thought that you may have occurred sth like this as well and you know if this is really lack of variabes' declaration or for example too old library, version of platform -tools idk.现在,有一些错误:“错误:找不到符号变量label_rightAnswers”,“错误:找不到符号变量failed_level”等。我以为你也可能发生过这样的事情,你知道这是否真的缺乏变量的声明或例如太旧的库,平台工具 idk 的版本。 I cant find anything useful in the internet:( When i comment these lines, there are no mistakes, the emulator starts to run but the app is not displayed.我在互联网上找不到任何有用的东西:(当我评论这些行时,没有错误,模拟器开始运行但应用程序没有显示。

Please let me know if you have any idea what this is all about.如果您知道这是怎么回事,请告诉我。 Thanks a lot!非常感谢!


part of code provoking errors:部分代码引发错误:

public class EndActivity extends Activity {

    //@SuppressLint("SetTextI18n")
    @SuppressLint("SetTextI18n")
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_end);

        Bundle extras = getIntent().getExtras();
        boolean pass = extras.getBoolean("PASS");

        if (pass) {
            passLevel();
        } else {
            failLevel();
        }

//        txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 100);

        int wrongAnswers = extras.getInt("WRONG");
        int rightAnswers = extras.getInt("RIGHT");
        int timeout = extras.getInt("TIMEOUT");
        TextView right = (TextView) findViewById(R.id.rightAnswers);
        right.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
        //int label_rightAnswers = 0;
        //int label_wrongAnswers = 0;
        //int label_timeout = 0;


        right.setText(getResources().getString(label_rightAnswers) + " " + rightAnswers);
        TextView wrong = (TextView) findViewById(R.id.wrongAnswers);
        wrong.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
        wrong.setText(getResources().getString(label_wrongAnswers) + " " + wrongAnswers);

        TextView time = (TextView) findViewById(R.id.timeout);
        time.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
        time.setText(getResources().getString(label_timeout) + " " + timeout);

    }

XML file: 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:background="@drawable/background"
    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="pg.autyzm.graprzyjazneemocje.EndActivity">

    <ImageView
        android:id="@+id/sun_image_end"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:adjustViewBounds="true"
        android:src="@drawable/sun" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:orientation="vertical">

            android:id="@+id/rightAnswers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/score" />

        <TextView
            android:id="@+id/wrongAnswers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/score" />

        <TextView
            android:id="@+id/timeout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/score" />

    </LinearLayout>

    <!--
    <ImageButton
       android:id="@+id/exitButton"
       android:layout_width="80dp"
       android:layout_height="80dp"
       android:layout_alignParentEnd="true"
       android:layout_alignParentRight="true"
       android:layout_alignParentTop="true"
       android:background="@null"
       android:scaleType="centerCrop"
       android:src="@drawable/icon_exit" />
       -->

   <TextView
       android:id="@+id/endTextMain"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:gravity="center_horizontal"
       android:textColor="@color/command"
       android:textSize="40dp"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true" />

   <ImageButton
       android:id="@+id/prevButton"
       android:layout_width="80dp"
       android:layout_height="80dp"
       android:background="@null"
       android:onClick="repeatLevel"
       android:scaleType="centerCrop"
       android:src="@drawable/icon_prev"
       android:layout_alignParentBottom="true"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true" />

</RelativeLayout>

I think these tricks will might help you.我认为这些技巧可能会对您有所帮助。

You shouldn't be importing android.R .您不应该导入android.R That should be automatically generated and recognised.这应该是自动生成和识别的。 if you get some error referring to R after removing the import then do as following:如果您在删除导入后R的错误,请执行以下操作:

Some basic steps after removing the import, if those errors appear:删除导入后的一些基本步骤,如果出现这些错误:

  • Clean your build, then rebuild清理你的构建,然后重建
  • Make sure there are no errors or typos in your XML files确保 XML 文件中没有错误或拼写错误
  • Make sure your resource names consist of [a-z0-9.] .确保您的资源名称由[a-z0-9.]组成。 Capitals or symbols are not allowed for some reason.由于某种原因,不允许使用大写字母或符号。
  • Perform a Gradle sync (via Tools > Android > Sync Project with Gradle Files)执行 Gradle 同步(通过工具 > Android > 使用 Gradle 文件同步项目)

hope so this will help you.希望这会对你有所帮助。

Now try this code:-现在试试这个代码: -

Bundle extras = getIntent().getExtras();
    boolean pass = false;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        pass = Objects.requireNonNull(extras).getBoolean("PASS");
    }

    if (pass) {
        passLevel();
    } else {
        failLevel();
    }

//        txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 100);

    int wrongAnswers = extras.getInt("WRONG");
    int rightAnswers = extras.getInt("RIGHT");
    int timeout = extras.getInt("TIMEOUT");
    TextView right = (TextView) findViewById(R.id.rightAnswers);
    right.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
    //int label_rightAnswers = 0;
    //int label_wrongAnswers = 0;
    //int label_timeout = 0;


    right.setText(getResources().getString(label_rightAnswers) + " " + rightAnswers);
    TextView wrong = (TextView) findViewById(R.id.wrongAnswers);
    wrong.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
    wrong.setText(getResources().getString(label_wrongAnswers) + " " + wrongAnswers);

    TextView time = (TextView) findViewById(R.id.timeout);
    time.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
    time.setText(getResources().getString(label_timeout) + " " + timeout);

I added few conditions.我添加了几个条件。

暂无
暂无

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

相关问题 已加载“旧” Android Studio项目-Studio更新后,它将不再打开/编译,要求更新版本吗? - Loaded “old” Android Studio project - after Studio updates it will no longer open/compile asking for even newer version? 迁移到旧版Android Studio(即3.1.2)上的androidx? - Migrate to androidx on older version of android studio i.e. 3.1.2? 如何在 ubuntu 中安装旧版本的 android studio 2.1.2 - how to install the older version of android studio 2.1.2 in ubuntu 编译要在Android Studio中使用的GitHub项目 - Compile GitHub Project to be used in Android Studio 如何在Android Studio中打开Zxing项目并进行编译? - How to open Zxing project in Android Studio and compile it? 将LibGdx项目生成到Android Studio版本1.0中? - Generating a LibGdx project into android studio version 1.0? 如何将android项目导入为库而不将其编译为apk(Android studio 1.0) - How to import android project as library and NOT compile it as apk (Android studio 1.0) 编译 Sdk 版本中的 Android Studio“无效哈希字符串”警告 - Android Studio "Invalid hash string" warning in Compile Sdk Version 我似乎无法在旧版的Android手机上运行我的Android Studio项目 - I cannot seem to run my android studio project on an older android phone Android Studio - 在现有的旧项目中启用本机 C++ 调试(card.io Android 源) - Android Studio - Enable native C++ debugging in existing older project (card.io Android Source)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM