readline Error

readline Error

Hi sir, please helpme with my code.

Mycode does not work. The readLine () method seems to loose the first character of the string input from command line after the the first call to it. When Ienter the text abcd, the firt time it prints it correctly, every other time the first character is missing. Why is this.

class TestAdvt
{
public static void main (String[] args)
{
boolean done=false;
while (!done)
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;

try
{
System.out.println ("Please enter the advertisement message to be displayed (enter 'n' to exit)");

str = br.readLine(); // Read input from command

if (!str.equalsIgnoreCase("n"))
{
System.out.println ("str1 = " + str);
Thread advt = new Thread(new Advertisement(str));

advt.start();
System.in.read(); // wait for input <ENTER>
advt.interrupt();

}
else
{
System.out.println ("str2 = " + str);
done = true;
br.close();
}
}
catch (IOException e)
{
System.out.println("IOException caught: " + e.getMessage());
}


}

} // end of main()
}
// --------End: TestAdvt.java ------------


class Advertisement extends Thread
{
private String message;

Advertisement (String message) { this.message=message;}

public void run()
{
while (!message.equals(""))
{
try
{
System.out.print(message+".. ");
Thread.sleep(1000);

}
catch (InterruptedException e)
{
this.message="";
break;
}
}
} // end of 'run()' ..


}

// --------End: Advertisement.java ------------
View Answers

April 27, 2010 at 3:10 PM

Hi Friend,

Your code works fine here.

Thanks

April 27, 2010 at 4:19 PM

The error is hard to pust. but if you execute the code,
1. enter a string the first input request (eg hello world),
2. ENTER
3. ENTER n
The code will not terminated after the 'n'. This is because the first char is missing and from the readLine(). You would have to to enter 'nn'
for the code to exit. I think the problem is caused by the read() statement, just don't know why.

If on step 3 you type bye world, you would see the text (ye world), again the first char is missing.

Could you please check again. I have to use the System.in.read() for this home work.

thanks sella









