Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-12-2008, 01:22 AM
Member
 
Join Date: Mar 2008
Posts: 5
oceansdepth is on a distinguished road
help with these errors
i have this error: i will highlight all lines that gave me errors:
Exception in thread "main" java.lang.NullPointerException
at cow.bedCow(cow.java:211)
at seu03Methods.farm(seu03Methods.java:110)
at seu03.main(seu03.java:81)
----------------------------------------------------------------------
ihere is my bedCow method: its goal is to write the array into farmcows.txt
public static void bedCow(cow[]cowList, String barn, int numcows)

{
PrintWriter ofile1 = null;



try
{
ofile1 = new PrintWriter(new File("farmcows.txt"));

ofile1 = new PrintWriter("farmcows.txt");
}
catch(FileNotFoundException e)
{
System.out.println("ERROR");

}


for (int index = 0; index < cowList.length; index++ )
{
ofile1.println(cowList[index].getName()+ "" +"getName" + cowList[index].getBreed()+ "" + "getBreed" + cowList[index].getWeight() +"" + "getWeight" + cowList[index].getGender() + "" + "getGender");
}
ofile1.println();


ofile1.close();

}

--------------------------------------------------------------------------
my seu03Methods:



import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.*;
import java.lang.*;

public class seu03Methods
{
//pre: choice
//post: menu option
public static int seu03Menu()
{
String username = System.getProperty ("user.name");
String ESC = "\033[";
System.out.print(ESC + "2J");
System.out.flush();
System.out.println("Hello");
System.out.println("****************************** **********");
System.out.println("Welcome to the Seu03 Menu System, " + username + "!");
System.out.println("Please choose an option : ");
System.out.println("1. Calculator module");
System.out.println("2. Convert dollar to cents");
System.out.println("3. Find the square root of a number");
System.out.println("4. Print a personalized message");
System.out.println("5. Sentence Analysis");
System.out.println("6. Big Money!");
System.out.println("7. Farm Menu");
System.out.println("9. Exit =*(");
int choice = MyMethods.getInt("Please enter a choice: ", 5);
return choice;
}

//pre:
//post:
public static void farmMenu()
{

System.out.println("Welcome to the 1123 Farm");
System.out.println("1: List cows on the farm");
System.out.println("2: Buy a cow (add a cow to the herd)");
System.out.println("3. Send a cow to slaughter house (delete a cow)");
System.out.println("9: Return to seu03");

return;
}

//pre:
//post:
public static void farm ()
{
Scanner cscan = new Scanner(System.in);
boolean runAgain = false;
int check = 0;
int choice = 0;
cow[]cowList = new cow[50];
int cowcount = 0;

cow.getCow(cowList, "farmcows.txt");

do
{
farmMenu();
choice = MyMethods.getInt("Please choose option: ", 5);


switch (choice)
{

case 1:
{
cow.cowReport(cowList, cowcount);
break;
}

case 2:
{
cow.addCow(cowList, cowcount);
break;
}

case 3:
{
cow.deleteCow(cowList, cowcount);
break;
}

case 9:
{
cow.bedCow(cowList,"farmcows.txt", cowcount);
runAgain = true;
break;
}


default:

System.out.println ("Invalid choice. Please try again.");
break;
}//end of switch statement

if (choice == 9)
return;
if(choice != 9)
{
return;
}


}
while(check == 1);
return;
}

-------------------------------------------------------------------------------------------

import java.util.*;
import java.math.*;
import java.io.*;
import java.awt.*;
import java.lang.*;

public class seu03
{

public static void main (String[] args)
{

Scanner cscan = new Scanner(System.in);
boolean runAgain = false;
int check = 0;
int choice = 0;

do
{
choice = seu03Methods.seu03Menu();


switch (choice)
{

case 1:
{
seu03Methods.calculator();
break;
}

case 2:
{
seu03Methods.coins();
break;
}

case 3:
{
seu03Methods.sqrtD();
break;
}

case 4:
{
seu03Methods.message();
break;
}


case 5:
{
seu03Methods.sentenceCheck();
break;
}
case 6:
{
seu03Methods.bigMoney();
break;
}
case 7:
{
seu03Methods.farm();

break;
}
case 9:
{
seu03Methods.exit();
runAgain = false;
break;
}


default:

System.out.println ("Invalid choice. Please try again.");
break;
}//end of switch statement

if (choice == 9)
return;
if(choice != 9)
{
System.out.println("****************************** ****************");
System.out.println ("Would you like to run program again?");
System.out.println ("Yes = 1");
System.out.println ("No = 2");
check = cscan.nextInt ();

if(check == 1)
{
runAgain = true;
}
else
{
runAgain = false;
}
}


}
while(check == 1);
return;
--------------------------------------------------------------------
i also need to return to seu03 if option 9 on the farmMenu is chosen but whenever I chooose it I always get that error.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-12-2008, 03:41 AM
Member
 
Join Date: Jan 2008
Posts: 21
banie is on a distinguished road
Please fill your code in code bracket.

You can get your answer here

Last edited by banie : 04-12-2008 at 03:45 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 05:39 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 524
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
String value stackTrace generated by JVM through console/input stream is understandable and readable enough by a programmer..

There is also a line number that indicates where the exception occured.

banie's reply will help you out....

regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-16-2008, 05:55 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
Your line is referencing a place outside of the bounds of the cow list. I cannot give you anything anymore exact. If you look at the place where the length of your list is calculated(which you did not post) i would think that the error is in there. Try outputing the list to the screen and output what your program thinks the length of the list is at the time. And remember that your length will be one number greater than your last array element. If you array goes 0 to 7 then your length will be 8. And if you reference element 8 then there will be a null pointer exception. However i don't think this is part of your error since your for loop goes to less than your length which brings me back to an incorrect length.

Side thought...is Sukatoa a reference to the trigonometry memory tool for sin cos and tangent (soh cah toa)? If not then that is a crazy coincidence.

Last edited by Chris.Brown.SPE : 04-16-2008 at 05:58 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors I don't understand MattyB New To Java 4 04-02-2008 12:55 AM
Handling SQL Errors and Warnings Java Tip Java Tips 0 02-12-2008 10:37 AM
I have 3 errors after compiling coco Database 2 10-18-2007 10:32 AM
Trying to catch thread errors yelllow4u New To Java 2 08-07-2007 03:52 PM
Errors in constructor ai_2007 Advanced Java 0 07-01-2007 06:35 PM


All times are GMT +3. The time now is 08:18 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org