Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Beginning Java
null pointer exception
Muhammad usman shad
Ranch Hand
Posts: 30
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
No error when compile it,
But it does not execute!!!
What is the solution???
class Initializing_Array { int x; int y; String z; int xx = 10; int yy = 20; public static void main(String args[]) { Initializing_Array obj = new Initializing_Array(); obj.initialization(); } public void initialization() { Initializing_Array[] ia = new Initializing_Array[10]; // Initializing_Array ia[] = new Initializing_Array[10]; for(int i=0; i<10; i++) { xx = xx+15; ia[i].x = xx; ia[i].y = yy; if(xx == 70) { xx = 10; yy = yy+15; } } } }
sujith Acharya
Ranch Hand
Posts: 60
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Initializing_Array[] ia = new Initializing_Array[10];
You have created 10 reference of type Initializing_Array
It doesnt mean 10 objects of Initializing_Array.
So you have to create Object and assign to these refence, then only you able to set the values.
like
for(int i=0; i < ia.length; i++){ ia[i] = new Initializing_Array(); }
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Giving Pong Computer Intelligence.
How to make all my graphics selectable and doubleclick with event?
Syntax for mapping a var to a method
Runtime vs Compile time
constructor invocation
More...