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
ADVERTISEMENT
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
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
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
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
Aug 23, 2007
The getGraphics() method in my constructor is returning a nullPointerException and I can't figure out why. This class is extending a JPanel and I thought calling super() would fix it because it makes sense that the JPanel would initialize its graphics object in the constructor, but that didn't fix it. The line that produces the error is in bold. I've narrowed it down to the getGraphics() method is returning null, so the next line that calls the graphics object is actually the one that produces the error.
int leftMargin = 2, rightMargin = 2, topMargin = 2, bottomMargin = 2;
int lineSpacing = 1;
int currentX = leftMargin, currentY = topMargin;
Font defaultFont, customFont;
public HTMLFrame(){
super();
[Code] ....
print(String) is a method I made that draws lines of text on the graphics object, similar to System.out.println(String) in the command prompt.
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
Mar 31, 2014
I am very Java illiterate and I need to know how would i set all the variables in the first class to null or 0 to make a new method to clear everything.
import java.util.Arrays;
import java.util.Scanner;
public class studentMethods
{
private double totalScore;
private int count;
[Code] ....
View Replies
View Related
Apr 16, 2014
I'm getting an error on line 137 and all it is rsmd = rs.getMetaData();The error happens only after I press a JButton and it is
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionat softwareDesign.createAccount.actionPerformed(createAccount.java:137)
There is a lot more to it but that has nothing to do with my code it's just the stuff with Eclipse anyway I want to know how do I fix this problem?
View Replies
View Related
Feb 28, 2015
public class Test {
public static void main(String[] args) {
Car c = new Car();
c.setInf("toyota", "red");
System.out.println("name: "+ c.brand + " colour: " + c.colour);
[code]....
Why do I get the result brand null, colour null? I know what null means but what am I missing here?
View Replies
View Related
Apr 6, 2015
This simple program should build a new table with random values and on the getValue method (perhaps called from othe TestClass) return back content of particular cell. why my getValue method doesn't work. Nay! It returns error while compilation.
import java.util.Random;
class TablicaIntowa{
public int getValue(int a){
return tabl[a];
} //getValue method end
[Code]....
View Replies
View Related
Nov 22, 2014
I have created a class and a matrix of doubles (or at least, I think I have, that's partly what I want to verify).I need to return the values of the array,Here is my class:
public class example{
double[][] Position=new double[2][11];
double calculate(){
for (int time=0;time<=10;time=time+1){
Position[1][time]=time;
Position[2][time]=time+1;
double A=Position[2][time];
return A;
}
}
}
I am getting the error: "This method must return a result of type double", though to me it looks like I am returning double (A).
View Replies
View Related
Jan 4, 2015
I've made a class called Car with a method which will tell me a category for the engine size regarding the actual size (which I've included in the main just so I could see if it works) but everytime I test it I get an error.
public class Car {
public String b;
public String c;
public double es;
public double cs;
public String getCategory() {
if (es < 1.3)
[Code] ....
Figured it out. Was missing parenthesis on audiCar.getCategory();
View Replies
View Related
May 14, 2014
i am trying to run a command in terminal the code is below if i run the command in terminal it works fine however when i run it from netbeans with code below nothing gets printed. however if i run a different command such as (ip addr) it works fine?
public static void a() throws IOException{
ArrayList lister=new ArrayList();
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("ps -ef | grep firefox");// the command i am trying to run to get pid of application
InputStream stderr = proc.getInputStream();
[Code] ....
View Replies
View Related
Oct 12, 2014
I am writing a code where in the first method the question will ask whats your favorite website. for example www.javaprogrammingforums.com...when it outputs it will read just "javaprogrammingforums" without the www. and the .com.
Because the program will ask a series of questions in the main, I would like website question to be returned to the main. Here is my code, and what can I do?
import java.util.Scanner;
public class chapter3 {
public static String website(Scanner kb) {
String website;
System.out.println("What is your favorite website?");
website = kb.next();
[Code] ......
View Replies
View Related
Sep 1, 2014
I'm having an issue returning data from a constructor. This is an assignment, and the specifications were that two classes are to be used, one for the variables and assigning methods, and one for the main method and the printing. This app compiles, but returns "0" for the isbn number, and I'm sure it's because I'm not doing something right with my constructors. My code is below
public class Book {
/* Declare Variables */
public static int isbn;
/* Constructor */
public Book (int isbn) {
isbn = 454545;
[code]....
There are other variables to add, but if I can get one working, I can get the rest working.
View Replies
View Related
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
Mar 27, 2014
I want to return multiple values in my EJB query. The query goes something like this:
SELECT SUM(s.sales) SUM(s.cancels) FROM accounts.
To implement this if I write as below:
Query query = _em.createNamedQuery("Accounts.findAccountData");
Now if I do query.getSingleResult(); how do i retrieve both the values since the ejb finder returns either a single object or a collection?.
View Replies
View Related