0

//MAIN ACTIVITY.java..........

package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;    
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
       private class Person {
        Spy mySpy = new Spy(name:"Frank", id:24851)
    }
}

//Spy.java

package com.example.helloworld;

public class Spy {

    public String name;
    public int id;

    public Spy(String name, int id){
        this.name= name;
        this.id= id;    
    }    
}
Stultuske
  • 9,296
  • 1
  • 25
  • 37
  • `Spy mySpy = new Spy(name:"Frank", id:24851);` is an incorrect way of setting values of `Spy` object. You need to do this: `Spy mySpy = new Spy("Frank", 24851);` You don't need to specify `name` and `id` in the constructor, just provide the values – nehacharya Apr 03 '21 at 07:02

1 Answers1

0

Try to change this (kotlin way):

 Spy mySpy = new Spy(name:"Frank", id:24851)

to this (java way):

 Spy mySpy = new Spy("Frank", 24851)
shmakova
  • 6,076
  • 3
  • 28
  • 44