Solved

simply java memory error

Posted on 2002-04-17
2
184 Views
Last Modified: 2010-03-31
The code below is compiling but throws error when executing. Why? pls. include detailed explanation. thanx.


class One{
     String strOne;
     One(String str){
          strOne = str;
     }
}


public class Two{

     One[] o;
     int i;
     Two(){
          for (i=0; i<10; i++)
          {
               o[i] = new One("a");
               System.out.println(o[i].strOne);
          }
     }

     public static void main(String[] args) {
                Two t = new Two();
               
               
     }


}
0
Comment
Question by:pelau
  • 2
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 6949035
You don't initialise the array o.
Should be:

...
public class Two{

    One[] o = new One[10];
    int i;
...

0
 
LVL 92

Expert Comment

by:objects
ID: 6949085
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
MySQL  on Tomcat 8 71
jsp login check 12 43
Need Help! Getting a syntax error and don't understand why 3 31
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question