Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:41:08+00:00 2026-06-09T02:41:08+00:00

I’m writing a program that could manage universitary students with courses and subjects. The

  • 0

I’m writing a program that could manage universitary students with courses and subjects. The problem of the class I’m showing you is that when the method

public CorsoStudi(String unNomeCorso, ArrayList unElencoMaterie, int unIdCorso)

is called it throws a NullPointerException at line elencoEsamiDati.add(q);. So, probably the problem is with this line and the line after this:

EsameDato q = new EsameDato(unElencoMaterie.get(contatore), 0);

Eclipse doesn’t advice error on writing code.

Creatore.java

import java.util.ArrayList;
import java.util.Scanner;

public class Creatore {

int counterStudenti = 0;
int counterMaterie = 0;
int counterCorsi = 0;
//int counterEsami = 0;
ArrayList<Studente> listaStudenti = new ArrayList<Studente>();
ArrayList<Materia> listaMaterie = new ArrayList<Materia>();
ArrayList<CorsoStudi> listaCorsi = new ArrayList<CorsoStudi>();
//ArrayList<EsameDato> listaEsami = new ArrayList<EsameDato>();


public void iscriviStudente(String nomeStudente, String cognomeStudente, CorsoStudi corsoStudente){
    listaStudenti.add(new Studente(nomeStudente, cognomeStudente, counterStudenti, corsoStudente));
    counterStudenti++;
}

public void reimmatricolaStudente(int unaMatricola, int unIdCorso){
    int c = 0;
    CorsoStudi unCorso = null;
    for(c = 0; c < listaCorsi.size(); c++){
        if(listaCorsi.get(c).getIdCorso() == unIdCorso)
            unCorso = listaCorsi.get(c);
    }
    int contatore = 0;
    for(contatore = 0; contatore < listaStudenti.size(); contatore++)
        if(listaStudenti.get(contatore).getMatricola() == unaMatricola){
            iscriviStudente(listaStudenti.get(contatore).getNome(), listaStudenti.get(contatore).getCognome(), unCorso);
            rimuoviStudente(unaMatricola);
        };
}

public void rimuoviStudente(int matricola){
    int contatore;
    for(contatore = 0; contatore < listaStudenti.size(); contatore++){
        if(listaStudenti.get(contatore).getMatricola() == matricola)
            listaStudenti.remove(contatore);
    }
}

public Materia creaMateria(String nomeMateria, int crediti){
    listaMaterie.add(new Materia( nomeMateria, crediti, counterMaterie));
    counterMaterie++;
    return listaMaterie.get(counterMaterie - 1);
}

public void creaCorsoStudi(String nomeCorso, ArrayList<Materia> materieCorso){
    CorsoStudi q = new CorsoStudi( nomeCorso, materieCorso, counterCorsi);
    listaCorsi.add(q);
    counterCorsi++;
}

public ArrayList<Studente> cercaStudente(int opzione, String pattern){
    int contatore = 0;
    ArrayList<Studente> listaRicercati = new ArrayList<Studente>();
    //opzione 1 = ricerca per nome
    if(opzione == 1)
        for(contatore = 0; contatore < listaStudenti.size(); contatore++){
            if(listaStudenti.get(contatore).getNome().equalsIgnoreCase(pattern))
                listaRicercati.add(listaStudenti.get(contatore));
        };
    //opzione 2 = ricerca per cognome
    if(opzione == 2)
        for(contatore = 0; contatore < listaStudenti.size(); contatore++){
            if(listaStudenti.get(contatore).getCognome().equalsIgnoreCase(pattern))
                listaRicercati.add(listaStudenti.get(contatore));
    };
    //opzione 3 = ricerca per matricola
    if(opzione == 3)
        for(contatore = 0; contatore < listaStudenti.size(); contatore++){
            if(listaStudenti.get(contatore).getMatricola() == Integer.parseInt(pattern))
                listaRicercati.add(listaStudenti.get(contatore));
    };
    //opzione 4 = ricerca per corsoStudi
    if(opzione == 4)
        for(contatore = 0; contatore < listaStudenti.size(); contatore++){
            if(listaStudenti.get(contatore).getCorsoStudi().getIdCorso() == Integer.parseInt(pattern))
                listaRicercati.add(listaStudenti.get(contatore));
    };

    return listaRicercati;
}

public Materia materiaDaId(int id){
    int c = 0;
    Materia materiaDaRitornare = null;
    for(c = 0; c < listaMaterie.size(); c++){
        if(listaMaterie.get(c).getIdMateria() == id)
            materiaDaRitornare = listaMaterie.get(c);
    }
    return materiaDaRitornare;
}
}

CorsoStudi.java

import java.util.ArrayList;
import java.util.Scanner;

public class CorsoStudi {

private String nomeCorso;
private int idCorso;
private ArrayList<Materia> elencoMaterie;
private ArrayList<EsameDato> elencoEsamiDati;

public CorsoStudi(String unNomeCorso, ArrayList<Materia> unElencoMaterie, int unIdCorso){
    nomeCorso = unNomeCorso;
    elencoMaterie = unElencoMaterie;
    idCorso = unIdCorso;
    int contatore = 0;
    //EsameDato q = null;
    for(contatore = 0; contatore < unElencoMaterie.size(); contatore++){
        EsameDato q = new EsameDato(unElencoMaterie.get(contatore), 0);
        elencoEsamiDati.add(q);
    };
}

public String getNomeCorso(){
    return nomeCorso;
}

public int getIdCorso(){
    return idCorso;
}

public ArrayList<Materia> getElencoMaterie(){
    return elencoMaterie;
}

public ArrayList<EsameDato> getElencoEsamiDati(){
    return elencoEsamiDati;
}

public String toString(){
    String s = "";
    s = s + "Ecco le materie di questo Corso di Studi:\n";
    int c = 0;
    for(c= 0; c < elencoMaterie.size(); c++){
        s = s + elencoMaterie.get(c).getIdMateria() + " "; 
        s = s + elencoMaterie.get(c).getNomeMateria() + " (";
        s = s + elencoMaterie.get(c).getCrediti() + " crediti)\n";
    }
    return s;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:41:11+00:00Added an answer on June 9, 2026 at 2:41 am

    You have not initialized the field elencoEsamiDati therefore the actual value is null.

    Before adding elements to an ArrayList you need to create it:

    private ArrayList<EsameDato> elencoEsamiDati = new ArrayList<EsameDato>();
    

    You may also need to initialize other fields as well.

    BTW it is not a good idea to use your own language when programming, use English instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.