?
Solved

simply java memory error

Posted on 2002-04-17
2
Medium Priority
?
187 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 300 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

719 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