Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36096

Re: i need help figuring out what is wrong in my code

Newsgroups comp.lang.java.programmer
Date 2016-12-12 09:52 -0800
References <6f8c0f7d-a8b2-4e50-b815-d5d77e6e25d5@googlegroups.com> <9c73d4a8-b20f-42c0-bb87-dd1c1966fdbd@googlegroups.com> <o2ml4h$j28$1@dont-email.me> <64fe5d3e-7f71-4d26-ad6e-c47136806f08@googlegroups.com> <o2mnbo$rqp$1@dont-email.me>
Message-ID <a7c79903-e047-4c1c-9d60-9260f41c3bed@googlegroups.com> (permalink)
Subject Re: i need help figuring out what is wrong in my code
From Karim omar <karimyousrymohamedomar@gmail.com>

Show all headers | View raw


On Monday, December 12, 2016 at 8:40:39 PM UTC+3, Eric Sosman wrote:
> On 12/12/2016 12:06 PM, Karim omar wrote:
> > On Monday, December 12, 2016 at 8:02:39 PM UTC+3, Eric Sosman wrote:
> >> On 12/12/2016 11:54 AM, Karim omar wrote:
> >>> On Monday, December 12, 2016 at 7:13:46 PM UTC+3, Karim omar wrote:
> >>>> when i use the (reply = myScanner.findInLine(".").charAt(0);) method i get the following error message
> >>>>
> >>>> Exception in thread "main" java.lang.NullPointerException
> >>>> 	at Ifexercise1a.main(Ifexercise1a.java:18)
> >>>>
> >>>> and i am sure i wrote it write cause i tried copying and paste it from another prog which is working fine, i am using eclipse and i don`t know if it`s a bug in eclipse or something wrong in the class itself.
> >>>
> >>> thanks for your help , so i should use system.out.print instead of println?
> >>
> >>      (You posted this as a reply to your own message, so it is not clear
> >> whom you are thanking.  It would have been clearer if you had posted a
> >> reply to that person's message instead -- but on the off-chance that you
> >> are thanking ME, I'll try a further response.)
> >>
> >>      1. Your problem is with (choose one):
> >>
> >> 	[ ]  Input
> >> 	[ ]  Output
> >>
> >>      2. System.out is an ___choose one___ stream
> >>
> >> 	[ ]  Input
> >> 	[ ]  Output
> >>
> >>      3. System.out ___choose one___ involved with your problem.
> >>
> >> 	[ ]  is
> >> 	[ ]  is not
> >>
> >> --
> >> esosman@comcast-dot-net.invalid
> >> "Nobody ever went broke underestimating the intelligence of the
> >> American public." -- HLM (paraphrased)
> >
> > well i was thanking you :)
> >
> > is my problem with 3. is ?
> 
>       You are having trouble with a Scanner, right?  A Scanner that
> reads from System.in, right?  And you expect to solve this by
> doing something different with ... System.out?
> 
>      Here's a diagram (it's schematic, conceptual, not literal):
> 
> 	<======================
> 	  Input goes THIS way
> 	Your problem is with THIS
> 
> 	                          ======================>
> 	                           Output goes THAT way
> 	                        Your problem isn't with THAT
> 
> 
> -- 
> esosman@comcast-dot-net.invalid
> "Nobody ever went broke underestimating the intelligence of the
> American public." -- HLM (paraphrased)

ok i got your point , my problem is with the input which saved in the variable reply in my code and executed by the findInLine method but still i don`t know how to solve it , i tried everything i know but still not working mean while the following basic oracle program is working just fine while i am using the same technique

import java.util.Scanner;
import java.util.Random;

public class IfScannerRandomProg {

	public static void main(String[] args) {
		
		Scanner myScanner = new Scanner (System.in);
		Random myRandom = new Random ();
		
		int randomNum;
		
		System.out.println("What is your name?");
		
		String herName = myScanner.nextLine();
		
		System.out.println("hi " + herName +"," + " How are you doing today?");
		
		String   Answer1= myScanner.nextLine();
		
		System.out.println("Great, would you like to know your luck for today " + herName +"?" + "(Y/N)");
		
		char Answer2 = myScanner.findInLine(".").charAt(0);
		
		if(Answer2 == 'Y' || Answer2 == 'y'){
			System.out.println("Umm ......");
		}
		else{
			System.out.println("Ok then ,See you tomorrow!");
		}
		randomNum = myRandom.nextInt(10) + 1;
		
		switch (randomNum){
		case 1:
			System.out.println("You will have a fancy day with everything on your mind happening");
			break;
			
		case 2:
			System.out.println("Well ,it`s not your day today,sleeping is your friend today");
			break;
			
		case 3:
			System.out.println("Many people will contact you today for something you have and they want");
		break;
		
		case 4:
			System.out.println("Your time to kill your enemies");
			break;
			
		case 5:
			System.out.println("Chill out kid, everything is coming in place , be patient");
			break;
			
		case 6:
			System.out.println("Take care of the surroundings!");
			break;
			
		case 7:
			System.out.println("you will have a lot of fun today");
			break;
			
		case 8:
			System.out.println("Your worry too much , but today all your worries will go away");
			break;
			
		case 9:
			System.out.println("Live your day , it might be your last day");
			break;
			
		case 10:
			System.out.println("people will laugh at you always , so do your thing and don`t look at them");
		}
		
		
		
		

	}

}

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 08:13 -0800
  Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 08:15 -0800
    Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 11:27 -0500
  Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 08:54 -0800
    Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 12:02 -0500
      Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 09:06 -0800
        Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 12:40 -0500
          Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 09:52 -0800
            Re: i need help figuring out what is wrong in my code Eric Douglas <e.d.programmer@gmail.com> - 2016-12-12 10:21 -0800
            Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 13:36 -0500
              Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 12:28 -0800
                Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 16:28 -0500
                Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 13:39 -0800
                Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 14:17 -0800
                Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 18:08 -0500
      Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 09:09 -0800
  Re: i need help figuring out what is wrong in my code lewbloch@gmail.com - 2016-12-13 12:38 -0800
    Re: i need help figuring out what is wrong in my code Eric Douglas <e.d.programmer@gmail.com> - 2016-12-13 12:49 -0800
      Re: i need help figuring out what is wrong in my code lewbloch@gmail.com - 2016-12-14 17:01 -0800
        Re: i need help figuring out what is wrong in my code Martin Gregorie <martin@address-in-sig.invalid> - 2016-12-15 10:47 +0000
  Re: i need help figuring out what is wrong in my code Roedy Green <inquiry@mindprod.com> - 2016-12-13 16:07 -0800

csiph-web