java type.fasterxml.jackson.core.JsonParser не может быть разрешен.Это косвенная ссылка из необходимых файлов .class - PullRequest
0 голосов
/ 06 декабря 2018

Мой код ниже.В этой строке myCourse = mapper.readValue (новый файл ("course.json"), Course.class);это дает мне сообщение об ошибке.Тип com.fasterxml.jackson.core.JsonParser не может быть разрешен.На него косвенно ссылаются необходимые файлы .class.У меня есть файлы кувшина Джексона на фотографии

 /* The main driver class for project 2 */

import java.util.ArrayList;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.*;
import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 

class Project2Driver
{
    public static void main(String[] args)
    {
        // Write code to create a new course, c, with some name, crn code and maximum students
        /*Course c = new Course("ICS 111","23456",10);


        // Create a new instructor, say instr, with some name, faculty id, and department.
        Instructor instr = new Instructor("Sandeep Chin","12189","ICS");

        // Create a student with some name and an id
        Student s1 = new Student("John Doe","45678");
        // Create another student with some name and id
        Student s2 = new Student("Jane Doe","19087");
        Student s3 = new Student("Bill Gates","35810");
        //System.out.println(c);
        // Create an arraylist of student objects
        ArrayList<Student> sList = new ArrayList<>();
        // Add both student objects created above to this list
        sList.add(s1);
        sList.add(s2);
        sList.add(s3);
        // set the list created above to be the list of students for course c.
        c.setStudents(sList);
        // Set instr to be the instructor for course c
        c.setInstructor(instr);
        // Print the course to verify 
        System.out.println(c);

        int pos = c.find("45678");
        if(pos>=0)
        {
            System.out.println("Found the student in position "+pos);
        }
        else
        {
            System.out.println("Student not found");

        }

       // Student s4 = new Student("Mary Jane","27890");
        // Add a student
        int result=c.addStudent(new Student("Mary Jane","27890"));

        if(result ==-1)
            System.out.println("Student already registered");
        else if(result==-2)
            System.out.println("Course is full");
        else
            System.out.println(c);
            */

        /*
        boolean removed=c.removeStudent("27890");
        if(removed==true)
            System.out.println("Student was removed");
        else
            System.out.println("Student does not exist");*/

        //******************************************************
        // Code to parse course.json to Course object
        //******************************************************
        ObjectMapper mapper = new ObjectMapper();
        Course myCourse =null;
        try 
        {
            myCourse = mapper.readValue(new File("course.json"),Course.class);
        }
        catch (IOException e) 
        {
            e.printStackTrace();
            System.exit(1);
        }
        System.out.println(myCourse);
        //******************************************************
        // Code to parse course.xml to Course object
        //******************************************************

        File file = new File("course.xml"); 
        Document doc = null; 
        try 
        { 
            doc = Jsoup.parse(file,"UTF-8"); 
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
            System.exit(1);
        } 

        // Extract data from Doc object and store in Course object

        String name= doc.select("name").first().text();
        String code = doc.select("code").text();
        String maxStudentsStr = doc.select("maxStudents").text();
        int maxStudents =Integer.parseInt(maxStudentsStr);
        Course myOtherCourse = new Course(name,code,maxStudents);

        Element instr = doc.select("instructor").first();
        String fname = instr.select("name").text();
        String fid = instr.select("fid").text();
        String dept = instr.select("department").text();
        // Create a new instructor
        Instructor myInstr = new Instructor(fname,fid,dept);
        // make myInstr the instructor for my course
        myOtherCourse.setInstructor(myInstr);
        // Now get the students from the XML file
        Element studentsTag = doc.select("students").first();
        Elements students = studentsTag.children();
        ArrayList<Student> slist = new ArrayList<>();
        for(Element student: students)
        {
            String sname= student.select("name").text();
            String sid = student.select("id").text();
            Student myStudent = new Student(sname,sid);
            slist.add(myStudent);

        }
        //System.out.println(slist);


        // Set slist as the list of students for the course
        myOtherCourse.setStudents(slist);

        System.out.println(myOtherCourse);


    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...