Solved

simply java memory error

Posted on 2002-04-17
2
180 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
Comment Utility
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
Comment Utility
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

743 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

15 Experts available now in Live!

Get 1:1 Help Now