Solved

simply java memory error

Posted on 2002-04-17
2
181 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 119
Unable to start eclipse ? 17 127
Java SE 8u111  Lot of stuff broke 11 52
nextBoolean(double p) for Random class 3 35
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

943 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now