-1

I have two classes, one is Course, another is CourseController. They are in the same package , same path; But when I compile javac CourseController.java, Intellij says :"error: cannot find symbol"

Course:

package com.mjfirstSBv5.sprintboot.learnspringboot;

public class Course {
    private int id;
    private  String name;
    private  String author;

    public Course(int id, String name, String author)
    {
        super(); //why this?
        this.author = author;
        this.name =name;
        this.id = id;



    }

    @Override
    public String toString() {
        return "Course{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", author='" + author + '\'' +
                '}';
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getAuthor() {
        return author;
    }
}

CourseController

package com.mjfirstSBv5.sprintboot.learnspringboot;


//import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

//@RestController
public class CourseController {

    public List<Course> retrieveAllCourses()
    {
        return Arrays.asList(
                new Course(1, "learn aws", "28min"),
                new Course(2, "learn spring boot", "28min" )

        );

    }

}

PS D:\AutoQA_Progress\intg-mock-service\learn-spring-boot\src\main\java\com\mjfirstSBv5\sprintboot\learnspringboot> javac Course.java

PS D:\AutoQA_Progress\intg-mock-service\learn-spring-boot\src\main\java\com\mjfirstSBv5\sprintboot\learnspringboot> javac CourseController.java  
CourseController.java:12: error: cannot find symbol
    public List<Course> retrieveAllCourses()
                ^                           
  symbol:   class Course                    
  location: class CourseController  
        
CourseController.java:15: error: cannot find symbol 
                new Course(1, "learn aws", "28min"),
                    ^                               
  symbol:   class Course
  location: class CourseController

CourseController.java:16: error: cannot find symbol
                new Course(2, "learn spring boot", "28min" )
                    ^
  symbol:   class Course
  location: class CourseController

3 errors
PS D:\AutoQA_Progress\intg-mock-service\learn-spring-boot\src\main\java\com\mjfirstSBv5\sprintboot\learnspringboot> 

enter image description here

Progman
  • 16,827
  • 6
  • 33
  • 48
nick nick
  • 1
  • 1
  • 1
    That's because you haven't compiled `Course`. If you are learning `spring-boot`, use Maven or Gradle too. – tgdavies May 21 '23 at 00:15
  • 1
    Specify exactly **how** you are trying to compile. Nothing wrong with ant, maven, gradle, sbt or leningen. – Elliott Frisch May 21 '23 at 00:16
  • Than you tgdavies, i did compiled Course and used Maven :) – nick nick May 21 '23 at 00:17
  • @ElliottFrisch , I'm new here and not good at English. I've pasted the compile steps i was using , could you pls help take a look? – nick nick May 21 '23 at 00:29
  • Try `javac *.java` (use a build tool. Ant, Maven, Gradle, SBT or leningen. It will make your life much easier. Even more importantly, use ant IDE with support for one of the above. Maven is usually the most popular. Ant is old school. The others serve different needs. But all are superior to straight `javac`.) – Elliott Frisch May 21 '23 at 00:46
  • @ElliottFrisch I tried javac *.java , 1. The compile starts from Main, i got another error package org.springframework.boot does not exist; but actually Maven has downloaded the package right in the lib.... I was following this tutorial. https://www.youtube.com/watch?v=zTAHY0SLQAg I will try find another one to see if can skip this error... – nick nick May 21 '23 at 01:06
  • Build with a maven command, e.g. `mvn package` rather than trying to use `javac` directly. – tgdavies May 21 '23 at 01:14

1 Answers1

0

Compile Course first. The other class needs it to be compiled.

aled
  • 21,330
  • 3
  • 27
  • 34