0

I am new to android and following this tutorial: https://www.youtube.com/watch?v=qK0QNA0sMGc&t=2710s (It's in Hindi)

In my MainActivity.java:

In my MainActivity.java
When I'm trying to run the app it's giving errors saying:

9 errors found
1 warning found
2 typos found

It's asking me to put a semicolon at the end of
Log.i(tag:"this", msg:"clickbtn: This is a message");
which I have already put down.

This is my activity_main.xml: acitivity_main.xml file

Can anybody tell me what are the errors?

XML Code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
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"
tools:context=".MainActivity">

<TextView
    android:id="@+id/topText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="60dp"
    android:includeFontPadding="false"
    android:paddingTop="10dip"
    android:paddingBottom="10dip"
    android:text="Welcome to Shivam Travels"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1"
    android:textSize="24sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.504"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="32dp"
    android:ems="10"
    android:hint="Enter your username"
    android:inputType="textPersonName"
    app:layout_constraintStart_toStartOf="@+id/topText"
    app:layout_constraintTop_toBottomOf="@+id/topText" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="32dp"
    android:ems="10"
    android:hint="Enter your password"
    android:inputType="textPassword"
    app:layout_constraintStart_toStartOf="@+id/editText"
    app:layout_constraintTop_toBottomOf="@+id/editText" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="28dp"
    android:onClick="clickbtn"
    android:text="Sign In"
    app:layout_constraintStart_toStartOf="@+id/checkBox"
    app:layout_constraintTop_toBottomOf="@+id/checkBox" />

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="176dp"
    android:layout_height="65dp"
    android:layout_marginTop="32dp"
    android:text="Remember me!"
    app:layout_constraintStart_toStartOf="@+id/editText2"
    app:layout_constraintTop_toBottomOf="@+id/editText2" />

InsaneCat
  • 2,115
  • 5
  • 21
  • 40

5 Answers5

3

Replace you code with this code

Replace

Log.i(tag:"this", msg:"clickbtn: This is a message");

with

Log.i("This","This is a message");

Below full snippet of you code

JAVA FILE

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MainTestActivity extends Activity {
    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        setContentView(R.layout.activity_main);
    }

    public void clickbtn(View view){
        Log.i("This","This is a message");
        Toast.makeText(context, "Button Clicked", Toast.LENGTH_SHORT).show();
    }
}

XML FILE

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/topText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        android:includeFontPadding="false"
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        android:text="Welcome to Shivam Travels"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.504"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:ems="10"
        android:hint="Enter your username"
        android:inputType="textPersonName"
        app:layout_constraintStart_toStartOf="@+id/topText"
        app:layout_constraintTop_toBottomOf="@+id/topText" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:ems="10"
        android:hint="Enter your password"
        android:inputType="textPassword"
        app:layout_constraintStart_toStartOf="@+id/editText"
        app:layout_constraintTop_toBottomOf="@+id/editText" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="28dp"
        android:onClick="clickbtn"
        android:text="Sign In"
        app:layout_constraintStart_toStartOf="@+id/checkBox"
        app:layout_constraintTop_toBottomOf="@+id/checkBox" />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="176dp"
        android:layout_height="65dp"
        android:layout_marginTop="32dp"
        android:text="Remember me!"
        app:layout_constraintStart_toStartOf="@+id/editText2"
        app:layout_constraintTop_toBottomOf="@+id/editText2" />
</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here For more details : solution

Hope this may helps you now.

InsaneCat
  • 2,115
  • 5
  • 21
  • 40
  • Do I have to add your XML code in addition to my XML code or replace my code with yours? – Shivam Rana Jan 25 '20 at 06:54
  • Right now i'm just give example...wait i'll create modification into your code. but you can get a click in a right way like this. insteadof use android:onClick="clickbtn" in XML – InsaneCat Jan 25 '20 at 06:55
  • Thanks a lot but since I have just started learning I can't figure out most of the java file but it worked without errors. :) Thanks again! – Shivam Rana Jan 25 '20 at 07:06
  • It's working now or not? check updated answer again and look below cliked text appeared. – InsaneCat Jan 25 '20 at 07:07
2

Remove tag: and msg: from your code

Ajay K S
  • 350
  • 1
  • 5
  • 16
2

You define above type not supported in java.You can do like this.

public String tag = "this";
public String msg = "clickbtn:this is a message!";


Log.i(tag,msg);
ashok
  • 431
  • 5
  • 8
2

Replace

Log.i(tag:"this", msg:"clickbtn: This is a message");

with

Log.i("this","clickbtn:this is a message!");
Siddarth Jain
  • 304
  • 1
  • 6
1

You took the code from a screenshot. The problem is that Android studio added information that shows the name of the parameter when you call a method using literals.

This information is not part of the code and Android Studio just adds it to inform you about the parameter and make the code more readable.

The actual code should be:

Log.i("this", "clickbtn: this is a message");

instead of:

Log.i(tag:"this", msg:"clickbtn: this is a message");

If you use this, Android Studio will show you the tag: and message: even if it is not part of your code.

dan1st
  • 12,568
  • 8
  • 34
  • 67