Pantry Class NullPointException Error

Nov 13, 2014

The program runs a NullPointException Error when I run the MixedFruit method.How do I fix that?

import java.util.Scanner ;
public class Exercise1
{
public static void main ( String[] args )
{
Scanner scan = new Scanner (System.in) ;
String inChars;

Jam goose = new Jam( "Gooseberry", "7/4/86", 12 );
Jam apple = new Jam( "Crab Apple", "9/30/99", 8 );
Jam rhub = new Jam( "Rhubarb", "10/31/99", 16 );

[code]....

View Replies


ADVERTISEMENT

NullPointException - Creating Pairs From Arrays

Oct 9, 2014

So in my java class we are suppose to ask for how many names are going to be entered, create an array of that length, and then store that many inputted names. We then take those names, alphabetize them, and create a set of pairs. For example, it might look like this:

How many people are there? 4
Please enter the names of those people:
Dana
Bob
Alice
Charlie

There are 6 possible pairings. They are:
Alice & Bob
Alice & Charlie
Alice & Dana
Bob & Charlie
Bob & Dana
Charlie & Dana

We are also suppose to account for less than two names (both 1 and 0 as well as negatives).

I keep getting a null point exception error and I can't figure out why. Even debugging in Eclipse doesn't give any pointers except that it is originating in line 76.

import java.util.Scanner;
import java.util.Arrays;
class partners
{
public static int numNames;
public static int numPairs;

[Code] .....

View Replies View Related

Program That Imitates A Pantry That Has 3 Jam Jars?

Oct 29, 2014

I created a program that imitates a pantry that has 3 jam jars. For the inputs of the user, I must create a jar using the class I have created for the jars (NAMED Jar). The only problem is that, after it asks for the first input, it skips the name of the second and third jar and inputs nothing for them. This is what it looks like:

What is the name of the 1st jar?
Blueberry
How much jam is there left in the jar?
500
What is the name of the 2nd jar?
How much jam is there left in the jar?
500
What is the name of the 3rd jar?
How much jam is there left in the jar?
500
The name is: Blueberry
The size is: 500.0
The name is:
The size is: 500.0
The name is:
The size is: 500.0

It does not ask for the second and third jar name when my code clearly tells the program to do that.

import java.util.Scanner;
class Pantry
{

[Code].....

View Replies View Related

Methods From Original Class Receiving Error When In Test Class

Jul 5, 2014

I am working on a program that simulates a bug moving along a horizontal line, My code works correctly when I test it in it's own class but when I tried testing my constructor and methods in a test class I received an error saying, "package stinkBug does not exist" on lines with my methods. However, stinkbug is not a package.

Java Code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

[code]....

View Replies View Related

Error Passing Value Of A Variable From One Class To Main Method Of Another Class

Jan 8, 2014

I've 3 classes.

1. Circle
2. GetInputFromUser
3. testCircle

package ABC;
public class Circle {
private double radius;
public double getRadius() {
return radius;

[Code] .....

In the testCircle class, in the line: getRadius = ui1.GetInput();

It's showing the error: The method GetInput(float) in the type GetInputFromUser is not applicable for the arguments ()

And when I do: getRadius = ui1.GetInput(rad);

It's showing the error: rad cannot be resolved

View Replies View Related

ERROR When Try To Implement A Class

Dec 6, 2014

I'm writing a simple queue program using a netbeans as a GUI program I've used netbeans GUI editor to create the GUI my main problem was I've written the queuing code to a button function it works but it runs only once and the queue becomes empty on the second run. So I implemented a class which will create the queue outside the button click event but when I do that I get a Symbol not found: method error . The place where I get the error:

addStd1.setText("Add Student");
addStd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addStd1ActionPerformed(evt);
}

My button function with the class:

class stdQueCls{
Queue stdQue;
public stdQueCls(){
stdQue = new LinkedList();
}
private void addStd1ActionPerformed(java.awt.event.ActionEvent evt) {

[code]....

View Replies View Related

No Class Def Found Error

Jan 25, 2014

The code below keeps giving me errors at runtime.

import java.util.*;
import javax.mail.*;
public class SendSmtp
{
public static void main(String [] args)
{
Properties properties = new Properties();
properties.setProperty("mail.smtp.host", "localhost");
Session mailSession = Session.getDefaultInstance(properties, null);
}
}

My intention is to send email locally on a Dovecot SMTP server using Postfix. I compile it with the command:

javac SendSmtp.java -cp /usr/share/java/geronimo-javamail-1.4-spec.jar

and run it with the command:

java SendSmtp

but I keep getting the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Session
at SendEmail3.main(SendEmail3.java:15)
Caused by: java.lang.ClassNotFoundException: javax.mail.Session
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more

View Replies View Related

Constructor Error When Extending A Class?

Oct 21, 2014

I am writing a program that should take a url and scan the page for any links. It is in the beginning stages, but I ran into an error when I tried to extend a class. There's a lot going on in this code, but the error is caused by the constructor.

Error message at compile time:

"constructor Page in class Page cannot be applied to given types;
{//Constructor
^
required: String
found: no arguments
reason: actual and formal argument lists differ in length".

Here's the code(first my class, then the class I extended)

public class SearchEngine extends Page {
public static Color customGreen = new Color(69, 194, 33);
public static Color customYellow = new Color(232, 166, 12);
public static Color customBlue = new Color(25,97,255);
public static Color customYellowComp = new Color(178,125,0);

[code]...

View Replies View Related

Error - Creating Instance Of Inner Class

Mar 22, 2014

Java Code:

package Threads;
// THIS PROGRAM WILL HAVE TWO THREADS i.e. "main" AND ANOTHER THREAD (SYSTEM WILL NAME IT "Thread-0"
//THE STORY IS THAT WE WILL START Thread-0 FROM main AND LET IT EXECUTE.
//main WILL WAIT AND LET IT EXECUTE FOR 5 MINUTES.
//IF IT FINISHES ITS EXECUTION BEFORE 5 MINUTES, WELL AND GOOD;
//BUT IF IT DOESN'T, WE WILL INTERRUPT IT.
//AFTER INTERRUPTION, WE WILL DECIDE TO WAIT INDEFINITELY.

public class SimpleThreadsCopy {
public static void threadMessage(String s){
String sThreadName= Thread.currentThread().getName();
System.out.format("%s: %s%n", sThreadName, s);

[Code] ....

The statement against which I have written many *'s gives the following error.

No enclosing instance of type SimpleThreadsCopy is accessible. Must qualify the allocation with an enclosing instance of type SimpleThreadsCopy (e.g. x.new A() where x is an instance of SimpleThreadsCopy).

Now that a similar "error-free" code is given here, what's wrong with this piece of code and what should I do about it?

Trying to understand the error statement, I replaced the erroneous statement with

Java Code : Thread t= new Thread(new SimpleThreadsCopy().new MessageLoop()); mh_sh_highlight_all('java');

And the error got fixed. From that I understand that the inner class is just kinda a nonstatic member of the outer class and it will be accessed by the objects of the outer class only.

But then why doesn't the code in the tutorial give an error?

View Replies View Related

Error - ArrayList Has Private Class

Jan 30, 2015

Java Code:

import java.util.Scanner;
import java.util.ArrayList;
public class Problem1
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();

[Code] ....

There is an error and says that my ArrayList has private access. I can't figure out how to fix it.

The code runs but when I enter "Quit", the program just stops. The arraylist isn't printed out?

View Replies View Related

Creating Object Of Inner Class - Getting Error

Aug 23, 2014

package home;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Box{
int x=70;
int y=70;

[Code] ....

L a = new L(); causing the error. It will be great to know why it is showing error.

View Replies View Related

Error Could Not Find Or Run Main Class

Jan 7, 2014

I made a breakout like game that runs as a applet and now i wanted to make it run in a jframe so i wrote this

Java Code:

import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class BrickBuster{
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JApplet BrickBuster = new JApplet();
frame.add(BrickBuster);
BrickBuster.init();
}
} mh_sh_highlight_all('java');

It compiles fine but whenever i try running it with the java command it says it couldnt find or load main class. also i have it save in a folder called BrickBuster so i called java BrickBusterBrickBuster.class

View Replies View Related

Super Class - Getting Error Identifier Expected

Aug 9, 2014

I created a superclass Ships and under that a class CivilShips. Under that HumanBulkFreighter.

I declared variables in Ships and CivilShips and wanted to have them set in HBF to a specific value. When I know try to compile them I get the following:

HumanBulkFreighter.java:2: error: <identifier> expected
cargo=1500;
^
HumanBulkFreighter.java:3: error: <identifier> expected
size=200;

[Code] ....

View Replies View Related

Getting Error - Class Interface Or Enum Expected

Aug 7, 2014

import java.io.*;
class addition {
public static void main(String[] args) {
int num1,num2,sum;
try {
DataInputStream x=new DatainputStream(system.in);

[Code] ,,,,,

View Replies View Related

Passing Variable From Class A To B To Do Calculation But Getting Error?

Mar 23, 2015

I'm getting this error, I definitely know that is my error trying to pass method/variable because when I commented received part of my code it ran and worked.

I get this error

at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Here are my 2 classes

Java Code:

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code] .....

View Replies View Related

Could Not Find Or Load Main Class Error

Sep 13, 2014

I have a problem that happens randomly where i try to compile and it just comes up with error

"Error: Could not find or load main class com.productiontrackingscreens.rexam.EmployeeAddressList"

This is a program that worked fine until i started it today. Seems a bug with eclipse.

View Replies View Related

No Compilation Error - No Class File Produced

Dec 24, 2014

I've a .java file that won't compile, but produces no errors (in cmd prompt).

I think its the import of java.util.ArrayList thats causing the problem (because it can compile a different file in the same source folder) - so i'm assuming its the classpath that is wrong. which is fine. i love fighting with classpaths.

But why isn't it providing me with an error. the compiler usually goes bat-sh.. crazy if the -cp is incorrect!

Its because I'm switching between command prompt and a text editor and it hadn't saved the file for some reason, and still won't am getting rid of this editor!!

View Replies View Related

Error - Could Not Find Or Load Main Class

Sep 30, 2014

I'm trying to run a java program from cmd. I'm using Windows 8, java version "1.8_0_20". I've got two classes, the main class called Middleware and a secondary class, called WorkerThread, of which the main class is using functions. I've successfully compiled both .java files with javac, and created the .class file. So all files are in the same folder. However, when I attempt to run the main class with java Middleware, I get the error message: "Error: Could not find or load main class". Here's the main class:

package middleware;
import java.net.*;
import java.util.concurrent.*;
public class Middleware {
//Number of threads serving clients.
private static int nr_threads = 5;
private static int portNr = 6789;
private static ServerSocket welcomeSocket;
private static ExecutorService executor;

[code]....

My code compiles and runs fine in eclipse but on the console, I'm having troubles.

View Replies View Related

Servlets :: Java Class - Session Variable Error

Dec 14, 2014

My dynamic web project has a java class that captures a session variable with the following code.

HttpSession LoginSession = request.getSession();
String VAR = LoginSession.getAttribute("myVar").toString(); //This is the row 127

If i test the app in local (Mac + Java 1.8 + Tomcat 8) all works. In my remote cloud server (Ubuntu 14.10 + Java 1.8 + Tomcat 8) all works, except this class, that has this code. I copy the complete error here. Note that the row 127 of the error message is the second row of the previous code; and, if i comment this row with // and assign a fix variable all works. So, the problem is that 127^ row.

14-Dec-2014 08:15:23.923 SEVERE [http-nio-8080-exec-14] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [srvNavigation.SrvPT] in context with path [/myapp] threw exception
java.lang.NullPointerException
at srvNavigation.SrvPT.doGet(SrvPT.java:127)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

[Code] ....

How can i solve the problem?

View Replies View Related

Stuck On Error - Could Not Find Or Load Main Class

Sep 2, 2014

I'm getting an error trying to run a welcome app from a book. I've looked at the FAQs and can't seem to solve the issue. I'm guessing my path and/or classpath are not right. Here's my path environment variable.

C:jdk1.8.0_20in;C:ProgramDataOracleJavajavapath;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program Files (x86)InteliCLS Client;C:Program FilesInteliCLS Client;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;%SYSTEMROOT%System32WindowsPowerSh

[Code] ....

Here's my output.

09/01/2014 10:23 PM 634 Welcome.class
09/01/2014 10:21 PM 422 Welcome.java
14 File(s) 126,243,703 bytes
9 Dir(s) 53,942,079,488 bytes free

[Code] .....

It looks like the version command gives me what it should, so it appears I've got java setup right, but I"m stuck on the error I'm getting :

C:jdk1.8.0_20>javac -version
javac 1.8.0_20
C:jdk1.8.0_20>

View Replies View Related

Error - Could Not Find Or Load Main Class GameTester

Oct 29, 2014

I was trying to write my own version of the game SimpleDotCom from Head First Java. I have two files:

Game.java:
package project_01;
public class Game{
byte hitCount = 0;
String result = "miss";
int counter = 0;
String checkGuess(int[] location,int userGuess){

[Code] .....

The two files are in the same directory, "project_01" and the CLASSPATH environment variable is set to ".;".
The game compiled but when I tried launching it with "java GameTester" it returned the error : Could not find or load main class GameTester. I know my game is horrible and probably extremely buggy but I'll fix all the bugs, etc. later, right now I just need to get it to run.

View Replies View Related

Error / Could Not Find Or Load Main Class HelloWorld

Jan 8, 2015

My problem is that I can compile a java HelloWorld program using javac HelloWorld.java but I cannot run the program using java HelloWorld. I didn't create the code it was developed by a professional programmer. My assignment is to compile and run, so that I see the output.

View Replies View Related

Error Constructor Class Cannot Be Applied To Give Types

Jun 12, 2014

I'm getting an error on line 51 and don't know what it means?

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/ 
package million;
import java.util.Scanner;
import java.util.ArrayList;

[code].....

View Replies View Related

JFrame Container - Unknown Class Error But Codes Looks Ok

Sep 2, 2014

I got stuck with the error "Unknown class" with the code that I copied from the book ...

import javax.swing.*;
class SwingDemo
{
// create a new JFrame container
JFrame MAIN_FRAME = new JFrame ("A Simple Swing Application");

// give the frame an initial size
MAIN_FRAME.setSize(275, 100);

// terminate the program when the user closes the application
MAIN_FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[code]...

The error comes from lines 21 and 27.

21 MAIN_FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27 MAIN_FRAME.add(FIELD_LABEL);

I have tried to rewrite from scratch and still gets the same error.

View Replies View Related

Populating ArrayList Using Scanner Class Logic Error

Sep 12, 2014

My code runs and populates an arraylist. However my break statement, while stopping the loop ends up being added to the arraylist. And I'm not sure how to fix this error.

public static void main(String args[]) throws Exception
{
// declaring variables
String input = "";
// creating array list
ArrayList<String> nameList = new ArrayList<String>();

[Code] ....

View Replies View Related

Servlets :: Unable To Resolve Class File Error

Sep 9, 2014

I am stuck with my application. I have jsp, servlet application with jasper report server. When I run the application through eclipse, everything works perfectly. But When I try to run it in Tomcat (without eclipse) it gives me the "Unable to resolve the class file " error. I tried all the solutions I got through the google, but still I am unable to come over it.

View Replies View Related







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