I am working on a simple system that collects elements from an array that is chosen through a series of button events, copies it into a new array called 'oneRay' and proceeds to cycle through its elements to test the user on their knowledge. If a user correctly identifies an answer from a prompt, the first element of the 2D array in that section becomes "", and is skipped with this code:
do{
pick = random.nextInt(oneRay.length);
}while(!(oneRay[pick][0].equals("")));
Which continues to return the aforementioned exception. The following code creates random as a member of the class in question:
Random random = new Random()
So what could I be doing wrong? Any help will be greatly appreciated.
UPDATE: Yes the elements are initialized through a series of switch statements that direct proper the selected array to oneRay
The error report is huge as it is launched as I am trying to build the swing UI, so it tosses failures left and right
Here is what I used for initialization:
switch(subject){
case 1:
switch(unit){
case 1: oneRay = new String[Master.SciChemArray_IntroductionANDFirstChapter.length][2];
for(int i = 0; (Master.SciChemArray_IntroductionANDFirstChapter.length) > i; i++){
oneRay[i][0] = Master.SciChemArray_IntroductionANDFirstChapter[i][0];oneRay[i][1] = Master.SciChemArray_IntroductionANDFirstChapter[i][1];}
default: System.exit(0); break;
} break;
case 2:
switch(unit){
case 1:
oneRay = new String[Master.MathaRay_Part2.length][2];
for(int i = 0; (Master.MathaRay_Part2.length) > i; i++){
oneRay[i][0] = Master.MathaRay_Part2[i][0]; oneRay[i][1] = Master.MathaRay_Part2[i][1];} break;
default: System.exit(0); break;
} break;
When creating this setup I pass a number which corresponds to a subject and a unit number, which are then used to copy the relevant array like so ^^
Unit and Subject are passed like so:
mathstatb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent l) {
new SwingImplementation(2, 1);
}});
Whereby a button sends off subject 2 and unit 1
And here are the Errors, now at the bottom, if anyone really wants them:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at wbh.SwingImplementation.<init>(SwingImplementation.java:60)
at wbh.matstatMenu$1.actionPerformed(matstatMenu.java:23)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
oneRay
and its elements been initialized? – Sotirios Delimanolis Sep 21 '13 at 20:06