Solved

simply java memory error

Posted on 2002-04-17
2
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss wildfly 10.1 10 625
maven module vs maven project 3 118
login form jsp example 2 73
Java class and jar 3 61
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

752 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