Rainfall Programming - Exception In Main Thread

Sep 10, 2014

exception in thread main java.lang.nullpointerexception code 45 and code 116

the lines are highlighted and no the code tags did not show up when I uploaded the file.

I typed '[code]' below:
Java Code: /**
This program demostrates rainfall for a year
*/

[Code].....

View Replies


ADVERTISEMENT

Exception In Thread Main

Jan 11, 2014

I am new to java and still learning. I am trying to execute the code below which compiles successfully, but getting the following error:"Exception in thread "main" java.lang.NoSuchMethodError: main"

Code:

class Dog{
int size;
String name;
String breed;
void bark(){
System.out.println("woof woof");
}
}
class DogTestDrive{

[code]....

View Replies View Related

Exception In Main Thread - Class Introductions

Dec 26, 2014

import java.io.Console;
public class Introductions{
public static void main(String[] args){
Console console = System.console();
console.printf("Hello!My name is ---");
}
}

Output :-

Compiling Introductions.java.......
-----------OUTPUT-----------
Exception in thread "main" java.lang.NullPointerException
at Introductions.main(Introductions.java:5)
[Finished in 2.2s with exit code 1]

View Replies View Related

Eclipse IDE - 2 Classes And Exception In Thread Main

Aug 31, 2014

I use Eclipse IDE

public class Emp {
 private String name;
private String jobTitle;
 public void setName(String nameIn){
name=nameIn;

[Code] ....

<terminated> TestClass
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at TestClass.payOneEmp(TestClass.java:21)
at TestClass.main(TestClass.java:13)

View Replies View Related

Exception In Thread Main - Cannot Format Given Object

Apr 16, 2014

I am working on a program that will allow a user to input grades for a class of four students who have taken two tests. Based on the grades entered, the program will calculate the averages of the two tests for each student and display it along with their respected letter grades.

Now I can get the program to compile successfully, but after inputting the grades in, I get the error message saying that it cannot format given object as a number. I am using 4 arrays to execute this program and maybe that's why I'm having the trouble? I'm not sure because I am still fairly new at this stuff and can't sen to resolve it.

I was having problems for a while and then finally got excited when I got it to compile without any errors and now I'm getting an error inside my program. All I need to do is format the numbers of the grades into something like: 000, and each of the averages as 000.0. I understand how to do it because I have done it in another program I've done in the past. I just don't know how to fix this error that is coming up.

here is my code:

import java.util.Scanner;
import java.text.DecimalFormat;
public class TestAverage
{
/**
* A program that will store and process 2 test scores for a class of 4 students.
* The program will prompt for the test scores as shown above in the sample run.
* After all the data is entered,the program will display the score for test 1, test 2 .
* The average of the 2 tests and the letter grade for the class for each student in a tabular format.
*
*

[code]....

View Replies View Related

User Input 20 Char And Program Will Print Most Common - Exception In Thread Main

Dec 17, 2014

My program is user input 20 char and the program will print the most common. So I use another int arr which count the number appears in the original array. i know its not so Effective but I don't know why it run but it stop in the middle. I got this code :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
at Ex2.common(Ex2.java:39)
at Ex2.main(Ex2.java:23)

import java.util.Scanner;
class Ex2 {
public static void main(String[] arg) {
Scanner reader = new Scanner (System.in);
char[] arr=new char[20];
System.out.println("Please enter 20 chars:");
for (int i=0;i<20;i++)

[Code] ....

View Replies View Related

Swing/AWT/SWT :: What Is Event-dispatching Thread For GUIs And Why Use It Over Main Thread

Sep 20, 2014

I'm currently learning about Swing but I can't get my head round this piece of the code. Here is a simplified gui (not interested in the gui part but the execution)

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
new SwingDemo();
}

I get the above, create a new instance of SwingDemo in the main thread which starts up the gui through the constructor. However, then the tutorial says that I should avoid doing the above but do this instead:

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() { //why do this instead?
public void run(){
new SwingDemo();
}
});
}
}

Reading, it talks about an event-dispatching thread which has completely lost me... Why not just instantiate the object directly instead of creating another thread?

View Replies View Related

Average Rainfall Main Class Using Nested For Loops Input Validation

Feb 23, 2014

When input validation for the first months rainfall is non-negative, this results in correct average rainfall.

When input validation is used for the first months rainfall I'm prompted to input a positive number, which is 2.

When asked to input rainfall, in inches, for each month, I begin with input -3, I am again prompted to re-enter a positive, I enter 3. What happens is, whichever positive integer I input after I had entered a negative for the first months rainfall, the average would be off by the positive number inputted.

package averagerainfall;
import java.util.Scanner;
public class AverageRainfall
{
public static void main(String[] args)
{
int maxYears;
int totalMonths;

[Code] ....

View Replies View Related

Event Driven Programming / No Main Method

Jan 29, 2015

I'm reading a book titled 'Intro to Java Programming'. I understand all the Main Method stuff. I'm now reading a chapter that talks about event driven programming. I know how to do this in VBA and in C#, ut I can't figure out how this works in Java. Here's the sample code that I'm trying to run.

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

[code]....

I'm using Net Beans IDE. When I paste that code into the IDE, I get all kinds of errors. Also, since there is no Main, I don't know how this is supposed to run. Java needs a Main Method for everything, I think. Does the Main call some kind of class?

View Replies View Related

Program Store Input Of Rainfall For Each Month - Print Out Month With Least And Most Rainfall

May 1, 2014

I have written program for rainfall that will store and give total, average, least and most. The program stores the input of rainfall for each month. However at the end it suppose to print out the month with the least and most rainfall. I am getting this on the print for

The month with the most rainfall: [Ljava.lang.String;@79a7bd3b

and for

The month with the least rainfall: [D@7378aae2[Ljava.lang.String;@79a7bd3b

. What have i done wrong?

View Replies View Related

Thread And Passing Exception With Two Classes

Jan 23, 2014

I have two classes, where main class is simple with only main function in it. Another class extends Thread and there's couple of functions I want to execute from main class.

Problem: I try to get other.shut() to be run in main class catch() block, after I have stopped the other class's running thread (e.g. by ctrl+c).

I think I need to somehow "pass" the exception from other class to main class so it goes to the catch block?

Code for main class:

Java Code:

public class MainClass {
public static void main(String[] arguments) {
OtherClass other = new OtherClass();
try {
other.exec();
} catch (Exception e) {
other.shut();

[Code] .....

View Replies View Related

Splitting String Not Working - Exception In Thread

Jul 19, 2014

I am designing the game of Snake but it crashes after i added the checkScore() method.

package com.complex.snake;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;

[Code] .....

The error i get is : Exception in thread "Thread-3" java.lang.ArrayIndexOutOfBoundsException: 1

View Replies View Related

Baby Names Exception In Thread InputMismatchException

Feb 10, 2015

I'm working on an assignment for my java class and I am currently stuck with an error/exception,

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at BabyNames.search(BabyNames.java:45)
at BabyNames.main(BabyNames.java:20)

I input my name, which is able to get my name from the names.txt, however after that, it hits an exception and does not go further on.Also please use the names,

JIMMY
JIMMIE
JIMMU
JIMI
(All can be lowered case), because I am unable to upload the full file for it is very big.

import java.util.*;
import java.awt.*;
import java.io.*;

//Jimmy
//Programming Assignment #6: Baby Names
//This program is going to scan a file with data
//about names and their popularity starting from the 1890's
//and will display their popularity over the years in 10 intervals.

[code]...

View Replies View Related

Exception In Thread - Array Index Out Of Bounds

Mar 20, 2015

The following code generates an array out of bounds exception

int[] myArray1 = new int[5]; 
for(int j = 0; j < myArray1.length; j++)
{
myArray1[j] = 10;
System.out.println("myArray1["+j+"] : " + myArray1[j]);
}
for (int i : myArray1) {
System.out.println("Blah myArray1["+i+"] : " + myArray1[i]);
}

The exception

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at Tutorial2.main(Tutorial2.java:40)

View Replies View Related

Thread Java - Illegal State Monitor Exception

May 30, 2014

Class A{
Public static synchronized void main(String args[]){
Thread t= new thread();
t.start();
Sysout("hi");
t.wait(1000);
Sysout("hello");
}}

Illegal state monitor exception. Why?

View Replies View Related

Slot Machine - Exception In Thread InputMismatchException (runtime Error)

Nov 16, 2014

For this program, I have to run a slot machine. It runs until right before the do while loop and then I receive the error: Exception in thread "main" java.util.InputMismatch.Exception. Searching around, someone said it was a scanner error and adding a call keyboard.nextLine(); fixes the problem- however with that I receive the same error.

Code :
import java.util.Scanner;
import java.util.Random;
import java.io.*;
public class SlotMachineSimulation
{
public static void main(String[] args) throws IOException
{
int number;

[Code] .....

View Replies View Related

How To Change State Of Object - Main Method Exception Error

Jan 8, 2015

The error I get when I execute my java file.

Exception in thread "main" java.lang.NullPointerExceptionat DogTestDrive.main(DogTestDrive.java:19)

Here is the source

class Dog {
int size;
String name;
void bark () {
if (size < 60) {
System.out.println("Woof woof");

[code]....

Some background: I'm reading "Head first Java 2nd edition" and I'm going through the examples which is showing me how to change the state of an object. The original code looks like the code below, however the previous chapter went over creating array's of an object, so I created an array of the object "Dog" and wanted to re-write it this way. To my understanding, it should work but it's giving me that error when I execute it. The error itself isn't very clear, if I could get a line number pointed to, that would work.

class Dog {
int size;
String name;
void bark() {
if (size > 60) {
System.out.println(“Wooof! Wooof!”);
} else if (size > 14) {
System.out.println(“Ruff! Ruff!”);
} else {
System.out.println(“Yip! Yip!”);

[code]....

View Replies View Related

Passing 2 Sub Arrays Into Sorting Thread Then To A 3rd Thread Merge

Oct 17, 2014

im having an issue with the 3rd thread that are supposed to merge the two sorted sub arrays , i pass the 2 subarrays to my runnable function sortlist and they are renamed IntSortList 1 and 2 and th1.start() and th1.join() are called and it works fine, but then i have another runnable constructor that takes IntSortList 1 and 2 but it does take a runnable. below is the code in my main,

Runnable InSortlist1 = new sortList(data2p1);
Runnable InSortlist1 = new sortList(data2p1);
Thread th1 = new Thread (IntSortlist1);
Thread th2 = new Thread (IntSortlist2);
try
{
th1.start();
th1.join();

[code]....

View Replies View Related

Accessing A Variable Of A Thread From Another Thread

Jul 16, 2014

class A extends Thread
{
String str;

public void run( )
{
//random stuff
}
}

[Code]....

View Replies View Related

Calculating Rainfall Quarterly Per Year

Mar 30, 2015

//calculates rainfall quarterly per year
 
import java.util.Scanner;
 public class SophiaKeyProgram2 {
 public static void main(String[] args) {
// TODO Auto-generated method stub
 
int numQuarter; //number of quarters in a year
double rainfall=0; //the amount of rain

[Code] ....

View Replies View Related

Calculate Rainfall Quarterly Program

Mar 29, 2015

//calculates rainfall quarterly program
 
import java.util.Scanner;
 public class SophiaKeyProgram1 {
 public static void main(String[] args) {
// TODO Auto-generated method stub
int numQuarter; //number of quarters in a year
double rainfall=0; //the amount of rain

[Code] ....

I have everything but the min and max numbers.

View Replies View Related

Rainfall - Show Driest And Wettest Correctly

Feb 14, 2015

How can I get the driest and the Wettest to show correctly with the Wettest took out the driest comes out fine

import java.util.Scanner;
public class Java {
public static Scanner key = new Scanner(System.in);
public static void main(String[] args)
{
// TODO Auto-generated method stub
double [] rainfall = {4.6,5.4,5.7,5.2,4.2,2.7,2.3,3.6,3.9,4.7,5.1,5.6};
double Wettest = 0.0 ;
double driest = 0.0;

[Code] .....

View Replies View Related

A Program That Stores Total Rainfall For Each Of 12 Months

Apr 29, 2015

Write a program that stores the total rainfall for each of the 12 months into an array of doubles. The program should have methods that return the following:

The total rainfall for the year
The average monthly rainfall
The month with the most rain
The month with the least rain

And the code:

double rain[] = new double [12];
double sum;
double average;
double most;
double least;

[code]....

I'm having a problem with figuring out how to show which month is the least and most.

View Replies View Related

Rainfall Analysis For The Number Of Days According To User Input

Feb 24, 2015

I am assigned with a project that will as the user for the amount of days they would like data entered, then loop asking them for these numbers. once it reaches the entered amount of days it will display a menu for which the user can enter the number they want on the list and it will display the data. the menu has 6 items. Total, Average, Determine if its a Drought, Flood or normal rainfall, highest of data entered, lowest of data entered, and 6 is to quit the program.

So far i have total and average working properly. Still looking at how to display drought, flood, and normal.

Main problems, i cannot get highest and lowest to display correct data.

Also when entering 6, or an invalid menu choice, neither "goodbye" or "invalid choice, choose again" gets printed. Rather the loop for entering data continues.

import java.util.Scanner;
public class RainAnalysis {
/*
* Project 1 This program will analyze the rainfall for the number of days a user inputs.
*/
 
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int numOfDays = 0;
double rainfallAmount = 0.0;

[Code] ....

Here is a sample output to show what happens when i put in 6 after the menu is displayed.

also i noticed that it does not say the correct day when displaying the lowest and highest rainfall. this is because i put count, i did not know what else to put in order to get the correct day.

how many days do you want to monitor rainfall?5

Enter the rainfall for day 1.01
Enter the rainfall for day 2.1
Enter the rainfall for day 36
Enter the rainfall for day 43
Enter the rainfall for day 51

Rainfall Data Display Menu:
1 - Display total rainfall.
2 - Display rain average for the period.
3 - Display if drought, flood, or normal conditions.
4 - Display the day and amount of the highest rainfall.
5 - Display the day and amount of the lowest rainfall.
6 - Quit the program.

Enter your choice:
4
Day5 has the highest rainfall with 6.0 inches.

Rainfall Data Display Menu:
1 - Display total rainfall.
2 - Display rain average for the period.
3 - Display if drought, flood, or normal conditions.
4 - Display the day and amount of the highest rainfall.
5 - Display the day and amount of the lowest rainfall.
6 - Quit the program.

Enter your choice:
5
Day5 has the lowest rainfall with 0.1 inches.

Rainfall Data Display Menu:
1 - Display total rainfall.
2 - Display rain average for the period.
3 - Display if drought, flood, or normal conditions.
4 - Display the day and amount of the highest rainfall.
5 - Display the day and amount of the lowest rainfall.
6 - Quit the program.

Enter your choice:
6
Enter the rainfall for day 6

View Replies View Related

How To Access One Thread From Another Thread

Oct 8, 2014

How to access one thread from another thread?

View Replies View Related

Program To Store Total Rainfall For Each Of 12 Months Into Array Of Doubles

Oct 26, 2014

"Create a project called RainFall and a class nameD RainFall. Write a program that stores the total rainfall for each of 12 months into an array of doubles. The program should display total rainfall for the year, the average monthly rainfall, the month with the most rain and the month with the least rain. When outputting the month with the most and least rain, output the name of the month. This is what I have so far.

Scanner keyboard = new Scanner(System.in);
double averageMonthly;
double mostRain;
double leastRain;
int months;
double monthlyRain = 0;
double totalRain = 0;

[Code] ....

View Replies View Related







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