Created Tree Lemur Object - Returning Null Consistently From Methods

May 24, 2015

The question pretty much says it all, but I tasked myself with creating a program about lemurs. There are multiple class files in this program. In the below code snippet, I have my TreeLemur.class which extends to the Lemur.class which extends to the Mammal.class. However, when I create a Tree Lemur object in the main program, it is returning null consistently from certain methods. What am I doing wrong here?

TreeLemur.class :

public class TreeLemur extends Lemur {
private String groupSize;
private String diet;
private String fur;
public void setGroupSize() {
groupSize = "
Group Size: Large";
}

[Code]...

As of yet, I'm just trying to get Tree Lemur working properly to continue with creating the other if-branches within the main program.

View Replies


ADVERTISEMENT

Black Jack Game - Initiated Object Returning Null

Nov 7, 2014

I've been assigned to create a Black Jack game with a gui. In this game I've created a seperate Player and Dealer class, and both initiated them, however when I try to call a Player object in a certain way I get a null pointer reference. (It should be noted that the Player object is an array)

public void runGame(){
while(running){
while(dealer.getPoints() <=19){
int count=0;

[Code] .....

And this is how I've initilized the Player class in the constructor

Player[] players = new Player[numberofplayers];
for(int i=0; i<numberofplayers; i++){
players[i] = new Player(i);
players[i].setDeck(d1);
gui.add(players[i].getPanel());
}

What I don't get is if I change players[i] to dealer, it works fine.

View Replies View Related

Why Is Method Returning Null

Sep 25, 2014

I am working on a project which manages an airport's airplanes and flights based on user input. The method printFlights() - lines 133-134 - is returning null and I can't figure out why. The method is supposed to print information about each flight. The logic is identical to the printPlanes() method which is working successfully.

View Replies View Related

GetNextMailItem Keeps Returning Null

Jun 16, 2014

When I try to getNextMailItem,it keeps returning null.Why?

public class MailServer
{
// Storage for the arbitrary number of mail items to be stored
// on the server.
private HashMap<String,ArrayList<MailItem>> mailbox;
/**
* Construct a mail server.
*/
public MailServer()

[Code] .....

View Replies View Related

FileReader - Returning Null

Jan 12, 2014

I'm following a tutorial and I can't work out why the version that I have written is returning null when reading the text file...?

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class AppReadFileFileReader {
public static void main(String[] args) {
File file = new File("test.txt");
BufferedReader br = null;

[Code] ...

I can't see any difference in the code though, and the files being found in order for the null to appear... :?

the text file is within the Java project, and just has three lines :

line one
line two
line three

That's all it say..... But all my program returns is the work 'null'

View Replies View Related

Method Is Not Returning Array - Null Error

May 18, 2015

I am trying to return an array and I keep getting a null error. The below class sets the material numbers into an array and should return that array if called :

public class Jobs {
private int[] materialsNumber;
//change to parts and create another class that gets the materials for the parts
 public int[] job1() {
materialsNumber[0] = 11960120;

[Code] ....

I later try to call the method. The program executes but stops after I println "test in loop"

public class PurchaseOrdersToParts {
 private Jobs job = new Jobs();
 int[] getPartsForPurchaseOrder(BigDecimal purchaseOrder) {
 System.out.println("inside getparts");
 BigDecimal testNum = new BigDecimal(123.0);
 
[Code] ....

This is the method that is calling the method in the GenerateOrdersToParts class

private PurchaseOrdersToParts purchaseOrdersToParts = new PurchaseOrdersToParts();
 @Inject
PoRepository poRepository;
public GenerateShopJobTickets() {
 
[Code] .....

View Replies View Related

Binary Search Tree Dictionary Returning All Words Misspelled

Feb 12, 2015

The assignment is to be able to read two files, a dictionary file, and a file you want to spell check. I've also attached the test files too.

When reading small files where there is only one word per line it works fine. But when I try to test a paragraph it returns all the words as misspelt.

Here are all of the classes that were given for this assignment. I've made some modifications to try to get them to work properly.

BinarySearchTree.java

// ADT binary search tree.
// Assumption: A tree contains at most one item with a given search key at any time.

public class BinarySearchTree extends BinaryTreeBasis {
// inherits isEmpty(), makeEmpty(), getRootItem(), and
// the use of the constructors from BinaryTreeBasis

[Code] .....

As you can see I read in the dictionary file and the spellcheck file, construct a new BST, and then insert each word from the dictionary into the tree.

Then I make an empty arraylist for the misspelt words. While searching through the spellcheck file, if it finds any incorrect words, it adds them to the list then returns the list after it's done reading through the file.

But for some reason it prints out every single word in the test file and I can't figure out why.

Attached File(s)

dictionary_large.txt (1.83MB)
dictionary_small.txt (225bytes)
test_large.txt (553bytes)
test_small.txt (52bytes)

View Replies View Related

Linked List Sort - ToString Returning Null

May 22, 2014

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.lang.Comparable;
import java.util.*;
import java.lang.*;
public class MyLinkedListSort {

[Code] .....

Output is :

name is nulland salary is0
name is nulland salary is0
name is nulland salary is0
name is nulland salary is0

Expected output :

Name is Crish Salary: 2000
Name is Tom Salary: 2400
Name is Ram Salary: 3000
Name is John Salary: 6000

Where i going wrong

View Replies View Related

Returning Values With Methods?

Sep 24, 2014

The code is below. The program runs a series of calculations based on data input by the user. My problem is that for the most important thing I'm looking for, total kg CO2 emissions, I continually get an answer of 0.0. What I need is a sum of the individual total emissions as calculated in each method, i.e. the values which are printed with the following: System.out.println(trans); System.out.println(elec); and System.out.println(food);

The total should be something like 25040 or whatever, depending on the value of the inputs provided by the user, but I'm constantly getting a total of 0.0., which is obviously false. Could have something to do with the way I've initialized my variables, or something to do with the limitations of returning values from methods.

import java.util.Scanner;
 public class CarbonCalc {
 public static void main(String[] args) {
double trans = 0;
double elec = 0;
double food = 0; 
giveIntro();
 determineTransportationEmission(null);

[code]....

View Replies View Related

Returning Data Using Set / Get Methods

Jan 23, 2015

I'm writing a program that involves the use of set/get methods. I will submit a sample code of my issue. The format appears to be alright however the program is not returning any data. This is the same format as my actual code. Why this might be happening?

Java Code:

public static void main(String [] args) {
SecondClass object = new SecondClass();
object.setName("Name");
object.getName();
} mh_sh_highlight_all('java');

Java Code:

public class SecondClass {
private String name;
public SecondClass(){
name = " ";
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
} mh_sh_highlight_all('java');

View Replies View Related

Binary Expression Tree Print - Null Pointer Error

Aug 3, 2014

I am trying to build an expression tree program . I try to print it then I have java.nullpointer exception . Is it error in my code or what ?

I have 2 classes

one is BSTreeNode which is the nodes for the tree . It has

public class ExpressionTree {
public BSTreeNode root;
public BSTreeNode curr = root;
ExpressionTree() {
root = new BSTreeNode(null, null, null, null);
curr = root;

[Code] ....

My BSTreeNode

public class BSTreeNode {
BSTreeNode parent;
Object element; // Binary search tree element
BSTreeNode left; // Reference to the left child
BSTreeNode right; // Reference to the right child
// Constructor
BSTreeNode (Object elem)
[Code] ....

The error i am getting is

Exception in thread "main" java.lang.NullPointerException
at binaryexpressiontree.ExpressionTree.insert(ExpressionTree.java:38)
at binaryexpressiontree.test.main(test.java:22)

Java Result: 1

After implementing exception handler what i am getting is

java.lang.NullPointerException
root 1 *
root 2 1 error error error//these error print because of my catch clause

View Replies View Related

Returning In Methods With Try Catch Block

Feb 18, 2015

Regarding return statements within methods. So I have a method containing try and catch block (as required) and much like when you have an if else statement... I noted you have to return an object for both the try and catch blocks. Now in my case my method should return a List object.

The way I have tried to overcome this:

- I've initialised a List object to null as an attribute of the class I'm working in.
- Therefore in the catch block would just simply return the null List object, where as the try block would return the non-empty List (which is what I want).
- I then just test to see if the List != null, when the method is invoked... and that is that.

However the method always seems to return null (when it shouldn't).

View Replies View Related

Returning Values Between Two Classes With Methods

Feb 4, 2015

I have a very standard Lab assignment. It's probably been seen a lot. I wrote the first part not realizing I had to write a second class to do use the methods. I'm not sure how to change my program to call methods from my second class instead of doing all my calculations with user input in my first class.

Here's the first class' code:

package tickets;
//Imports classes used for "Ticket" application.
import java.util.*;
import java.text.DecimalFormat;
public class Tickets {
 
[Code] ......

The code is obviously incomplete. I have not tried to compile, nor would I expect it to compile right. I'm not sure how to move my calculations from the first class shown above into my second class and use them as methods.

View Replies View Related

Overload Methods Returning Average?

Oct 8, 2014

I am stuck on this part of my assignment. When the answer prints out at the end, the calculation of average is incorrect. This is what the assignment wants:

Write two overloaded methods that return the average of an array with the following headers:

public static int average(int[] array)
public static double average(double[] array)

Write a test program that prompts the user to enter ten double values, invokes this method and displays the average value.

public class Week7Arrays2 {
public static int average(int[] array) {
int sum = 0;
int average = 0;
for (int i = 0; i < array.length; i++) {
sum = sum + array[i];

[code]....

View Replies View Related

JSP :: Can Use Object Which Is Created In Servlet?

Dec 7, 2005

How should I access object, which I have created in servlet? Servlet handles the requests(controller) and forwards to requested jsp page.Some of the jsp pages need EJB objects. When i create an ejb object in servlet and then forward the request to jsp, how can i access the object in jsp ? This should be MVC - based application, like JSP-Servlet-EJB.

View Replies View Related

How To Reference Object Created In One Class From Another

Oct 30, 2014

I have started working on a little project in my free time. It is just a simple text rpg that runs in a counsel window. I have 5 files each file contains 1 class.

public class SomnusCharacter {
private String gender = "";
private int age = 0;
private String race = "";
private int level = 0;
private int xp = 0;

[Code] ....

The chain of events right now is:

1. MainMenu is run
2. If user inputs n CreateCharactor is run
3. User inputs name, age, ect in SomnusCharacter object made in CreateCharacter
4. Intro (just rough demo for testing purposes) is run
5. If user inputs m Menu is run
6. Menu calls and prints out all the information from the object made in CreateCharacter

Step 6 is where I am having my problems. How can I reference (lets say the SomnusCharacter object made is called player) player from my Menu class? I know that if I made a new character that it would just create another SomunsCharacter object with the default values again.

View Replies View Related

Object Created Inside Switch

Mar 2, 2014

I have create as short example which contains two classes Cat and Dog followed by a switch statement in the main method.

Class Cat

public class Cat {
private String name;
//Setter
public void setName(String pName)
{name = pName;}
//Getter
public String getName()
{return name;}
// Constructor
public Cat(String catName)
{name = catName;}

[code]....

My Issue is that after creating the objects within the switch statement, is there a way to return the objects back to the main method once created within the switch ?

View Replies View Related

Accessing Object Created In Another Class

Mar 10, 2014

I have a situation where I have 2 classes and an array of objects which are causing me trouble.

The object type is one I have created - it is made from a class which is neither of the 2 classes I previously mentioned.

The array is created and occupied in Class1 and the problem arises when I try to reference one of the element from Class2.

At first I forgot the the array would be local to Class1.main so I made the array a global variable using:

Java Code: public MyObjectType[] myArray; mh_sh_highlight_all('java');
Then I tried accessing an element (2) from Class2 using:

Java Code: Class1.myArray[2] mh_sh_highlight_all('java');
However I get errors saying that I can't access the static variable from a non-static context.

I understand a little bit about static and non-static objects/methods but don't know how to fix this. Do I need to include "static" in the array declaration?

View Replies View Related

Passing Object Created In One Method To Another?

Oct 29, 2014

I am working on an independent project it is a simple little text based rpg that will run in a counsel window. I have an object for Character that is creating during a CreateCharacter method. I want the play to be able to enter a character that will open up a menu that displays things like the name and health and stuff of the character from the object created in CreateCharacter, but because I have it in a different class I don't know how to reference the object made in CreateCharacter.

I have it in 6 files

Character --- Object with getters/setters for things like name, age, race, class, ect
MainMenu --- Displays title and promts for new game and quit
CreateCharacter --- Walks through and sets all values in Character
Stats --- Keeps the players stats (health, attack, ect) in an array
Intro --- Beginning demo thing (not really important for this question)
Menu --- Displays all current user stats (Having issues with this one)

Example I have this in Menu

System.out.println("Name: " + ????.getName());

View Replies View Related

Servlets :: When HTTP Session Object Created In Web Application

Jul 17, 2014

When does HTTP Session object is created in web application. Suppose I have a website. Home page of website is HTTP page which contains details of company and link to Login page.

Consider below mentioned user journey as scenario:

a. user arrives at home page of website
b. user click on Login page
c. user fill in login details on login page and click on Submit
d. user is successfully authenticated and authorized from back end
e. User specific page is shown
f. user click on logout link
g. user is successfully logged out from website
h. user is redirected to home page
i. user closes browser

In the above mentioned user journey,

a. at which step does HTTP session starts (means at which steps does HTTP Session object is created ? )
b. at which step does HTTP session ends ?

In case required, assume tech stack to be Java 7, Servlet 2.5, JSP, Tomcat 7, Apache web server (for static web contents).....

View Replies View Related

Returning Text From A String Object?

Feb 19, 2015

I run a bash command and save the output as a string object

String str1 = "" +getLastOutput();

str1 would look like this: abcd efgh lkmn xsds

In this string ( str1) i need to check three separate words are there.

If i have an if statement with str1.contains("xyz") && str1.contains("lkmn") &&str1.contains("zzzzzzzzzzzz")

How can i get the one that is not there returned to the screen? so i can use elsewhere?

View Replies View Related

Returning Object After Try-Catch Statements

May 5, 2014

So I'm pretty sure this is correct, as it follows most examples I can find online, but I keep getting an error that my return variable cannot be resolved. The error is on the return conn; statement. It says conn cannot be resolved. If I place it above within the try block it allows it but then I receive an error saying the method getDBConnection must return type Connection.

import java.sql.*;
public Connection getDBConnection() {
try {
Class.forName("org.sqlite.JDBC");
String path = "jdbc:sqlite::resource:project.db";

[Code] .....

I don't want to create this method. Basically I want to connect to the database in the main program, but I do want methods that can access the DB too. But however I place it, it doesn't let me touch any of the DB variables outside of the Try block.

View Replies View Related

Returning Object That Has Been Removed Using Remove Method

Nov 18, 2014

So i have used the "remove()" method in conjunction with an iterator to remove an object from a HashSet in my program, and part of my exercise requires me to return said object. What I can do to return an object that has been removed using "remove()" method?

View Replies View Related

EJB / EE :: Create Stateless Bean That Instead Of Returning A String Returns Object

Jul 31, 2014

I'm training myself with the EJB 3 technology. I would like to create a stateless bean that instead of returning a String, it returns an object. I tried in the same way I did with the first exercise, but I'm getting several errors.

View Replies View Related

What Is The Length Of A Null Array Object

Feb 21, 2014

I tried the following and it gives me null pointer exception. I just want to verify if what is the actual value of a length of an array?

Object [] obj = null;
System.out.println("length:" + obj.length);

View Replies View Related

Linked Binary Search Tree - Creating Node Object

Apr 5, 2015

I'm trying to use LinkedBinarySearchTree but a lot of the variables are protected in BinaryTreeNode. I am creating a BinaryTreeNode object but it still isn't allowing me to use them. The variables I am trying to use are element, left, and right.

import ch11.exceptions.*;
import ch10.LinkedBinaryTree;
import ch10.BinaryTreeNode;
/**
* LinkedBinarySearchTree implements the BinarySearchTreeADT interface with links.

*/
public class LinkedBinarySearchTree<T> extends LinkedBinaryTree<T>
implements BinarySearchTreeADT<T>

[Code] ....

View Replies View Related







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