Histogram Not Reading Input File

May 1, 2015

The following program should read in a file on my desktop (I have the path set in Netbeans to that location) and produce a Histogram. Instead I am receiving this error.

Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at Histogram.main(Histogram.java:9)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Here is the code for the Histogram:

import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Histogram {
public static void main(String[] args) throws Exception {
int[][][] ch = new int[4][4][4];

[code]...

Why it's not reading the file?

View Replies


ADVERTISEMENT

Reading Input From Text File Not Working?

Apr 7, 2014

public void savePlants(ArrayList flowerPack) throws IOException
{
Scanner input = new Scanner(System.in);
String name;

[Code].....

When I open the saved file the information I need seems to be saved, but when I try to load and search it the data is not there. This is homework that was due about 2 days ago. I just want to get it right in my head for next time.

This is my text file: ¬í sr java.util.ArrayListxÒ™Ça I sizexp w sr FlowerNÏŠ¨r;¾  Z hasScentZ hasThornsL flowerColort Ljava/lang/String;xr Plant"ô²Ò0¢ I IDL Nameq ~ xp t Roset redsr Fungus“ +) Z isPoisonousL fungusColorq ~ xq ~  t toadstool t brownsr Weed #©éÇÙN Z isEdibleZ isMedicinalZ isPoisonousL weedColorq ~ xq ~  t dandylion t yellowsq ~  t tulip t pinkxq ~ q ~ q ~ 

View Replies View Related

Reading File Input - Display All Values

Apr 8, 2014

I've been trying to learn how to read in file input and have a question about this piece of code:

Java Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class readFile {

public static void main(String args[]) throws FileNotFoundException{
File file = new File("file.txt");
int sum[]=new int[5];
int i=0;

[Code] .....

"file.txt" holds the following information:

1
2
88
42
56
89

But my output looks like:

2
42
89

if I take out sum[i]=input.nextInt(); it will display all values in the file.

View Replies View Related

Reading Text File With Specific Input Format - Output Formatted Report

Apr 10, 2014

Here's a link to it : [URL] ....

The basic gist is it's "A program that reads in a text file that uses a specific input format and uses it to produce a formatted report for output."

Specifically :"For this lab you will write a Java program that produces a simple formatted report. The program will prompt the user to enter a file name. This file must contain information in a specific format (detailed below). Each "block" of the file contains information for one player in a competition -- the name of the player followed by a number of different scores that that player achieved. The program should find each player's average score, median score and best and worst scores and display them in a line on the final summary report. The program should also determine which player has the highest average score and which player has the lowest average score."

I get the following errors when I try and compile it:

Enter an input file name: Project11.txt
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException... -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at Project11.getMedian(Project11.java:68)
at Project11.main(Project11.java:27)

I get that the error(s) reside in lines 68 and 27, among problem other areas, but I'm not exactly sure how I can fix them.

Here's my code:

import java.io.*;
import java.util.*;
public class Project11 {
public static void main(String[] args) throws IOException{
Scanner in = new Scanner(System.in);
System.out.print("Enter an input file name: ");
String input = in.nextLine();

[Code] ....

View Replies View Related

Reading From Standard Input?

Jun 20, 2014

I have to write sorting algorithm for numbers given on standard input(console) with following requirements:

The application must remember the distinction between double and integer numbers. This must be evident in the sorted output. Double type numbers are written using a period (.) to separate the fraction from the whole part.

The problem is I don't know how to efficiently distinct whether something is an int or double on standard input, to save them into 2 different arrays.

Only idea I've come to so far is to read each number as String and check if it has '.' character, to figure out if it's double and than convert it into right type and add it to correct array.

Also thought that maybe this would be achieveable using Pattern but how to do that?

View Replies View Related

Reading Characters From User Input

Jan 11, 2012

I am using jdk 6 ... I came to know that how we can read strings from user input ... and how we can convert a string to int .. but i dont fount how to read a character by character from user ..

View Replies View Related

Reading Input From JTextField And Passing It To Another Class

Sep 7, 2014

I am having trouble taking user input and passing it to another class as a variable. If I assign the value explicitly (see line 59), it works just fine. What I want to do though, is assign the input from inputField to the variable inputVariable. I tried using:

inputVariable = inputField.getText();

This does not work. Regardless of what is typed into inputField, the output I get is just:

"The user typed "

package example;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

First Character Is Missing While Reading Input Stream

Jul 10, 2014

This is my code

// TODO Auto-generated method stub
File file=new File("D:/input.txt");
java.io.FileInputStream is=new java.io.FileInputStream(file);
int a=is.read();
try {
while((a=is.read())!=-1) {
System.out.print((char)a);

[Code] .....

My text in file is :my birthday Hello World

But in out i see only:y birthday Hello World

Why is first character is missing here?

View Replies View Related

Type Name And Get Histogram - Getting NullPointerException

Dec 10, 2014

I recently switched some of code around to restructure how some things were working but now when I run the program I am getting a NullPointerException in multiple areas. I suspect it may have something to do with a constructor. I am very new to "object" - ish based programming.

I figured I should give a little background on the program, this program is reading from a text file of names and decade numbers(for each name) and storing each line into an object array. From there, there are menus and based on the users decision they can type a name and get a histogram, compare names with histograms, ect. Below this main method, I have provided the area where I have gotten the null pointer exception.

Here is the main method for the Client "nameApp"

Also excuse the formatting and curly braces for now!

public class NameApp{

private static boolean validInput;
private static boolean done = false;
private static boolean validDecade;
private static boolean validName;

[Code] ....

And here is the method in the same Client that is getting the null pointer exception:

The pointer exception is on line 6 which is:

if (nameInput.equalsIgnoreCase(list[i].getName())){
private static int checkListArray(String nameInput, Name[] list){
int nameLocation = -1;
int listLength = list.length;

[Code] ....

View Replies View Related

Making A Rain Histogram

Mar 10, 2014

I prompted the user to enter inches of rainfall for seven days and stored them in an array. Now, I am trying to display a histogram of this data using a nested loop, but for each inch, I have to display a * like this:

Rainfall Histogram:
****
***
**
******
********
**********
**

The only way I know how to display a number of *s according to user input is by an if statement. I copied and pasted from a similar class assignment I did, so what I have so far is pretty messy and nonsensical:

static char DetermineRainfall(int inches)

System.out.println("Histogram");
//char inches;
for(inches = 0; inches < 7; inches++)
{
for(int j = 0; j < 1; j++)
{
if (rainamount > .9 && rainamount <= 1)
inches = '*';
return inches;
}
}

View Replies View Related

Reading User Input From JTextField As Int To Create Matrix

Sep 16, 2014

I am required to read user input to create two matrices which will eventually be added together. I am unsure as to how I can read the input from the user as an int and not a String. The input is from size 0-10 for both column and row size. Also, can you have a new button created in the actionPerformed method of a previous button?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Matrices implements ActionListener {
private JFrame win1, win2, win3, win4;

[Code]...

View Replies View Related

Reading Text File Into Object Array And Create Random Access File

Dec 9, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data. Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code]...

these continue for about 40-50 entries, they are not seperated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name seperated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

Reading Text File Into Object Array And Creating Random Access File?

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
//Constructor
public Product( String pName, double price, int quanity )

[code]....

and then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34

Mustard Seed,100,64

Coriander Powder,924,18

Turmeric,836,80

Cinnamon (Ground Korintje),951,10

Cinnamon (Ground) Xtra Hi Oil (2x),614,31

Cinnamon (Ground) High Oil (1X),682,19

these continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

JavaFX 2.0 :: Create Histogram - How To Label Bin Edges

Jan 30, 2015

How to create histogram in JavaFX ? Is it possible to do it using BarChart? how to label the bin edges (ticks)?

View Replies View Related

Reading Input With Scanner And Checking If User Entered Empty String?

Apr 7, 2015

The project is a program that allows the user to enter students and enter grades for each student. One of the requirements is that if there is already a grade stored for the student that it will display the previous grade. IF the user then enters a new grade the new grade will be stored. IF the user simply presses enter (enters an empty string) nothing is done. I have everything working except for the requirement of doing nothing if the user enters an empty string. If I just press enter at this point I get a NumberFormatException.

The below code is a method "setTestGrades" from the student class. This method iterates through each student object stored in an array list and then checks if there is a previous grade (Requirement# unset grades have to default to -1) before allowing the user to set a new grade.

public void setTestGrades(int testNumber) { //Sets the grade for the specified test number for each student in the arraylist.
testNumber -= 1;
Scanner input = new Scanner(System.in);
for (int i = 0; i < studentList.size(); i++) {
System.out.println("Please enter the grade for Test #" + (testNumber + 1) + " For Student " + studentList.get(i).getStudentName());

[code]....

View Replies View Related

Histogram That Allows To Visually Inspect Frequency Distribution Of A Set Of Values

Apr 4, 2014

Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values . The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered.

No input prompt

Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems)

Use hasNextInt() to terminate your input

Format as below (slightly different from the text example)

Z:dbraffittWeek10> javac Histogram.java

Z:dbraffittWeek10> java Histogram

10 10 10 10 10 20 20 20 20 20 20

20 25 35 45 55 65 75 85 95

ctrl/z

1 - 10 | *****

11 - 20 | *******

21 - 30 | *

31 - 40 | *

41 - 50 | *

51 - 60 | *

61 - 70 | *

71 - 80 | *

81 - 90 | *

91 - 100 | *

What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.

Java Code:

import java.util.Scanner;
public class Histogram
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
int [] nums = new int[101];

[Code] ....

View Replies View Related

Create Histogram That Allow To Visually Inspect Frequency Distribution Of A Set Of Values

Apr 4, 2014

Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values . The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered.

No input prompt
Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems)
Use hasNextInt() to terminate your input
Format as below (slightly different from the text example)
Z:dbraffittWeek10> javac Histogram.java
Z:dbraffittWeek10> java Histogram

[Code] ....

What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.

import java.util.Scanner;
public class Histogram {
public static void main (String[] args) {
Scanner scan = new Scanner (System.in);
int [] nums = new int[101];
 
[Code] .....

View Replies View Related

Create Program That Prompts Input And Creates File With That Input As Name

Jul 14, 2014

So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong.Code SO Far:

Java Code:

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
public class File_Read {
public File_Read() {//File_Read is the Interactive object

[code]....

So that it puts the Correct or Wrong into the file.

View Replies View Related

Reading CSV File

Jan 18, 2014

I have a CSV file with 16K entries of a data table. Does Java work well with CSV file? So I found this code. And it seems its quite easy to read in the data I need. Say for example if I wanted a loop to randomly pick the first field of a specific line in the CSV data table. How would i go about coding that??????

package cvs.test;
 
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
 
[code]....

The CSV looks like the above. and I basically would like to read in the Hand to get it to show in a text box and then randomly have the program ask me to correctly identify the True/False return for one of the SB/BB/UG/MP/CO/BN columns.

View Replies View Related

Reading A File Header / Hex?

Mar 3, 2013

how to get the first few hex symbols of a file in java, for example if i input a pdf into my coding i want my program to output, e.g "25 46 44 38" ....

I have been able to print out the hex of a whole file but not managed to set a maximum read limit so that my code only takes a certain amount of values ....

View Replies View Related

BNF Grammar And Reading From A Txt File?

Mar 21, 2014

I am implementing a recursive descent parser that recognizes strings in the language below. The input should be from a file "input.txt" and output should be to the console.

The grammar:

A -> I = E | E
E -> T + E | T - E | T
T -> F * T | F / T | F
F -> P ^ F | P
P -> I | L | UI | UL | (A)
U -> + | - | !
I -> C | CI
C -> a | b | ... | y | z
L -> D | DL
D -> 0 | 1 | ... | 8 | 9

An example session might look like this:

String read from file: a=a+b-c*d

The string "a=a+b-c*d" is in the language.

String read from file: a=a**b++c

The string "a=a**b++c" is not in the language.

Java Code: /**

* The Grammar
* A -> I = E | E
*E -> T + E | T - E | T
*T -> F * T | F / T | F
*F -> P ^ F | P
*P -> I | L | UI | UL | (A)
*U -> + | - | !

[code]....

My current output looks like this:

Java Code: The string read from file: a=a+b-c*d

The string "" is not in the language. mh_sh_highlight_all('java');

So it seems to be reading the input file correctly. My error seems to be on this part

Java Code: s = args.length == 1 ? args[0] : ""; mh_sh_highlight_all('java');

When I put the string in that line such as: s = args.length == 1 ? args[0] : "a=a+b-c*d";

My output is:

Java Code: The string read from file: a=a+b-c*d

The string "a=a+b-c*d" is in the language. mh_sh_highlight_all('java');

How can I go about it reading the string from the input file though?

Also, I am not too sure my boolean functions for P, I and, L are correct. Mainly when two terms are together (UI, UL, CI, DL).

View Replies View Related

Reading Content From FTP File?

Jan 27, 2013

I am trying to read a content of file downloaded from ftp and return it as a String. This is what I use:

Java Code:

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.net.ftp.FTPClient;
public class Test {
public static void main(String [] args) throws IOException{
FTPClient ftp = new FTPClient();

[code]....

The code does not work, although all the links are correct.

View Replies View Related

Reading From A File - While Loop

Oct 22, 2014

I have to read from a file that is formatted like that :

name
status
friend
END
name
status
friend
END
.. etc

could be more than one line of friends, which where I have my problem. I can't get it to check if after the friend name the word "END"

I have tried to write a while loop inside the main while loop but it didn't work, and now I have tried to check that in a separate function which it also failed, thats my two while loops

BufferedReader br = null;
FileReader fr = null;
int getLine = 0;
try {
String line;
fr = new FileReader(fileName);
br = new BufferedReader(fr);

[Code] .....

Most of the time I got nullPointerException or missed up order for printing the file !!

View Replies View Related

File Reading / Writing

Sep 9, 2014

I've looked at multiple sources and everyone is saying different stuff. Which one should I be using? FileWriter/FileReader, other people was saying PrintWriter, and one even said : "Formatter" which is the one I'm doubting mostly. My purposes for writing files is for like saving maps, saving high scores, etc.

View Replies View Related

Not Reading Entire File

Mar 29, 2014

I'm new to Java and have not been able to figure this out. I'm reading a text file that contains this:

110001 commercial 500000.00 101
110223 residential 100000.00 101
110020 commercial 1000000.00 107
110333 land 30000.00 105
110442 farm 200000.00 106
110421 land 40000.00 107
112352 residential 250000.00 110

The output goes to a text file and should look like this:

COMMERICAL

FARM
LAND
RESIDENTIAL

101 600000.00
105 30000.00
106 200000.00
107 1040000.00
110 250000.00

I'm creating the output file, but it only contains the categories and not the details below them. Cant seem to figure out why.

Java Code:

package propertylistings;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

[Code] ....

View Replies View Related

Reading From A Txt File Using A Loop

Oct 6, 2014

I am trying to read from a text file that has that contains a list of stock tickers and pairs letting the user choose a ticker and provide analysis of stock. Given a ticker from the user provide

1) the max price, the min price and the avg price of the stock from all lines in the file.
2)Additionally the user should be able to find the stock with the highes price as well as the lowest price in the list.
3)lastly the user should be able to specify a different filename for the stock file.

Im trying to do part 1 and I am having trouble trying to read the whole text file and outputting the stock price with the max,min and avg. Am I heading towards the right track at least? Keep in mind I have just attempted trying to read the text file I have and not tried to find the max or min or avg Right now my code is crashing when I enter the stock ticker that is my primary concern.

package hw01b;
import java.util.Scanner;
import java.io.*;
public class Hw01b
{
static Scanner in = new Scanner(System.in);
static Scanner console = new Scanner(System.in);

[Code] .....

View Replies View Related







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