Note that there are some explanatory texts on larger screens.

plurals
  1. POScanner.nextInt() Returns null
    primarykey
    data
    text
    <p>Edit: Yes, I know that <code>ScanObj</code> is not a proper name. And here is all of my code. It is not complete so there are some errors and some glitches, but you asked for it:</p> <pre><code>import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.util.Scanner; import javax.swing.JFrame; public class MainClass { static String[][] medium = new String[5][4]; static String names[] = { "Gatz ", "Cat ", "Women", "Mice ", "Robin", "Romeo ", "Summer ", "Tempest", "Hamlet ", "Lear ", "Titanic ", "StarWars", "DieHard ", "Elf ", "RED " }; static String lexile[] = { "L:1070", "L:123 ", "L:9254", "L:1234", "L:534 ", "L:349", "L:632 ", "L:1097", "L:6453", "L:812 ", "L:NA ", "L:NA ", "L:NA ", "L:NA ", "L:NA ", "L:NA " }; static String grade[] = { "G:9", "G:10", "G:12", "G:11", "G:9", "G:12", "G:11", "G:9", "G:9", "G:12", "G:12", "G:11", "G:11", "G9", "G:9" }; static int max = 4; char sorttype = (Character) null; public static void main(String args[]) throws InterruptedException { System. out.println("Would you like to browse:\nB)Book C)CD or D)DVD"); Scanner ScanObj = new Scanner(System.in); String[] input = new String[10]; input[1] = ScanObj.nextLine(); int store[] = { 6, 6, 6, 6, 6, 6 }; if (input[1].equals("B") || input[1].equals("Book") || input[1].equals( "book") || input[1].equals("b")) { String temp[][] = new String[5][4]; int random[] = new int[5]; boolean repeat = true; int nums[] = new int[5]; for (int i = 0; i &lt; 5; i++) { temp[i][0] = "book"; temp[i][1] = names[i]; temp[i][2] = lexile[i]; temp[i][3] = grade[i]; for (int qwop = 0; qwop &lt; 4; qwop++) { medium[i][qwop] = temp[i][qwop]; if (qwop == 0) System. out.printf(i + 1 + " | "); else if (qwop &lt; 3) System. out.printf(medium[i][qwop] + " | "); else System. out.println(medium[i][qwop] + "\n"); Thread.sleep(150); } // System.out.println(temp[i][i]); // random = store[i]; if (i == 4) System. out.printf("\n\n\n"); } } if (input[1].equals("C") || input[1].equals("c") || input[1].equalsIgnoreCase( "CD") || input[1].equals("cd")) { String temp[][] = new String[5][4]; for (int i = 0; i &lt; 5; i++) { int random1 = (int) (Math.random() * max) + 6; for (int p = 0; p &lt; 4; p++) { for (random1 = (int) (Math.random() * max) + 6; random1 == store[p];) { random1 = ( int) (Math.random() * max) + 6; } } temp[i][0] = "CD"; temp[i][1] = names[i + 5]; temp[i][2] = lexile[i + 5]; temp[i][3] = grade[i + 5]; for (int qwop = 0; qwop &lt; 4; qwop++) { medium[i][qwop] = temp[i][qwop]; if (qwop &lt; 3) System. out.printf(medium[i][qwop] + " | "); else System. out.println(medium[i][qwop] + "\n"); Thread.sleep(150); } // System.out.println(temp[i][i]); random1 = store[i]; if (i == 4) System. out.printf("\n\n\n"); } } if (input[1].equalsIgnoreCase("D") || input[1].equalsIgnoreCase("DVD")) { String temp[][] = new String[5][4]; for (int i = 0; i &lt; 5; i++) { int random1 = (int) (Math.random() * max) + 6; for (int p = 0; p &lt; 4; p++) { for (random1 = (int) (Math.random() * max) + 6; random1 == store[p];) { random1 = ( int) (Math.random() * max) + 6; } } temp[i][0] = "DVD"; temp[i][1] = names[i + 10]; temp[i][2] = lexile[i + 10]; temp[i][3] = grade[i + 10]; for (int qwop = 0; qwop &lt; 4; qwop++) { medium[i][qwop] = temp[i][qwop]; if (qwop &lt; 3) System. out.printf(medium[i][qwop] + " | "); else System. out.println(medium[i][qwop] + "\n"); Thread.sleep(150); } // System.out.println(temp[i][i]); random1 = store[i]; if (i == 4) System. out.printf("\n\n\n"); } } // for loop goes through each of the parameters and compltes the // instructions System. out .println( "How would you like to sort?\nA)Name B) Lexile C) Grade Level"); input[2] = ScanObj.nextLine(); for (int i = 0; i &lt; 3; i++) { for (int j = 0; j &lt; 2; j++) { // if statement checks if the condition is true, then does the // instructions if it is // compareTo checks the ascii values of two strings. If the // second // is smaller (would come first in alphabetic order) it returns // -1 boolean mismatch = true; while (mismatch) { if (input[2].equalsIgnoreCase("a")) { mismatch = false; // makes a new temporary String String temp1 = null; // Switches the String at position i with the one above // it for (int z = 0; z &lt; medium.length - 1; z++) { for (int x = z + 1; x &lt; medium.length; x++) { if (medium[z][1].compareTo(medium[x][1]) &gt; 0) { for (int qwop = 0; qwop &lt; 4; qwop++) { temp1 = medium[z][qwop]; medium[z][qwop] = medium[x][qwop]; medium[x][qwop] = temp1; } mismatch = true; } } } } if (input[2].equalsIgnoreCase("b")) { mismatch = false; // makes a new temporary String String temp3 = null; // Switches the String at position i with the one above // it for (int z = 0; z &lt; medium.length - 1; z++) { for (int x = z + 1; x &lt; medium.length; x++) { if (medium[z][2].compareTo(medium[x][2]) &gt; 0) { for (int qwop = 0; qwop &lt; 4; qwop++) { temp3 = medium[z][qwop]; medium[z][qwop] = medium[x][qwop]; medium[x][qwop] = temp3; } mismatch = true; } } } } if (input[2].equalsIgnoreCase("c")) { mismatch = false; // makes a new temporary String String temp3 = null; // Switches the String at position i with the one above // it for (int z = 0; z &lt; medium.length - 1; z++) { for (int x = z + 1; x &lt; medium.length; x++) { // Here I encounter an error because compareTo() // sorts Lexicographically, meaning anything // starting with a 1 comes before anything // starting with a 2, 3, etc. This means that // Grade 11 comes before grade 9, and simply // comparing greater than does not work due to // the fact that they are Strings. if (medium[z][3].compareTo(medium[x][3]) &gt; 0) { for (int qwop = 0; qwop &lt; 4; qwop++) { temp3 = medium[z][qwop]; medium[z][qwop] = medium[x][qwop]; medium[x][qwop] = temp3; } mismatch = true; } } } } } } } Thread.sleep(1000); for (int prt = 0; prt &lt; medium.length; prt++) { for (int qwop = 0; qwop &lt; 4; qwop++) { if (qwop &lt; 3) System. out.printf(medium[prt][qwop] + " | "); else System. out.println(medium[prt][qwop]); } } Thread.sleep(1800); for (int t = 0; t &lt; 1000; t++) { System. out.println("\n\n\nTo edit a selection, type edit\n" + "To sort by a different category, type sort\n" + "To browse another medium, type browse\n" + "To search the " + medium[1][0] + "s, type search"); input[3] = ScanObj.nextLine(); if (input[3].equalsIgnoreCase("browse")) { Thread.sleep(500); System.out.println("What would you like to browse?:"); if (medium[1][0].equals("book")) { System.out.println("CDs, or DVDs"); input[4] = ScanObj.nextLine(); } if (medium[1][0].equals("CD")) { System.out.println("Books, or DVDs"); input[4] = ScanObj.nextLine(); } if (medium[1][0].equals("DVD")) { System.out.println("Books, or CDs"); input[4] = ScanObj.nextLine(); } if (input[4].equalsIgnoreCase("CD") || input[4].equalsIgnoreCase("DVD") || input[4].equalsIgnoreCase("Book")) { for (int i = 0; i &lt; 5; i++) { String temp[][] = new String[5][4]; temp[i][0] = "CD"; int addon = 0; if (input[4].equals("CD")) addon = 5; if (input[4].equals("DVD")) addon = 10; temp[i][1] = names[i + addon]; temp[i][2] = lexile[i + addon]; temp[i][3] = grade[i + addon]; for (int qwop = 0; qwop &lt; 4; qwop++) { medium[i][qwop] = temp[i][qwop]; if (qwop &lt; 3) System. out.printf(medium[i][qwop] + " | "); else System. out.println(medium[i][qwop] + "\n"); Thread.sleep(150); } } } } if (input[3].equalsIgnoreCase("edit")) { Thread.sleep(500); System. out.println("First type the number of the " + medium[1][0] + "\nyou want to edit"); int input4 = ScanObj.nextInt(); System. out .println( "Now, type the number of the column you want to edit"); int input5 = ScanObj.nextInt(); System. out.println("Now, make your edit:\n"); input[6] = ScanObj.nextLine(); medium[input4][input5] = input[6]; System. out.println(medium[input4][input5]); } for (int y = 0; y &lt; 10; y++) { if (input[3].equalsIgnoreCase("search")) { Thread.sleep(2000); System. out.println("Would you like to search by 1) Title or 2) Lexile #"); int input4 = 1; input4 = ScanObj.nextInt(); Thread.sleep(2500); System. out.println("Now Type your search"); input[5] = ScanObj.nextLine(); Thread.sleep(2500); for (int i = 0; i &lt; 5; i++) { System. out.println(input4 + ", " + input[5]); System. out.println(medium[i][input4]); if (input[5].compareToIgnoreCase(medium[i][input4]) == 0) { y = 10; System. out.println("why do you lie"); for (int r = 0; r &lt; 4; r++) { if (r &lt; 3) System. out.printf(medium[i][r] + " | "); else System. out.println(medium[i][r]); Thread.sleep(150); } } else System. out.println(medium[i][input4]); System. out.println("Couldn't find item, please search again:"); } } } } } } </code></pre> <p>Where <code>ScanObj</code> is my scanner. I'm just trying to get an <code>Integer</code> input, but it always returns <code>null</code>. What's wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload