Programme Producing NullPointerException

Mar 18, 2014

Am new to programming and am trying to create a system that is similar to a train timetable system.I want the user to be able to enter the stops between two stations ( from a preset list of 5 stations ) and this be saved as an array list, and this array list be saved accordingly within a 2D array so if they were to look in [1][2] there would be an arraylist of stops between station 1 and 2.I used this to initialise the array of arraylists (in a class i created called stops)

ArrayList<String>[][] stopsArray= (ArrayList<String>[][])new ArrayList[5][5];
 
public void stops(){
for (int i = 0; i<5; i++){
for (int j=0; j<5; j++){
stopsArray[i][j]= new ArrayList<String>();
}
}
}

Then I use this code to set the stops

public void setNoStops(int stopsNo){
noOfStops = stopsNo;
}
 
[code]...

The bottom written line of code is mentioned in the null pointer error I recieve. Then.Then in my main programme I declare the new object and use these methods the method options displays the list of five stations with a number reference

System.out.println("Please choose a start station :");
options();
place1 = scanner.nextInt();
System.out.println();
 
System.out.println("Please choose an end station :");
options();
place2 = scanner.nextInt();
System.out.println();

[code]...

mystops is the object I created to store the information.

when compiling I recieve no errors.when I run the program it runs smoothly, asks for the number of stops, allows the user to enter a number, then says enter stop 1, I enter a word and the program crashes giving the error java.lang.NullPointerException

View Replies


ADVERTISEMENT

Code Keeps Producing NaN

Mar 18, 2015

Code isn't giving me the output that I want and keeps giving me NaN

What I want -

Enter the A value for the line: 2.45
Enter the B value for the line: 4
Enter the C value for the line: -8
Enter the x coordinate of the point: 2.17
Enter the y coordinate of the point: -4

Distance from the point to the line is: 3.9831092774319026

What I am getting

Distance from the point to the line is: NaN

Here is my code-

Tester-

import java.io.*;
import java.util.*;
 class tester
{
public static double A;
public static double B;
public static double C;
public static double distance;
public static void main(String args[])

[Code] ....

View Replies View Related

Producing Output From Two Different Files

Feb 13, 2015

How can I extract data from two different files but produce one output. For example, the first three columns are from text_file_1 and the last column (the last foruth column of the output) is from text_file_2...

View Replies View Related

Array Recursion Sum Is Not Producing Correct Output?

Feb 2, 2015

I am trying to sum up the elements of an array. When I test my code the sum is always off by one. For example if I input: 20, 40,30 it gives me 89 instead of 90.

This is what I have so far:

public static void main(String[args]){
int size = kbd.nextInt();
int [] myArray = new int [size]
//user inputs the elements of array
for(int i =0; i<myArray.length; i++){
myArray[i]= kbd.nextInt();
}
int total = sumNum(myArray,0, myArray.length-1)
System.out.println("The sum is"+ total);
}

[code]....

View Replies View Related

Producing Image By Reading From A Data File Filled With Digits

Nov 16, 2014

I'm a complete beginner in Java programming and I'm interested to learn more about its concepts.

Recently, I've been given an exercise which instructs me to display two versions of a picture. The picture to be displayed is provided in the form of a data file of 40,000 digits that are arranged in rows (although there is no marker between rows) and it starts from the top of the picture. So the first digit represents the top left corner of the picture and the last is the bottom right.

Basically, what the exercise wants me to construct a program that plots a dot in one of two colours for each digit. If the digit is in the range 0 to 3 the output should be one colour and for digits in the range 4 to 9 the dot should be in the other colour.

I understand I have to use arrays and also loops to perform this. I'm familiar with the fillEllipse, drawEllipse, drawRectangle and fillRectangle but this exercise is nothing I've attempted before.

View Replies View Related

Why Does String Split Method Producing Arrays With Whitespace Variables

Jan 17, 2015

I used the string split method in the following lines of code like this:

String[] numbers = out.split("[^d.]", 0);
String[] operations = out.split("[.d()]", 0);

When out is equal to the String "2x2.5", the array operations ends up looking like this when it is printed using the toString method:

[, , , x]

As you can see, before the array element x, there are three String variables which only contain whitespace. Why does this occur, and how can I prevent this from happening?

View Replies View Related

Why Is There A NullPointerException

Apr 21, 2015

I am doing a project for my Java class but I ran into a snag with my code.

package lesson13;
import java.io.FileNotFoundException;
import java.util.LinkedHashSet;
import java.util.Set;

public class CharCountingStudy {
public static void main(String[] args) throws FileNotFoundException{
Set<FileExaminer> examiners = new LinkedHashSet<>();
examiners.add(new FileExaminer("raven.txt"));
examiners.add(new FileExaminer("jabberwocky.txt"));

[Code] ....

I keep getting a NullPointerException at the "examiners.add(new FileExaminer("raven.txt"));", the "calculateCharCountAlpha();", and the "if (charCountAlpha.containsKey(w)){"and I don't know why it is doing that.

View Replies View Related

Getting A NullPointerException Error?

Oct 23, 2014

I am getting a NullPointerException Error and I cannot seem to figure out what is causing it. I am reading in a grades1.dat text file and putting the values into a 2D array. The error is occuring in my addGrade method, but I am not sure what the error is. Here are the values for my grades1.dat that I am running in through Run Arguments in JGRASP.

Student1
5
a Activities 0.05
q Quizzes 0.10
p Projects 0.25
e Exams 0.30
f Final 0.30
a100 a95 a100 a100 a100
q90 q80 q100 q80 q80 r90
p100 p95 p100 p85 p100
e77.5 e88
f92

Here are the errors that I am getting.

Exception in thread "main" java.lang.NullPointerException
at GradeBook.addGrade(GradeBook.java:114)
at GradeBookApp.main(GradeBookApp.java:55)
import java.util.Arrays;
/**
* Stores students name, a char array of category codes, a String array of categories, a double array of category weights, and a two dimensional double array of grades where each row contains all the grades in a particular category.

[code]....

View Replies View Related

How To Avoid NullPointerException

May 3, 2014

I have been playing around with my code, but how to avoid NullPointerexception.. So my program's point is simple, use Jsoup to scrape html of certain webpage, then i search the things i want and print them out. Problem is, when scraped html doesnt contain even 1 thing on my search list, i get NullPointerException... i understand why, Heres part of my code:

Java Code:

//Things i need to search from html
String[] MySearchArray = new String[]{"138","146","474"};
//Search things contained in MySearchArray and print them out
for (String Ml : MySearchArray) {
Element flights = doc.select(String.format("tr:contains(%s)", Ml)).first();
Elements flights2 = flights.select("td");
System.out.println(flights2.get(4).text() + " " + flights2.get(0).text()+ " " + flights2.get(3).text());
} mh_sh_highlight_all('java');

View Replies View Related

NullPointerException Under IF Statement Which Should Be Skipped

Feb 10, 2015

/**
* This method displays all winner names for a given year.
* @param year is the integer parameter asked of the user.
*/
public void displayAllWinnersForYear (int year) {
if (year >= 1993 || year <= 2009) {
String[] winnersForTheYear = nobelPrizeWinners.get(year);
for (int i = 0; i < winnersForTheYear.length; i++) {

[Code] ....

When year is outside the 1993-2009 range, I get a NullPointerException from line 10. Shouldn't it be skipped entirely since the conditions of its parent IF statement (line 7) is not met?

View Replies View Related

NullPointerException With Hashtable Object

Mar 1, 2014

I am having some problems with some code and I need an extra set of eyes. It appears I've missed something. I am getting a NullPointerException with a Hashtable object, which I can clearly see I've created. So I'm not quite sure why it is happening. I am pretty sure it is do with the code I've posted because I've tested everything else involved.Here is the code where it happens,

Java Code:

public void siteGen(String user, String site)
throws ExcGenDatabad, ExcSiteNodomain, Exception {
System.out.println("calling siteGen, user: " + user + ", site: " + site);
String nginx_template;
String fpm_template;

[code]....

View Replies View Related

EJB / EE :: Java JAX-WS Client NullPointerException

Aug 26, 2014

I'm new to web services. Right now i'm trying to consume JAX-WS web service on IBM WebSphere Application Server 7. Sending SOAP message with security header[username, password] parameters. Getting NullPointerException..

Exception :

javax.xml.ws.WebServiceException: java.lang.NullPointerException
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitBareMinimalMethod
Marshaller.demarshalFaultResponse(DocLitBareMinimalMethodMarshaller.java:443)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.getFaultResponse(JAXWSProxyHandler.java:559)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:497)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:404)

[code]....

View Replies View Related

Type Name And Get Histogram - Getting NullPointerException

Dec 10, 2014

I recently switched some of code around to restructure how some things were working but now when I run the program I am getting a NullPointerException in multiple areas. I suspect it may have something to do with a constructor. I am very new to "object" - ish based programming.

I figured I should give a little background on the program, this program is reading from a text file of names and decade numbers(for each name) and storing each line into an object array. From there, there are menus and based on the users decision they can type a name and get a histogram, compare names with histograms, ect. Below this main method, I have provided the area where I have gotten the null pointer exception.

Here is the main method for the Client "nameApp"

Also excuse the formatting and curly braces for now!

public class NameApp{

private static boolean validInput;
private static boolean done = false;
private static boolean validDecade;
private static boolean validName;

[Code] ....

And here is the method in the same Client that is getting the null pointer exception:

The pointer exception is on line 6 which is:

if (nameInput.equalsIgnoreCase(list[i].getName())){
private static int checkListArray(String nameInput, Name[] list){
int nameLocation = -1;
int listLength = list.length;

[Code] ....

View Replies View Related

Static Error And NullPointerException With Array

Nov 7, 2014

I have an arraylist, list, that I need to take the size to declare an array, arr3, in another class. Problem 1: the size is giving me an error of "can not make static reference to non-static method getListSize() from the type FindItemInfo". I tried to change getListSize() to static and it gives me and error another place. I try to then fix that, and I get a new error... and so on.

I am using arr3 to store items the user can not afford. I have this next problem even when I input an integer for the arr3 size. I am getting a NullPointerException, and I can't figure out why the arr3[] is not loading. I tried debugging but can not figure out where I went wrong, especially since this code was working in the last assignment before I changed list[] to an arrayList. It always breaks at line 64, but I believe it has to be somewhere in the cashOut() method.

Relevant code is:

public class FindItemInfo implements InterfacePrint{
ArrayList <ItemAttribute> list = new ArrayList<ItemAttribute>();
//does stuff
public void printPriority(){
TransactionCalc finish = new TransactionCalc();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: JFileChooser Is Throwing NullPointerException

Nov 20, 2014

I have a swing application that is using JFileChooser. When I click the Open menu item from File menu it should show the File dialog box where user can select the file.This application is running in my machine but encounters problem in another machine. File dialog box is not showing and stack trace shows that NullPointerException is thrown by JFileChooser..My machine is a 64 bit Windows 7 while the other machine is Windows 7 32 bit. Both machine are using java 1.6..To verify if its because of the 32-bit, I tried in another Windows 7 32-bit and the same application is working.

I came across this article [URL] .... which identified it as bug but already fix in 1.4.2_04. Though I am using 1.6, just to make sure I also tried the suggested work around.I put System.setProperty("swing.disableFileChooserSpeedFix", "true"); in my code but still not working...I also tried to add java -Dswing.disableFileChooserSpeedFix=true to the batch file that is launching the application and still not working

Code Sample:

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
public class FileChooserTester{
public Boolean loadMDBFile() {
System.setProperty("swing.disableFileChooserSpeedFix", "true");
JFileChooser fc = new JFileChooser();

[code]...

View Replies View Related

Changing Canvas Returns With NullPointerException

Jun 21, 2014

I'm currently having trouble with a Breakout clone that I'm working on when I want to change the scenes of the game. When I start out with the main menu and I hit play, the main menu calls for the StateManager to remove the MainMenu and then to add the GameState to start playing through the levels. But, whenever this is done it just gives a NullPointerException and freezes the game. I know the code for initially starting a State is fine because that is the same way the MainMenu is loaded but there seems to be an issue with changing from one to another...

This is the StateManager class that adds and removes the States/Canvases to and from the JFrame/Main class:

public class StateManager
{
private ArrayList<State> states;
private int currentState;
private JFrame gameFrame;
public StateManager(JFrame gameFrame)
{
this.gameFrame = gameFrame;
states = new ArrayList<State>();

[Code] ....

I've tried messing around with the order of which things are added/loading from the StateManager but am just failing to see what I did wrong.

View Replies View Related

String Object In Class - NullPointerException

May 18, 2013

I have a little a problem with String object in this class ....

public class Personne {
     private String nom;
     private String prenom;
     private int age;     
     public Personne(){
          this(null, null, 0);
     
[Code] ....

When i call the class personne with the Personne() i get these errors in compiling-time :

Exception in thread "main" java.lang.NullPointerException
     at java.lang.String.<init>(Unknown Source)
     at Personne.setNom(Personne.java:18)
     at Personne.<init>(Personne.java:12)
     at Personne.<init>(Personne.java:8)
     at Main.main(Main.java:4) // The line wich i inisialize my object in my main method.

View Replies View Related

JavaFX 2.0 :: Printing WebView Causes NullPointerException

Jun 17, 2014

I tried to print something using the new JavaFX 8 printing logic. Unfortunately, it does not work.
 
System:
Linux Mint 17x64
Oracle JDK 8u5
Default printer is cups pdf
 
Code:

package sample;
import javafx.fxml.FXML;
import javafx.print.PrinterJob;
import javafx.scene.control.TextField;

[Code].....
 
Debugging shows the array MediaPrintableArea[] mpa at J2DPrinter:839 is missing its first element, which causes the exception at line 844.

If I execute

service.getSupportedAttributeValues(MediaPrintableArea.class, null, null)
instead of

service.getSupportedAttributeValues(MediaPrintableArea.class, null, pras)
I get an array with an element on the first position.
 
The msn object used for the PrintRequestAttributeSet is "iso-a4", which causes the missing first element in the MediaPrintableArea[] array.

So why does this happen? Am I missing some important config stuff? I tried to fix it myself, but I am not able to debug service.getSupportedAttributeValues(...).

View Replies View Related

Swing/AWT/SWT :: Changing Canvas Returns With NullPointerException

Jun 22, 2014

I'm currently having trouble with a Breakout clone that I'm working on when I want to change the scenes of the game. When I start out with the main menu and I hit play, the main menu calls for the StateManager to remove the MainMenu and then to add the GameState to start playing through the levels. But, whenever this is done it just gives a NullPointerException and freezes the game. I know the code for initially starting a State is fine because that is the same way the MainMenu is loaded but there seems to be an issue with changing from one to another...

This is the StateManager class that adds and removes the States/Canvases to and from the JFrame/Main class:
package com.pathtocreating.Breakout_V2.state;

import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.JFrame;
public class StateManager {
private ArrayList<State> states;

[Code] ....

The code that calls the change of state in MainMenuState is called in the update method:

if(inputController.isMouseClicked("LeftClick")) {
if(playHover) {
soundManager.playSound("ButtonClick");
BreakoutMain.sm.changeStates("GameState");

[Code] ....

Here is the full stack trace when clicking the area to change states:

Exception in thread "Thread-2" java.lang.NullPointerException
at sun.java2d.SunGraphics2D.validateColor(Unknown Source)
at sun.java2d.SunGraphics2D.<init>(Unknown Source)
at sun.awt.image.SunVolatileImage.createGraphics(Unknown Source)

[Code] ...

It gives that same value both before and after clicking on the region.

Printing out b after the State is changed to GameState gives the following:

java.awt.Component$BltSubRegionBufferStrategy@66116674

I've tried messing around with the order of which things are added/loading from the StateManager but am just failing to see what I did wrong.

View Replies View Related

Binary Tree Delete Method - NullPointerException

Oct 4, 2014

Iva tried flipping the entire code upside down (expression) and No matter what I do the delete function returns a null pointer exception after my while loops takes the pointer right to where it should be.

package bp;
import java.time.LocalDate;
public class BinaryTree implements IBinaryTree {
private Node root = null;
private int sizeOfTree = 0;

[Code] ....

View Replies View Related

Enterprise JavaBeans :: Calling Singleton Bean From Session Bean Returns NullPointerException

Feb 23, 2013

I am doing this

@Startup
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.READ)
public class ResourceBean {

[Code] ....

And I call this singleton bean from a stateless session bean like this

@Stateless
public class ClientBean {
@EJB
ResourceBean resource;

public String create(String r)
{
String res=resource.returnString(r);
return res;
}
}

But resource.returnString(r); gives a org.apache.jasper.JasperException: java.lang.NullPointerException I started the glassfish server in debug mode and found out that "resource" was null. but @PostConstruct in singleton does print which means singleton bean exists.

Can we call singleton beans with no interface in such a way form a session bean? I actually want to acquire instance of singleton bean when a client invokes method in Client bean...

View Replies View Related

JSP / JSTL :: Page Set Bean Variables But Give NullPointerException When Bean Try To Merge In DB

Nov 21, 2013

I'm new to JSP but I've to use it to grab data coming from an external site, pass data to a Bean, write data in a DB and redirect the user to another page. Follow the JSP page.

<%@page import="EJB.getResponse"%>
<%
long paymentID = Long.parseLong(request.getParameter("paymentid"));
String responsecode = "9999";
getResponse g = new getResponse();

[Code] ....
 
This is the bean:

@ManagedBean
@RequestScoped
public class getResponse implements Serializable {
private Long paymentId;
private String result;
private String auth;

[Code] ....
 
On the console I see the prints but I receive the NullPointerException

WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at EJB.getResponse.printData(getResponse.java:72)
at org.apache.jsp.notify_jsp._jspService(notify_jsp.java from :60)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)

[Code] ....

View Replies View Related

NullPointerException Adding JPanel To JPanel

Jun 17, 2014

I have a Main() class that extends JPanel and I'm trying to add Card() that also extends JPanel.When I add a Card() or Main() object to the JFrame directly, it works fine. The problem arises when I try to add a Card() object to the Main() object.

I edited the code a little bit to make it easier to read so hopefully it's fine.

Main() code:
public class Main extends JPanel implements Runnable {
// HARDCODED OPTIONS
public static final int WIN_WIDTH = 1200;
public static final int WIN_HEIGHT = 800;

public static final int GRID_X = 9;
public static final int GRID_Y = 5;

[Code] ...

View Replies View Related







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