Exception in Main
Hi Everyone,
Everytime i run my class i get the exception below, when i dont use an array it is fine. what am doing wrong. i am a total newbie to java and i need to be able to test my classes are fucntioning properly so i can continue with my application. here is a subset of the code. line where the error referencing are underlined
Exception in thread "main" java.lang.NullPointerException
at runGame.myGPlayers(runGame.java:22)
at runGame.main(runGame.java:9)
public static void main(String[ ] args)
players[ ] myPlayers;
//gameCode myGameCode = new gameCode();
myPlayers = myGPlayers();
PlayGame(myPlayers);
public static players[ ] myGPlayers()
players[ ] GPlayers = new players[3];
Scanner sc = new Scanner(System.in);
String nameIn;
for (int i = 1; i < GPlayers.length; i++)
System.out.println("enter player name : ");
nameIn = sc.next();
GPlayers.setplayerName(nameIn);
return GPlayers;
You created the array, but all elements of it are still null.
The loop should probably be 0..< GPlayers.length.
After you read a name, do:
GPlayers[i] = new player(); // add constructor parameters as necessary.Please use code tags (see button above posting box), so that the [ i ] in your code doesn't cause italics. You can't underline in code tags, but you can put a comment next to the line as I did.
Similar Messages
-
Exception in Main under Win XP
Every time I try to run JVM through the JDK 1.3.1, I get and exception in main under Win XP. Any thoughts???
What kind of exception.....can you post the entire error message?
V.V. -
Throws Exception in main and return code for JVM
Hello,
Could someone tell me what the following statement :
public class Foo {
public static void main(java.lang.String[] args) throws Exception {
// Some source code
is supposed to do with the return code of the VM when the Exception is thrown.
I mean what num�ric value is supposed to return the following instruction :
java -classpath ... com.app.Foo
Because my Java program is run in a script shell which is supposed to get a return code which as to be interpreted.
Off course I am not allowed to do the test myself because this script shell is executed on a production server ...I don't know what the return code will be, but you could do this:
public static void main(String[] args)
try
// ...Run the program here...
catch (Exception e)
// Print the stack trace
e.printStackTrace();
// Exit with an error code
System.exit(10);
}Jesper -
Tomcat exception in main when starting
When I start tomcat 4.1 it throws an exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/InputSou...
What's going on? I'm getting really frustrated.Hi,
You must check tomcat version and java version.
the Tomcat4.1.24 exists two version. it is normal version and LE version.
if you installed LE version. it must be used "jdk1.4.x".
and jdk1.4.x has org.xml.sax package but less then version not have.
thanks.
i am japanese. sorry bad english... -
HelloWorldApp throws Exception in Main
Hi folks,
Can some one help me to get this working. It compiles fine but when i run using the
java HelloWorldApp
it throws this error
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
the program i am trying to run is
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
Thanks
pavanPerhaps:
mkdir c:\java\classes
javac -d c:\java\classes YourClass.java
That'll put the output classes in the classes directory, which is cleaner anyway, rather than keeping them with your source.
Then set your classpath to include c:\java\classes -
Why throw exception in main thread
A very simple example
public class ExceptionTest {
public static void main(String[] args) throws StupidException {
int i = 0;
if (i == 0)
throw new StupidException():
public class StupidException {
public StupidException() {}
}Umm, one of us is missing something here. My only question is "What are you surprised about?" You have the line
throw new StupidException();and you don't catch that exception anywhere, so of course the program is going to exit that way. You explicitly told main to throw an exception and it did it.
Sorry, not trying to sound snotty or anything. I guess I still just don't know what you're asking.
>
class ExceptionTest {
public static void main(String[] args) throws
StupidException {
int i = 0;
if (i == 0)
throw new StupidException();
class StupidException extends Exception {
public StupidException() {
System.out.println("Da. This is a stupid
d exception!");
}The error that occurs during runtime, along with
expected output, is the following:
Da. This is a stupid exception!
StupidException
at ExceptionTest.main(ExceptionTest.java:7)
Exception in thread "main"
Process completed.
Okay. Now the question again will be "Why is this
runtime error thrown?" It is possible for the main
method to throw an IOException. This is a common
throwable.It's possible for main to throw any throwable you tell it to.
>
It is true that a try/catch can handle this. But then
again creating an exception package for a full
application makes could use of the write once/use
anywhere dictum.I have no idea what you're talking about here. What do you mean "an exception package for a full application"? and what does that have to do with write one, run anywhere?
>
Anyone able to naildown the conflict with the runtime
system?What conflict would that be. -
Hi all
I'm trying to out put an XML file to the screen as a string in DOS as
having problems using JCreator package I have to view it. The file compiles ok in dos but when I try java Filename it has an exception in thread "main" java.lang.NoClassDefFoundError: Class
I have a main method in the class so what is the problem?????
thanks for your helpDear ChuckBing
thanx for the reply
please refer to the other thread with the same title. I stupidly managed to press the post button twice ;)
Im basically having a prob outputting some XML to the screen
Ive given up trying to run it thru dos and am back trying to view it through JCreator
its looking better - I dont get any system.out.println output though - but I know of at least one person who has run my code and managed to get XML output - Im still trying to discover how!!!! -
I can compile the code well but when try running the compiled code an error occurs Exception in the thread "main" java.lang.NoclassDefFoundError what could be the problem? OS is window XP. Please help
1) make sure your class name and java filename are the same
2) make sure your classpath covers the current directory you're in -
Java Exception in Main/Menu/Reporting Tools/XML Publisher/Report Definition
Hi ,
One know this error :
Java Exception: java.lang.NoSuchMethodError: oracle.xml.parser.schema.XSDBuilder.build(Ljava/io/InputStream;Ljava/net/URL;)Loracle/xml/parser/schema/XMLSchema;: during call of com.peoplesoft.pt.xmlpublisher.PSXPXsdUtils.getLevel0ColNames. (2,763) PSXPRPTDEFN_WRK.FUNCLIB.FieldFormula Name:GetBurstFieldValues PCPC:3211 Statement:48
Called from:PSXPRPTDEFN_WRK.FUNCLIB.FieldFormula Name:SetBurstFieldValues Statement:81
Called from:PSXPRPTDEFN_WRK.FUNCLIB.FieldFormula Name:LoadReportDefn Statement:660
Called from:PSXPRPTDEFN_WRK.FUNCLIB.FieldFormula Name:SelectReportDefn Statement:744
Called from:PSXPRPTDEFN.GBL.PostBuild Statement:36 The noted Java error was thrown during a call of the given method.
It's if i Add a New Value in the report definition (Peoplesoft 8.5 , CRM ) : No customization in this
Thanks in advance..Judging by the error, it looks like the xsd can not be constructed.
I would start of by checking if the target location is defined in the Intergration Broker.
PeopleBooks > PeopleTools 8.52: PeopleSoft Integration Broker Administration > Configuring PeopleSoft Integration Broker for Handling Services > Using the Target Locations Page to Set Target Locations for Services
http://docs.oracle.com/cd/E28394_01/pt852pbh1/eng/psbooks/tiba/book.htm?File=tiba/htm/tiba08.htm#H3007 -
I am connected to internet...all other devices receive emails (ipad, iphone). However, my main computer will not receive emails anymore. Why?
Ok. So this is interesting.
Previously, I had checked my storage with Yahoo Mail Plus and I had tons of available space.
Similar to this post, I sent an email to Yahoo Mail customer service outlining my problem. Did not receive a response.
Despite my Yahoo Mail Plus account showing plenty of available space, I decided to clean-up (delete emails and delete the resulting Trash) the various folders in the Yahoo Mail Plus account.
While deleting emails from the Sent folder and Spam folder in Yahoo Mail Plus, my Mac Mail started uploading my inbox from Yahoo Mail Plus.
I don't know if someone at Yahoo Mail "fixed something" in response to my customer service email or whether Yahoo Mail wasn't allowing Mac Mail to upload my Inbox due to some "folder sublimit" issue that wasn't readily apparent (which was "resolved" when I started cleaning up the Yahoo Mail folders).
I know it wasn't the overall storage that shows on your Yahoo Mail account because I checked that as one of the first things.
Anyway, I'm back up and running. Thanks for responding and working with me to try to figure this out. -
Exception in "main" java.lang.NoClassDefFoundError:
I'm in the wrong forum, but can't figure out how to move it. Ok, I've reread the section on setting the classpath 12 times & I still get this error. I created a CLASSPATH variable both under the user & system variable of the environmental variables. I'm using Windows XP. The CLASSPATH is set at C:\Program Files\Java\jdk1.5.0_07\bin
Somebody please help me, I'm a student & at my wits end.
Message was edited by:
astinabeanI'm in the wrong forum, but can't figure out how to
move it. Ok, I've reread the section on setting the
classpath 12 times & I still get this error. I
created a CLASSPATH variable both under the user &
system variable of the environmental variables. I'm
using Windows XP. The CLASSPATH is set at C:\Program
Files\Java\jdk1.5.0_07\bin
Somebody please help me, I'm a student & at my wits
end.
Delete the Classpath environmental variables. Go to the directory where your .class file is. Enter "java YourClassName" Do not put .class or .java at the end - just put in the class name. Use the same upper/lower case characters that your class name uses in the .java file. If you need more help, post the 'exact' error message and the 'exact' command you are using. -
Vipca: Exception in thread "main"
I am trying to install oracle clusterware
I reached the point where I had to run root.sh on both the servers (one by one).
root.sh on 1st server went smoothly.
I commeted out the LD_ASSUME_KERNEL from vipca.
I ran root.sh on 2nd node, but it threw standard error for vipca.
Then I ran vipca on 2nd node from root user from outside as a standard procedure, on completion of root.sh on 2nd node.
I am getting the following error:
*[root@rac2 bin]# ./vipca*
*Exception in thread "main" [root@rac2 bin]#*
I did set DISPLAY variable and my xclock works fine too.
Please help me out.
Thanks..
shomil
Edited by: user7387659 on May 20, 2009 2:53 PMThis could be a bug - see MOS Doc 5854172.8 (Bug 5854172 - VIPCA fails with exception thread main error)
HTH
Srini -
Execute jar file: "could not find the main class" program will terminate
Hey,
I am new to Java. I have started to make a small java program which supposed to help me at my studies to lean the Dominic Memory System. I have used the latest version of Netbeans 5.5.1 to build my program in. I have two problems which I cannot figure out how to solve, please help me.
The first problem is that the java script I have made works when I compile it in Netbeans, but when I create a Jar file it does not work. I receive a pop up message in windows ?could not find the main class program will terminate? when I execute the jar file.
The second problem I have is that I need to compare the strings generated by the "numbers" and "TIP" and if the numbers is not identical the numbers in the ?Center? JPanel should be highlighted as red.
If anyone would like to clean up the code I would be pleased. I have copied quite a lot from anyone because of my one lack of knowledge.
* GoListener.java
* Created on 12. september 2007, 21:48
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package grandmaster;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
import java.util.StringTokenizer;
import java.awt.Color;
* @author Computer
public class GoListener implements ActionListener {
private JTextField viewer;
private JTextField TIP;
private JTextField freq;
private JTextField max_num;
private Vector numbers;
public GoListener(JTextField j,JTextField k, JTextField m, JTextField f, Vector n) {
freq = f;
max_num = m;
viewer = j;
numbers = n;
TIP = k;
public void actionPerformed(ActionEvent e){
int time = Integer.valueOf(max_num.getText());
int f = Integer.valueOf(freq.getText());
if (e.getActionCommand() == "GO") {
for (int i = 0; i< time;++i) {
int number=0;
number = (int)Math.floor(100*Math.random());
while(number>51){
number = (int)Math.floor(100*Math.random());
if(number<=9){
viewer.setText(" "+"0" + String.valueOf(number) + " ");
} else{
viewer.setText(" " + String.valueOf(number) + " ");
viewer.paintImmediately(viewer.getBounds());
numbers.add(number);
try {
Thread.sleep(f*1000);
} catch (Exception exp) {
viewer.setText(" XX ");
viewer.paintImmediately(viewer.getBounds());
if (e.getActionCommand() == "VIEW") {
try {
//int numb = Integer.valueOf( TIP.getText() ).intValue();
StringTokenizer tokenizer = new StringTokenizer(TIP.getText(), " ");
String[] split = null;
int tokenCount = tokenizer.countTokens();
if (tokenCount > 0) {
split = new String[tokenCount];
for (int current = 0; current < tokenCount; current++) {
split[current] = tokenizer.nextToken();
viewer.setText(" " + String.valueOf(numbers) + " ");
// k=numbers(1);
/*while(c<i){
String.valueOf(k).equals(split[1]);
c++;
TIP.setText(" " + split[2] + " ");
} catch (Exception exp) {
try {
//string testit = numb.toString();
//String str = "" + numb;
//viewer.setText(str);
//viewer.setText(numbers.toString());
numbers.clear();
} catch (Exception exp) {
* Main.java
* Created on 12. september 2007, 21:07
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package grandmaster;
import java.util.Vector;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JButton;
import java.awt.*;
import grandmaster.GoListener;
* @author Computer
public class Main extends JFrame {
private JTextField viewer;
public JTextField TIP;
// private TextInputPanel TIP;
private Vector numbers;
/** Creates a new instance of Main */
public Main() {
numbers = new Vector();
JPanel p = new JPanel(new GridLayout(0,4));
JButton go = new JButton();
JButton view_num = new JButton();
go.setText("Go!");
go.setVisible(true);
go.setActionCommand("GO");
view_num.setText("VIEW");
view_num.setVisible(true);
view_num.setActionCommand("VIEW");
JTextField max_num = new JTextField();
max_num.setText("5");
JTextField freq = new JTextField();
freq.setText("1");
viewer = new JTextField();
viewer.setText("XX");
TIP = new JTextField("");
p.add(go);
p.add(max_num);
p.add(freq);
p.add(view_num);
getContentPane().add(p,BorderLayout.NORTH);
getContentPane().add(viewer,BorderLayout.CENTER);
getContentPane().add(TIP,BorderLayout.SOUTH);
setSize(200,200);
GoListener g = new GoListener(viewer,TIP,max_num, freq, numbers);
go.addActionListener(g);
view_num.addActionListener(g);
* @param args the command line arguments
public static void main(String[] args) {
// TODO code application logic here
Main window = new Main();
window.setVisible(true);
}NetBeans questions should be posted to the NB site. It has mailing lists and associated forums.
This tutorial from the NB site addresses running programs outside of NB
http://www.netbeans.org/kb/articles/javase-deploy.html
When you compare objects, use ".equals()" and reserve == for comparing values. -
Logon Error:Could not retrieve the source file for Port "Main"
Hi All,
We have a port which is blocked due to structural exceptions.When i try to connect to the Exceptions folder
"Main[Exceptions]" the import manager throws an error "Logon Error:Could not retrieve the source file for port "Main".
Any help greatly appreciatedHi ,
Thanks for your reply.
This is what I see in the log file in the exceptions folder
These are the line I see almost to the end of the log file before they complete field mappings,value addings
<Failure ts="2008/07/22 00:10:48.326 GMT" tid="1286" entry-no="9114" operation="Create lookups" rc="0x80000001">Illegal value for parameter</Failure>
<Timer ts="2008/07/22 00:10:48.327 GMT" tid="1286" entry-no="9115" name="Import Lookup" total="0.040819">1</Timer>
<Trace ts="2008/07/22 00:10:48.327 GMT" tid="1286" entry-no="9116">Import of Lookup Failed.</Trace>
But when I open the same source xml file after downloading to my local folder from Exceptions Structural folder and load manually using IM i get the status as "Ready to import".
Any Help greatly appreciated -
Error message Java Application uncaught exception
When trying to launch my Optus mobile broadband connection I get error message 'cannot launch Java Application uncaught exception in main method: java.lang. NullPointerException. This only started recently. I try restarting and shutting down, and occasionally it launches successfully, but not very often.
Fixed
Maybe you are looking for
-
I have quite alot of music etc so to save hard drive space I have created my iTunes library on an external hard drive. If I ever accidentaly open iTunes when that external hard drive isn't attached iTunes makes a whole new library from scratch on my
-
Error in adding KE30-PA report created to new user.
Please help me with my problem. I have created a report for KE30-profitability analysis report which I will add to a new user name in sap. I have created the role which is zabc then I added the profitability analysis report which I created. A YXxxxxx
-
Upgrade OS of Primary Site (2008 R2 to 2012 R2)
Our org has a single primary site (SCCM 2012 R2 5.00.7958.1203) and is comprised of two site systems/servers and roughly 2500 clients. Site System/Server 1 has the following site system roles installed: Distribution Point Management Point Software Up
-
Find and Replace Font Colors in Multiple Text Boxes
Hello, I have Illustrator version 15 I made many text boxes with multiple colors, red and black on each letter. I was wondering if there is a find and replace tool for multiple text boxes. I want to change the reds to black and the blacks to light gr
-
Missing access rights to watch documents in BI Portal (Integrated Planning)
Dear All, At the moment we are working on our first project with integrated planning. One of our requirements is to enter a long text to a planning position. Unfortunaltey we receive an error message while trying display the popup text box with the l