This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/10/30

student attendance error

divinity divinity

2017/10/30

#
hi everyone/anyone I am currently doing an attendance student register. now start to build it. the program goes somethings like this, the program suppose to allow the lecturer to mark student either absent or present, and if there is a holidays in between the day when there is a class, it can allow the lecture to plan a make up class , i tried to implement an if and else statement but ran into a runtime error on line. can u tell me what is the cause of the error and how it can be fixed. here is the codes that I have used. it isnt much because I have now started.
public class AttendanceRecordSystem extends javax.swing.JFrame {

    /**
     * Creates new form AttendanceRecordSystem
     */
    public AttendanceRecordSystem() {
        initComponents();
        
        ArrayList <AttendanceRecordSystem> list = new ArrayList<>();
        
        String classday=null ;
        String makeup_class = null, plan;
        
        if(classday.contains("holidays")){
            
            System.out.println("plan"+ makeup_class);
            
        }
        
    }

        here is the output. the runtime error I am speaking about



    
     
   
[code]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at AttendanceRecordSystem.AttendanceRecordSystem.<init>(AttendanceRecordSystem.java:27)
	at AttendanceRecordSystem.AttendanceRecordSystem$4.run(AttendanceRecordSystem.java:190)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745)
	at java.awt.EventQueue.access$300(EventQueue.java:103)
	at java.awt.EventQueue$3.run(EventQueue.java:706)
	at java.awt.EventQueue$3.run(EventQueue.java:704)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:715)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
divinity divinity

2017/10/30

#
the error is on line 14 and the other error is this
 java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new AttendanceRecordSystem().setVisible(true);
               
            }
divinity divinity

2017/10/30

#
the other error is on line 4
danpost danpost

2017/10/30

#
When given a run-time error trace output, only take the top-most line as the line the error occurred on (provided it refers to a line within your project). The lines below it give you a sense of how it got to the error line; not that errors occurred there also. So, line 4, in the 'run' method should be okay. Line 14, on the other hand is calling a method, 'contains', on a String variable, 'classday' which you had just declared and set a null value to at line 11. Its value does not change in between those lines. Similarly, line 16 will always output "null" for the String variable 'makeup_class' (declared and set to null at line 12; no change in value in between). Without a detailed explanation of what you are trying to have the code do, it is difficult to give any further advise.
divinity divinity

2017/10/30

#
ah was trying to do if there comes a day when there is a holidays on a class day, is to plan a make up class in order to compensate for the loss class day, the reason for the null, is when i add the if(classday.contains("holiday") it was saying it is not initialized hence the reason for the null, didnt know what else to do
danpost danpost

2017/10/30

#
divinity wrote...
if there comes a day when there is a holidays on a class day, is to plan a make up class in order to compensate for the loss class day
Then, it figures that 'classday' needs to be set to some specific day before it can be checked for being a holiday. Where are the days stored? or come from?
divinity divinity

2017/10/30

#
is it possible it can be stored in an arraylist
danpost danpost

2017/10/31

#
divinity wrote...
is it possible it can be stored in an arraylist
That certainly would not be a permanent solution. Only during program running with a loading/saving system to a database or file system.
divinity divinity

2017/10/31

#
okay but just for trying out sake, i put the days of the week in an arraylist, i had gotten an error to create a new class which i did, now now I am getting another error saying: illegal start of type and classday does exist since I have given it a value. and it is also telling me to add a return type:
 public class daysoftheweek{
        
         String classday = "thursday";
         String makeup_class = "Sunday";
         String plan;
         
          if(classday.contains("holidys")){
              
          }
         
       
    }
divinity divinity

2017/10/31

#
the error is on line 7
danpost danpost

2017/10/31

#
For one thing, I do not think you needed to create another class. The error is because you created a class with an open command line (an 'if' statement that is not within a code block). Show what you tried with the arraylist.
You need to login to post a reply.