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
ADVERTISEMENT
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
Mar 19, 2015
I'm trying to call the grade.processFile method from the main method but I'm getting this Error below. I'll post my code which includes the main method and the class underneath the error message:
Exception in thread "main" java.lang.NullPointerException
at java.io.FileInputStream.<init>(FileInputStream.jav a:130)
at java.util.Scanner.<init>(Scanner.java:611)
at MyGrades.processFile(MyGrades.java:49)
at myGradesMain.main(myGradesMain.java:19)
import java.util.Scanner;
import java.io.*;
[code]...
View Replies
View Related
Jun 8, 2014
Question 1: I am working on an assignment where I have to remove an item from a String array (see code below). When I try to remove an item after entering it I get the following error "java.lang.NullPointerException." I am not sure how to correct this error.
Question 2: In addition, I am having trouble figuring out how to count the number of occurrences of each string in the array and print the counts. I've been looking at other posts but they are more advanced and I have not yet learned how to use some of the tools they are referring to.
private void removeFlower(String flowerPack[]) {
// TODO: Remove a flower that is specified by the user
Scanner input=new Scanner(System.in);
System.out.println();
System.out.println("Please enter the name of the flower you would like to remove:
[Code] ....
View Replies
View Related
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
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
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
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
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
View Related
Mar 5, 2014
Which method is used while passing or returning a java object from the native method?
View Replies
View Related
Jan 14, 2014
I am getting these errors with this code, I can not figure why this error is occuring.
what is the issue with this code?
Java Code: package ABC;
import java.util.ArrayList;
import java.util.Scanner;
public class GetInputFromUser {
private ArrayList<String> name = new ArrayList<String>();
[code]....
View Replies
View Related
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
Apr 29, 2014
I'm new to Java and I have a problem with a method, I can't see the code of the method, I just have a jar, but it should return a boolean, something like this:
boolean band = false;
band = TestClass.testMethod("blabla");
// band = false
The problem is that the method seems that is returning nothing (band remain false), and if I initialize band to true:
boolean band = false;
band = TestClass.testMethod("blabla");
// band = true
band remain true, in other words, the value of band is never modified, the question is, how is this possible? because it should return the same value on both calls, true or false, no matter the initial value of the variable that is receiving the returning value of the method.
View Replies
View Related
Nov 18, 2014
Now that I have figured out how to return a single variable from a method I am on to the next step, I need to return 2 or 3 variables from a method. I have searched the internet on how to do this to no avail (am I doing the wrong search? I do not know) but what I need to do is return a second (and eventually a third variable)
Here is what I have
private static String Engine() {
String engine = "";
int enginePrice = 0;
System.out.println("Choose a engine size:");
System.out.println("[4] cylinder");
[Code] .....
Which does not work.
View Replies
View Related
May 20, 2014
I'm using apache POI to input data from a excel database. I have a method that is supposed to count the number of rows containing data so I can use that number to initialize an object array. It's returning one more than the actual number of rows and I can't figure out why.
public int getDataRange() throws IOException{
int rowCount = 0;
Iterator<Row> rows = sheet.rowIterator();
while(rows.hasNext()){
HSSFRow row = (HSSFRow) rows.next();
rowCount++;
[Code] .....
I get an array index out of bounds exception at the highlighted line.
View Replies
View Related
Oct 15, 2014
So I'm trying to add two numbers using a stack class I made myself. I have a main class with a main method in which I use three stacks on holds one number one holds the other and then I sum one digit at a time keeping in midn that there may be a carry before putting the result on a third stack.
My problem is I'm getting a null pointer error when it should be putting an integer into the top of my stack which is index 0, I've checked my code and can't see why it would be doing this.This is my main method in my main class
import java.util.*;
import java.io.*;
public class CS25driver {
public static void main(String[]args) throws FileNotFoundException {
[code]...
my input file looks like a single line of input stating the problem followed by two lines of input which need to be summed.this is the error I'm getting
Exception in thread "main" java.lang.NullPointerException
at StackClass.push(StackClass.java:38)
at CS25driver.main(CS25driver.java:55)
View Replies
View Related
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
Feb 20, 2014
So I want to know how in Java you can pass a unkown type into a method (type can be an int, double, or a user defined object) and return that unkown type.
example of what I want:
Java Code:
public (unknowntype)[] method2 ((unknowntype)[])
//Process Data
//unknowntype.process();
return (unknowntype);
} mh_sh_highlight_all('java');
I know in C you can use void pointers and in c++ we have templates but I do not know how java handles this. Also I want to know if it is possible to call a method in the unknowntype.
View Replies
View Related
May 16, 2014
what i do keep getting nullpointerexception error whenever i input 1 or 2 whenever the code is asking me to input the type of display to be shown..
this is my error - "Exception in thread "main" java.lang.NullPointerException
at dakilangtaoako.DakilangTaoAko.alphabetSorter(Dakil angTaoAko.java:195)
at dakilangtaoako.DakilangTaoAko.main(DakilangTaoAko. java:91)
Java Result: 1 "
package dakilangtaoako;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
[code]....
View Replies
View Related
Apr 10, 2014
public int[] allIndicesOf(E itemSought) {
ArrayList<Integer> toUse = new ArrayList<>();
for (E anArray : container) {
if (anArray.equals(itemSought)) {
toUse.add(container.indexOf(itemSought));
[Code] ....
I have an array list of strings. I want to be able to return an array of integers telling me which indexes in the string array list contain the itemSought object.
View Replies
View Related
Feb 26, 2014
I have this method
Java Code:
public static int[] oddNums(int n){
} mh_sh_highlight_all('java');
When a number is passed in, this method returns an array of odd numbers the amount of the number passed in.
So
Ex: Class.oddNums(5) would return [ 1, 3, 5, 7, 9 ]
Class.oddNums(2) would return [ 1, 3]
View Replies
View Related
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
Mar 31, 2014
I'm using NetBeans to create this project and I have the gui registering text boxes, but it won't retrieve what the user entered, so the calculate button returns a null exception error.
Java Code:
package payroll;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JComboBox;
[Code] .....
View Replies
View Related
Apr 16, 2014
I'm making a program with several functions for an array of integers, one being to find the last occurrence of a given integer and returning it. The problem is that the method is returning -1 for every input, even though it's only supposed to do so for numbers not in the array. Here's the part of my code with the sections I'm having an issue with:
Driver
import java.util.Arrays;
public class ArrayMethodsDriver
{
public static void main(String[] args) {
int[] a = {7,8,8,3,4,9,8,7};
System.out.println("Last index of 8: " + ArrayMethods.findLast(a, 8));
System.out.println("Last index of 2: " + ArrayMethods.findLast(a, 2));
[Code] ....
As you can see, I'm testing 8(which should give a 6) and 2(which should give -1 because it's not in the array), and 4(which should give 4). The print statements all say -1.
View Replies
View Related
Dec 10, 2014
Exception in thread "main" java.lang.NullPointerException
at ShoeStore.calculateTotal(ShoeStore.java:103)
at ShoeStore.main(ShoeStore.java:88)
This is the error when program is ran. The program is supposed to calculate the total amount paid for all shoes and display it.
import java.util.Scanner;
public class ShoeStore
{
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String shoe_Name, nameStore, type;
int size, shoeAmount;
double sellingCost;
[Code] .....
View Replies
View Related
May 25, 2014
I am currently making a double linked list class in my compsci class. i was absent for a few days and i need to make an add method for the class. when i go to compile test code i made i get a null pointer error on line 36. This is the node class i wrote and the double linked list class i wrote.
node class
public class Node{
// Two references and Data
Node prev;
Node next;
String data;
public Node(){
prev = null;
next = null;
[Code] ....
This is the class i need working with ( in the doublelinkedlist class)
public void add(Node n){
if(isEmpty()){
first = n;
return;
}
Node temp = first;
while(temp != null){
temp = temp.getNext();
}
temp.setNext(n);
temp.setPrev(temp);
}
View Replies
View Related