N
N
Nordman992021-09-30 15:35:21
Java
Nordman99, 2021-09-30 15:35:21

I am writing the first Hello World project and immediately fail, what is the mistake?

Good day to everyone, tell me by mistake,
I just started studying development on Android studio according to the book "Mobile Application Development"
by M.A. Fedotenko 2019 the Start button is fixed, there is no such thing in andre.studio libs, downloaded the picture from the Internet, called it Button.png, put it in the project folder in \AndroidStudioProjects\HelloWorld\app\src\main\res\drawable\
I did everything according to the manual, I run Build - Make Project
During the build process, there was an error right away - the studio cursed, the error is that there should not be capital letters in the name of the resource files, well renamed Button.png to button.png
re-pointed to this file in the button properties, but the name with a capital letter still remained in the properties, Build - Make Project failed again, deleted Button.png altogether, and cleared the link to it from the button properties, updated the resources, dropped the button. png again, updated the resources, specified button.png in the button properties, now I am doing Build - Make Project and now other errors:
1st error:
startButton.setImageResource(R.drawable.android);
^
symbol: variable startButton
location: class MainActivity

2nd error:
startButton.setClickable(false);
^
symbol: variable startButton
location: class MainActivity

6155ad7bbaa7a666278593.png
Here is the MainActivity.java code itself

package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView helloText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        helloText= (TextView) findViewById(R.id.helloText);
    }

    public void onStartButtonClick(View view) {
        startButton.setImageResource(R.drawable.android);   - 20 строка, 1ая ошибка
        helloText.setVisibility(view.VISIBLE);
        startButton.setClickable(false);       - 22 строка, 2ая ошибка

    }
}


AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Мое первое приложение"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HelloWorld">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Kosolobov, 2021-09-30
@Nordman99

Since you are writing in Java, I immediately advise you to use SceneBuilder to create a GUI.
The description of the onButtonClickEvent event is also recommended to be written in a separate controller.
Errors occur due to a non-existent startButton.

B
BorLaze, 2021-09-30
@BorLaze

just started learning development on android studio

What's in Android Studio, what's in Java, I'm a little more than zero

because you still need to study the language itself first, and only then its application for a specific platform
, then there would be no questions "what's wrong here" when the variable is not declared ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question