Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: i need hep with my java program

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default i need hep with my java program

    package wow;

    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    import java.util.Scanner;

    public class Wow
    {
    String question;
    String answer;
    int correct=0, number;
    Wow[] quizBank = new Wow[14];
    List<Wow> quizList = Arrays.asList(quizBank);

    public static void main(String[] args)
    {
    Wow bank = new Wow();
    bank.bankList();
    bank.askQuestion();
    } //end main

    public void bankList()
    {
    quizBank[1] = new Wow();
    quizBank[1].question = "A version of Windows released in October 15 2001";
    quizBank[1].answer = "windows xp";

    quizBank[2] = new Wow();
    quizBank[2].question = "It is the world's first multi-touch smartphone released in June 29 2007";
    quizBank[2].answer = " iphone";

    quizBank[3] = new Wow();
    quizBank[3].question = "It is the first quad core processor released by intel";
    quizBank[3].answer = "core 2 quad";

    quizBank[4] = new Wow();
    quizBank[4].question = "He is the chief architech of the linux kernel";
    quizBank[4].answer = "linus tolvards";

    quizBank[5] = new Wow();
    quizBank[5].question = "He is the founder of Microsoft";
    quizBank[5].answer = "bill gates";

    quizBank[6] = new Wow();
    quizBank[6].question = "It is the first multitouch tablet relased by apple";
    quizBank[6].answer = "ipad";

    quizBank[7]= new Wow();
    quizBank[7].question = "Its is the latest version and codename of android";
    quizBank[7].answer = "4.2.2 jelly bean";

    quizBank[8] = new Wow();
    quizBank[8].question = "It is the operating system of iphone/ipad";
    quizBank[8].answer = "ios";

    quizBank[9] = new Wow();
    quizBank[9].question = "Its the latest version and codename of mac os x";
    quizBank[9].answer = "10.8 mountain lion";

    quizBank[10] = new Wow();
    quizBank[10].question = "how old is the microsoft corporation";
    quizBank[10].answer = "35";

    quizBank[11] = new Wow();
    quizBank[11].question = "What is the latest version and codename of ubuntu linux";
    quizBank[11].answer = "12.10 quantal quetzal";

    quizBank[12] = new Wow();
    quizBank[12].question = "it is the first computer that has a graphical users interface released by apple in 1984";
    quizBank[12].answer = "macintosh";

    quizBank[13] = new Wow();
    quizBank[13].question = "he is the current ceo of google inc.";
    quizBank[13].answer = "larry page";

    quizBank[14] = new Wow();
    quizBank[14].question = "A version of windows released in 2007";
    quizBank[14].answer = "windows vista";



    Collections.shuffle(quizList);
    }

    public void askQuestion()
    {
    Scanner input = new Scanner(System.in);
    System.out.println("****************************** **");
    System.out.println(" Welcome to TECH QUIZ");
    System.out.println("****************************** **");

    for (number=1; number<15; number++)
    {
    System.out.printf("%d. %s?%n", number, quizBank[number].question);
    String entered = input.nextLine();

    if (entered.compareTo(quizBank[number].answer)==0)
    {
    System.out.println("*** Correct! ***");
    correct = correct + 1;
    }
    else {
    System.out.println("--- Incorrect! ---");
    System.out.println("the correct answer is");
    }
    }

    System.out.println("*******************");
    System.out.printf(" Your score is %d/%d%n", correct, number);

    System.out.println("*******************");
    }

    }



    how can i get rid of this error?

    Exception in thread "main" java.lang.NullPointerException
    at wow.Wow.askQuestion(Wow.java:84)
    at wow.Wow.main(Wow.java:21)
    Java Result: 1



    How can i make this program show the correct answer in every question if the inputted answer is incorrect thanks....


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: i need hep with my java program

    Exception in thread "main" java.lang.NullPointerException
    at wow.Wow.askQuestion(Wow.java:84)
    The code at the statement on line 84 has a variable with a null value when it is executed. Find the variable with the null value and then backtrack in the code to see why that variable does not have a valid value.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Invoke a Java program with windows program
    By jackhard in forum Object Oriented Programming
    Replies: 1
    Last Post: February 21st, 2013, 07:16 AM
  2. convert java program to java ME program
    By abhishek1212 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 4th, 2013, 03:22 PM
  3. Replies: 1
    Last Post: January 17th, 2013, 07:04 AM
  4. Replies: 1
    Last Post: July 8th, 2012, 10:23 AM
  5. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 10:04 AM

Tags for this Thread