Related Tutorials/Questions & Answers:
readline Error - Java Beginners
readline Error  Hi sir, please helpme with my code. Mycode does not work. The readLine () method seems to loose the first character of the string...; Hi Friend, Your code works fine here. Thanks  The error
readline Error 2 - Java Beginners
readline Error 2  Hi sir, can you look again please. The error is hard to notice, but if you execute the code, 1. enter a string the first input... is missing and from the readLine(). You would have to to enter 'nn' for the code
Advertisements
ModuleNotFoundError: No module named 'readline'
library, ModuleNotFoundError: No module named 'readline' error...ModuleNotFoundError: No module named 'readline'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'micropython-readline'
: No module named 'micropython-readline' error? Thanks   Hi..., ModuleNotFoundError: No module named 'micropython-readline' error...ModuleNotFoundError: No module named 'micropython-readline'  Hi
ModuleNotFoundError: No module named 'micropython-readline'
: No module named 'micropython-readline' error? Thanks   Hi..., ModuleNotFoundError: No module named 'micropython-readline' error...ModuleNotFoundError: No module named 'micropython-readline'  Hi
ModuleNotFoundError: No module named 'micropython-readline'
: No module named 'micropython-readline' error? Thanks   Hi..., ModuleNotFoundError: No module named 'micropython-readline' error...ModuleNotFoundError: No module named 'micropython-readline'  Hi
ModuleNotFoundError: No module named 'pycopy-readline'
'pycopy-readline' error? Thanks   Hi, In your python... named 'pycopy-readline' error will be solved. Thanks...ModuleNotFoundError: No module named 'pycopy-readline'  Hi, My
ModuleNotFoundError: No module named 'urwid-readline'
'urwid-readline' error? Thanks   Hi, In your python... 'urwid-readline' error will be solved. Thanks...ModuleNotFoundError: No module named 'urwid-readline'  Hi, My
Version of rubygems>jruby-readline dependency
List of Version of rubygems>jruby-readline dependency
Maven Dependency jruby-readline >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of rubygems >> jruby-readline version1.1.1 in your project
Maven Dependency jruby-readline >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of rubygems >> jruby-readline version1.1.0 in your project
Maven Dependency jruby-readline >> 1.0
You should include the dependency code given in this page to add Maven Dependency of rubygems >> jruby-readline version1.0 in your project
Maven Repository/Dependency: rubygems | jruby-readline
Maven Repository/Dependency of Group ID rubygems and Artifact ID jruby-readline. Latest version of rubygems:jruby-readline dependencies. # Version Release Date 1 1.2.0
error
error  while iam compiling iam getting expected error
Error-
Error-   Hello, I would like to know about XSD file. I try to print XML file but I am getting error SAXException-- says Content is not allowed in prolog. Please help me
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  i have 404 error in my program plz tell me yhe solution about
error
/ServletUserEnquiryForm.shtml getting an error given below SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error please suggest
Error
Error  I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'. This error come only in IE browser, but in other brower
error
error  java.lang.unsupportedclassversionerror:bad major version at offset 6 how to solve this????   Hi, Please check the version of framework used and also the JDK version.ADS_TO_REPLACE_1 This type error also comes
error
error
error
error  When I deploye the example I have this message cannot Deploy HelloWorld Deployment Error for module: HelloWorld: Error occurred during deployment: Exception while deploying the app [HelloWorld
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern = /^\d{3,5
error
"+it); } } this is my program i am getting an error saying cannot find symbol class stringADS
error
error  whats the error.............. import java.util.Scanner; public class g { public static void main(String[] args) { Scanner s=new Scanner(System.in); int d,x,y; System.out.println("Enter the first number
Maven dependency for rubygems - jruby-readline version 1.2.1 is released. Learn to use jruby-readline version 1.2.1 in Maven based Java projects
Maven dependency for  rubygems  - Version 1.2.1 of jruby-readline released The developers of   rubygems - jruby-readline project have... of  rubygems - jruby-readline library is 1.2.1. Developer can use
Maven dependency for rubygems - jruby-readline version 1.2.0 is released. Learn to use jruby-readline version 1.2.0 in Maven based Java projects
Maven dependency for  rubygems  - Version 1.2.0 of jruby-readline released The developers of   rubygems - jruby-readline project have... of  rubygems - jruby-readline library is 1.2.0. Developer can use
ReadLine(String fmt,Object... args) of Console class - Java Beginners
ReadLine(String fmt,Object... args) of Console class  How to reload the string and objects of console class in Java?  Hi friend,import java.io.Console;import java.io.PrintWriter;import java.util.Scanner; public class
error
error
error
error
error
error message
error message  Sir i make one form facility with insert,update,delete.i want to error msg if any type of the data is missing and display in error msg which of the data is misssing
Permgen error
Permgen error  hi how can i solve permgen error
installation error
installation error  hi, m getting an error like " semicolon found in the selected path".how to resolve this error? during installation of jdk 1.6
error log
error log  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details-------------- Table
MAin error
MAin error  Error while running hello program in another dir rather in bin. path is already set. java -version jdk1.6.0_24 no error while compilation but @ d tym of runnin error in main class is generated Exception in thread
JSF error
JSF error  some of the users are not able to update the db. getting the error "An Error Occurred: Error calling action method of component with id CreateorManageOffer:jidjsp134312524923 Caused by: java.lang.NullPointerException
404 error
into jboss->server-> default->deploy folder it doesn't shows any error. but when i run this application by using localhost:8080/webapp ,it shows 404 error how should i slove this error
404 error
404 error  struts application having 404 error while hosting to a online server.it works fine in my local machine but dont work in virtual host.showing 404 error
Error display
Error display  I want to give a message on the screen that an error has occured...but I dont want to use alert and give pop up box...any other solution for the problem
JSP error
JSP error  what is difference between global-exception and error-page in jsp. which condition they are use
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team

Ads