Run Time Error In Reading Data From Keyboard

Aug 9, 2014

i tried to run simple program od adding two number by using scanner class but there is run time error here it is code file and error.

View Replies


ADVERTISEMENT

Error In Program To Read Int Or Float Type Data From Keyboard

Aug 9, 2014

Here is a code and error .....

View Replies View Related

Reading From File And Sort Data Based On Person GPA - Catching Error

Dec 9, 2014

I am catching an error in my driver class that reads from a file and sorts the data based on a person's GPA. Here is my code:

import java.io.*;
import java.util.*;
public class Driver {
public static void main(String[] args) {
new Driver(args[0]);

[Code] ....

Why throwing this exception?

View Replies View Related

Compile Time Error - Cannot Invoke Read On Primitive Data Type Int

Jul 10, 2014

I have a code in which I am reading input from System.in and Destination is some where else

Here is my code

File file=new File("D:/output.txt");
OutputStream os=new java.io.FileOutputStream(file);
Scanner scanner=new Scanner(System.in);
System.out.println("Enter Data to write on File");
String text=scanner.nextLine();
int c=Integer.parseInt(text);
int a;
while((a=c.read())!=-1)
os.write(a);
System.out.println("File Written is Successful");

In the line while((a=c.read())!=-1)

a compile time error is shown "cannot invoke read on primitive data type int"

Where I am going wrong?

View Replies View Related

JSP :: Reading Data From MySQL Database And Displaying Results On Webpage - HTTP Status 500 Error

Feb 13, 2014

I have created a jsp file which does the simple task of reading data from a mysql database and displaying the results on a web page. Please see below:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

[Code] ....

However, each time I run the jsp file in the browser with my localhost as server, I get an HTTP Status 500 error.

View Replies View Related

Reading Values From The Keyboard?

Aug 21, 2014

why we are not able to read second string in this program.

String s1,s2,s3;
String decider;
Scanner sc = new Scanner(System.in);

[Code].....

Note: If I uncomment line num 9 it works fine

View Replies View Related

Reading The Name Of The File From The Keyboard

Feb 20, 2014

Write a program that extracts words from a file. For the purposes of this program, a word is defined as a series of adjacent letters. Only print words that are at least four and no more than 12 letters long. Print each word on a different line.

The program should read the name of the file from the keyboard.

************************************************** ************************************************** **************

I need to get the filename from the user for this particular program. Usually I would have the name of the file prewritten into the source code like this....

Scanner input = new Scanner(new File("gettsy_burg.txt");

I tried different ways but I just can't seem to figure it out.... I guess what I'm really asking is how to rearrange Scanner input = new Scanner(new File("gettsy_burg.txt"); since I want the user to input the filename instead of the filename being prewritten by the programmer(me).

This is what I have so far to let the user for input....

Scanner keys = new Scanner(System.in);
System.out.println("Enter the filename: ");
String fileName = keys.nextLine();
keys = new Scanner(new File(fileName));

View Replies View Related

Reading Name Of File From Keyboard

Feb 20, 2014

Write a program that extracts words from a file. For the purposes of this program, a word is defined as a series of adjacent letters. Only print words that are at least four and no more than 12 letters long. Print each word on a different line.

The program should read the name of the file from the keyboard.

************************************************** ************************************************** **************

I need to get the filename from the user for this particular program. Usually I would have the name of the file prewritten into the source code like this....

Scanner input = new Scanner(new File("gettsy_burg.txt");

I tried different ways but I just can't seem to figure it out....

View Replies View Related

Going Through All The Keys On Keyboard One At A Time

Jul 14, 2014

I am writing a code that tries to figure out the users password by going through every possible key (brute force). Although I think its going to work, it looks EXTREMELY inefficient to me, since its just a huge switch statement for each character -- 94 total, including the shift values. Is there a built in method in the JAVA API that goes through every key or something?

Here is my code for that segment:

public char[] HackingPassword(){
char[] passChars = this.password.toCharArray();//convert the password to char[]
char[] hacking = new char[passChars.length];//make the hacking variable same size as users password
int nextCharValue = 0;//this is used to cycle through the keyboard
//check each letter of hacking to match with password
for(int i = 0; i < passChars.length; i++){

[Code] .....

View Replies View Related

Java 2D Game - Overcoming Max Of Three Keys At A Time Limitation Of Keyboard

Jan 7, 2014

I'm working on a Java 2D game which requires a max of six keys be held down at the same time.

The game is for two players on the same keyboard, playing simultaneously.

However, all three computers I ran the program on only allow a max of three keys held at a time. They all have trouble with reacting to more than three keys being held.

It seems that pressing a new key after three are already held, either cancels some other key-holding or is ignored.

I've been told that this is a hardware issue. Most keyboards can't handle more than three keys held at a time. But a lot of games do require this, and they do not require special gaming-keyboards to run on my computer without problems.

So there has to be a solution that will make the game playable on any standard keyboard.

(I use Key Bindings).

The game's controls:

Player 1

- Rotate sprite and set angle of movement: LEFT arrow

- Rotate sprite and set angle of movement: RIGHT arrow

- Move forward: UP arrow

- Shoot missile: ENTER key

Player 2

- Rotate sprite and set angle of movement: 'A' key

- Rotate sprite and set angle of movement: 'D' key

- Move forward: 'W' key

- Shoot missile: 'T' key

Relevant code:

The Key Bindings part:

Java Code:

// An action for every key-press.
// Each action sets a flag indicating the key is pressed.
leftAction = new AbstractAction(){
public void actionPerformed(ActionEvent e){
keysPressed1[0] = true;

[Code] .....

This is mostly how reacting to key-presses and key-releases works in my program. When a key is pressed or released, a flag is set. The Board class reades the flags every game-loop cycle and reacts accordingly.

As I said, the program doesn't react correctly to more than 3 keys held at a time, probably because of the keyboard. Is there a way to code a solution?

View Replies View Related

Error Cannot Find Symbol - Variable Keyboard

Sep 14, 2014

I am trying to create this program I am pretty sure it is easy but I am making it difficult lol, it keeps giving me a error, it is saying cannot find symbol - variable keyboard, I don't think I have keyboard as a variable but I may be wrong.

double distancel = keyboard.nextdouble(); that is the specific line ....

import javax.swing.JOptionPane;
import java.io.File;
import java.util.Scanner;
//import java.util.totalInches;
//instance variables
public class Map{
public static void main(String[] args){

[Code] ....

View Replies View Related

Insert Data From Keyboard And Check Whether Any Of Constructor Fields Remained Empty

May 12, 2015

I'm trying to use in the constructor inserts from keyboard and then check whether any of the constructors fields remained empty. Let say my constructor is:

public SomeClass(String a, String b, String c)throws SomeClassException{
if (a == null || b == null || c == null) {throw new SomeClassException("Some message"); // here is the empty test
} //...

Thus I prepared method: insertConstruct() as follows:

public static String insertConstruct(){
String lettering = null;
Scanner sc = new Scanner(System.in);
lettering= sc.nextLine();
return lettering;
}

And during creating the new object in some main method I call:

// ...
ClassName obj1;
obj1 = new ClassName(insertConstruct(),insertConstruct(),insertConstruct());
//...

The problem is not with inserting data but with leaving the field empty. When I pass any field just with keyboards Enter, the empty test doesnt return me any message about it. While it works if I build object with the constructor like:

// ...
className obj1;
obj1 = new ClassName("word a",null,"word c");
//...

What might case this failure?

View Replies View Related

Reading Data From A File And Putting That Data In Arrays

Feb 8, 2015

I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .

Java Code:

public static void main(String[] args) {
// TODO Auto-generated method stub
// Variables Declaration Section
//******************************
BufferedReader br;
String sCurrentLine;
String str;

[Code] ....

My issue is that the 'str' value is not initialized, but if I initialize it, it ruins the code. I'm not sure what to do in the situation.

View Replies View Related

Error In Reading Text File

May 2, 2014

I have a problem in reading the text file. I have my source text file at "D:/input.txt".When the below code is executed the following errors are coming.

" java.lang.NoClassDefFoundError: Try
Caused by: java.lang.ClassNotFoundException: Try
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)

[Code] ....

View Replies View Related

Reading ASCII Data Correctly

Jan 21, 2015

I have two programs that talk to each other over a TCP connection. When I write the data "STX+1234" where STX is the Ascii character STX or Ctrl B and I expect the written String length to be 6 which it is. On the other side of the socket I create the ServerSocket and use the client socket's InputStream to create a BufferedReader. When I receive the string it now has 12 characters where each original character has been replaced by NUL and the character.  How do I read the string as it is originally specified without the conversion? And is the problem on the reader side or the writer side?

View Replies View Related

Time - Cannot Input Any Value Into Parameter Without It Returning Error

Nov 25, 2014

I think my code is correct, but I cannot input any value into the parameter without it returning an error. I have tried different forms of the time (0734, 7:34, 7,34, and others) but none of them work. I attached a screenshot of the error message. How can I input the parameter?

public class Time extends Object
{
private int itsHour; // always in the range 0 to 23
private int itsMin; // always in the range 0 to 59 
/** Create an object for the given hour and minute. If min
* is negative, adjust the values to make 0 <= min < 60. */
 
public Time (int hour, int min) // constructor

[Code] ......

View Replies View Related

Importing CSV / Reading Data And Have A Count Using Queries

Oct 11, 2014

Ok so I know how to import a csv using java. What I'm curious about doing is importing a csv using file chooser, reading the data, sorting the data out by certain parameters, and then outputting a count of each parameter I chose. Say for example I have columns 1,2 and 3. Column 1 has the name, column 2 has the percentage, column 3 has an o'clock time. I want to use queries to sort through the parameters and have a count of each parameter I choose...

View Replies View Related

Reading Data From A File And Setting It To Array

Jun 5, 2014

I can read the data to a monitor perfectly. But, I'm having problem reading data from an external file into an array of class objects. Here's my attempt at writing the method:

private void openFile()
//This method asks the user to enter a file name(including the file extension) and then
//Sets the data to an array of Product type {
String fileName, storeName="", emptyLine1="", emptyLine2="", name="", productName="";
int demandRate=0;
double setupCost=0.0, unitCost=0.0, inventoryCost=0, sellingPrice=0;
Scanner inputStream = null;

[code]...

View Replies View Related

Reading XML Schema And Obtaining Data From It Using Java

Jan 20, 2015

A method in Java returns a schema. In .net, we use DataTable to get the data from the schema. How to write the following code in Java:

/* Result r = method();
r.DataSchema; */
using (DataTable tbl = new DataTable())
{
using (MemoryStream ms = new MemoryStream())
using (StreamWriter sr = new StreamWriter(ms))

[code]....

View Replies View Related

Reading Tabular Format Data From PDF File

Feb 20, 2015

I am working on a project where as an input I need to read to data from PDF.

The PDF data will look like

As shown below:

Serial NoName of bookQuanity of BooksLibrary NamePrice

1aaa1London

2bb2Newyork

3cc1Paris

Total number of books4

Payment info

The number of books are dynamic in every pdf which I am going to receive.

View Replies View Related

Value Format While Reading Excel Data Into Java

Jan 20, 2015

I am reading Excel data using java apache. I got format issue while reading double value such as 869.87929 (in excel) into 869.8792899999999 (in java).

I'm using following files to read excel data.

1. Schema.csv: SheetName,2-int-Double
2. File.xls:

col1 | col2
123 | 869.87929

Sample code:

if(type.equals("Double")){
String str = content[i-1];
//System.out.println(str);
BigDecimal d = new BigDecimal(str);
listObjects.add(d);
}

Note: type from schema.csv & content [] value from file.xls
If I print **str**, it shows value as 869.8792899999999.
But i need to get **str** value as 869.87929. How can I get it?

View Replies View Related

Merge Sort Data - Time Complexity

Mar 16, 2014

Suppose i have written a method like this

public void myWork(){
mergeSortMyData(); O(nlgn)
....
someProcessing(); O(n^2)
someprocessing2(); O(n^2)
}

then what will be time complexity of my code...according to me it will be O(nlgn + n^2) ...is it correct ?

View Replies View Related

Run Time Error As Null Pointer Exception While Compiling

Apr 12, 2015

I have an input text file as file.txt where, it consists of only real values separated with commas, and arranged as rows as columns as mentioned below :

1,2,3,4,5,6,10,5,8,9
1,4,7,8,9,0,6,4,3,2,1
2,4,5,8.1.3.4.6.7.9.0

the number of rows is 100 and the number of columns are 9, that is they are fixed.Above is just an example, the file consists of decimal values.What I require is for each column of values I need to find out it's average or mean, that is in above example,

for 1st column:(1+1+2)/3
for 2nd column(2+4+4)/3
for 3rd column(3+7+5)/3,,,,,,,like this till the last column.

So I need to take the input from the .txt file, calculate the column average of each column and the average of each column must be displayed as output. I have done a bit of coding, but it is giving a run-time error as NullPointerException.I will forward my code as attachment, the reading of file, is done as string in java and then it must be converted to double values, also to read the comma separated input from a file I have used the split().

View Replies View Related

Reading Different Types Of Data From A Single Line Of A File?

Oct 12, 2014

I have to read data from a text file and print it in a new text file. An example of one line is like this:
Johnson 85 98 75 89 82

I then have to take the average of all the numbers and assign a "grade" to the numbers for each line of the text file and make a new file so it looks like this for 10 lines:

Name 1 2 3 4 5 Average Grade

Johnson 85 98 75 89 82 85.80 B

My problem is extracting the data from the file so I can use it.

View Replies View Related

Reading Data From Socket / Responses Of Python Server

Nov 3, 2014

I'm having a lot of problems reading data from a socket. I'm trying to read the responses of a python server. I've a

BufferedReader inputStream = new BufferedReader( new InputStreamReader(socket.getInputStream()));

And then:

char[] messageChunk=new char[32768]; //32768
List<Byte> messageBytesList = new ArrayList<Byte>();
while (inputStream.ready()) {
inputStream.read(messageChunk, 0, 32768);
for(int k=0;k<32768;k++){
messageBytesList.add((byte)messageChunk[k]);
}
}

inside a thread. Then I convert the list of bytes to a byte array using:

Byte[] messageBytes = messageBytesList.toArray(new Byte[messageBytesList.size()]);
byte[] message = ArrayUtils.toPrimitive(messageBytes);

The problem is that I often receive ArrayOutOfBound errors when I try to parse the byte array. I think that I'm reading from the socket in a wrong way..

View Replies View Related

Producing Image By Reading From A Data File Filled With Digits

Nov 16, 2014

I'm a complete beginner in Java programming and I'm interested to learn more about its concepts.

Recently, I've been given an exercise which instructs me to display two versions of a picture. The picture to be displayed is provided in the form of a data file of 40,000 digits that are arranged in rows (although there is no marker between rows) and it starts from the top of the picture. So the first digit represents the top left corner of the picture and the last is the bottom right.

Basically, what the exercise wants me to construct a program that plots a dot in one of two colours for each digit. If the digit is in the range 0 to 3 the output should be one colour and for digits in the range 4 to 9 the dot should be in the other colour.

I understand I have to use arrays and also loops to perform this. I'm familiar with the fillEllipse, drawEllipse, drawRectangle and fillRectangle but this exercise is nothing I've attempted before.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved