473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

int cannot be dereferenced error message

6
Expand|Select|Wrap|Line Numbers
  1. package bankobject;
  2. import java.io.*;
  3. import javax.swing.JOptionPane;
  4.  
  5. class Number {
  6.    String studentName;
  7.    String teacherName;
  8.    int[] Number;
  9.  
  10. public Number () {
  11.    studentName = JOptionPane.showInputDialog("Please Enter student name");
  12.     teacherName = JOptionPane.showInputDialog("Please Enter the teacher name ");
  13.     int numNumber = Integer.parseInt(JOptionPane.showInputDialog("Please enter the number of numbers"));
  14.     Number[] obj = new Number [numNumber];
  15.     for (i = 0; i < numNumber.length; i++)
  16.        obj [i] = new Number ();   
  17. }
  18.  
I want the array to take as many numbers object, by using a for loop and instantiate each number object by calling the Number constructor.
Feb 15 '08 #1
11 11654
BigDaddyLH
1,216 Expert 1GB
I think you meant to write this:

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < numNumber; i++)
Feb 15 '08 #2
BigDaddyLH
1,216 Expert 1GB
There are also several logical errors in your code that you need to attend to. In your Number class you create an array full of Number objects -- that could lead to an infinite loop if you keep creating non-empty arrays. I think you meant the user interaction code to be elsewhere, perhaps in the main method, which hasn't shown up, yet. Also you have an int array called Number -- surely pure confusion on your part?
Feb 15 '08 #3
JPane
6
There are also several logical errors in your code that you need to attend to. In your Number class you create an array full of Number objects -- that could lead to an infinite loop if you keep creating non-empty arrays. I think you meant the user interaction code to be elsewhere, perhaps in the main method, which hasn't shown up, yet. Also you have an int array called Number -- surely pure confusion on your part?
Yeah, I meant for (int i = 0; i < numNumber; i++); forget the int there.

in the attributes list I wanted to make an array of number objects then in the constructor I would prompt the user for the number of number objects and use a for loop to instantiate each number account using the number constructor for each.

in the main method I would just instantiate two number objects.

The problem I'm having is in the for loop and getting the error " int cannot be dereferenced error message" I know I have to do something with it because it's a primitive, just don't know how in an array and for loop.
Feb 15 '08 #4
Ganon11
3,652 Expert 2GB
Don't know if this will fix your problem, but it looks like you declare a private data member of the Number class called int[] Number - that;s bound to give you problems. Consider a better name for it.
Feb 15 '08 #5
JPane
6
Don't know if this will fix your problem, but it looks like you declare a private data member of the Number class called int[] Number - that;s bound to give you problems. Consider a better name for it.

maybe int [] grade is better.


Still doesn't work since the error is coming with this line

for (int i = 0; i < numNumber; i++)
Feb 15 '08 #6
BigDaddyLH
1,216 Expert 1GB
I don't get syntax errors from your code when I change it as I indicated.
Feb 15 '08 #7
JPane
6
Thanks for the help.
Feb 15 '08 #8
JPane
6
There are also several logical errors in your code that you need to attend to. In your Number class you create an array full of Number objects -- that could lead to an infinite loop if you keep creating non-empty arrays. I think you meant the user interaction code to be elsewhere, perhaps in the main method, which hasn't shown up, yet. Also you have an int array called Number -- surely pure confusion on your part?
If I have two classes which are number and student how would I call them up in the main method when I just instantiate a number object. Meaning the input attributes in the student class.

Both classes are composition of each other.
Feb 15 '08 #9
BigDaddyLH
1,216 Expert 1GB
If I have two classes which are number and student how would I call them up in the main method when I just instantiate a number object. Meaning the input attributes in the student class.

Both classes are composition of each other.
I don't understand what you are trying to say. perhaps is you posted some code to explain what you are trying to do.
Feb 15 '08 #10
JPane
6
Expand|Select|Wrap|Line Numbers
  1.  
  2.       package studentobject;
  3.  
  4.       import java.io.*;
  5.  
  6.       import javax.swing.JOptionPane;
  7.  
  8.  
  9.       class Number {
  10.  
  11.          String studentName;
  12.  
  13.  
  14.          int[] Number;
  15.  
  16.  
  17.       public Number () {
  18.  
  19.          studentName = JOptionPane.showInputDialog("Please Enter student name");
  20.  
  21.           teacherName = JOptionPane.showInputDialog("Please Enter the teacher name ");
  22.  
  23.           int numNumber = Integer.parseInt(JOptionPane.showInputDialog("Please enter the number of numbers"));
  24.  
  25.           Number[] obj = new Number [numNumber];
  26.  
  27.           for (i = 0; i < numNumber.length; i++)
  28.  
  29.              obj [i] = new Number ();   
  30.  
  31.       }
  32.  
  33.  
  34. class Student
  35.  
  36. {
  37.  
  38.     String schoolName;
  39.  
  40.  
  41. // Methods
  42.  
  43.  
  44.     void  students()
  45.  
  46.     { 
  47.  
  48.  
  49.         double students = 0;
  50.  
  51.  
  52.     }
  53.  
  54.  
  55.  
  56.     // Constructor
  57.      public Student ()
  58.  
  59.  {
  60.  
  61.  
  62.    schoolName = JOptionPane.showInputDialog("Please Enter the school name ");
  63.  
  64.  
  65.  }
  66.  
  67.   }
  68.  
  69.  
  70. }
  71. public class StudentOject  {
  72.  
  73.  
  74.     public static void main(String[] args) {
  75.  
  76.       Number nu = new Number ();
  77.  
  78.  
  79.    String output = "Student Name " + nu.studentName + "      Teacher Name: "  + nu.teacherName
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.         JOptionPane.showMessageDialog(null, output, "Student Information",
  90.                 JOptionPane.INFORMATION_MESSAGE);
  91.  
  92.  
  93.     }
  94.  
  95.  
  96. }   
  97.  
  98.  
  99.  
  100.  
  101.  
Since the student class is part of the number class when I do the output it isn't going to work with the student class because I only made a new object in the number class.
Feb 16 '08 #11
BigDaddyLH
1,216 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. public Number () {
  2.     ...
  3.     int numNumber = Integer.parseInt(JOptionPane.showInputDialog("Please enter the number of numbers"));
  4.     Number[] obj = new Number [numNumber];
  5.     for (i = 0; i < numNumber.length; i++)
  6.         obj [i] = new Number ();   
  7. }
  8.  
I can't get past this constructor. Do you understand it? When you construct a Number object, you prompt the user for a size, allocate an array and then construct more Number objects, each of which will prompt the user for a size, allocate an array and then construct more Number objects, each of which will prompt the user for a size, allocate an array ...

I think you need to start over again. I still have no idea what you are trying to do, and I'm not convinced anyone does, including yourself. First, answer these questions.
  1. What is a Number object? What are its key responsibilities?
  2. What is a Student object? What are its key responsibilities?
  3. What is a StudentObject object? What are its key responsibilities?
Feb 16 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Christopher Brandsdal | last post by:
Hi! I get an error when I run my code Is there any other way to get te information from my form? Heres the error I get and the code beneath. Line 120 is market with ''''''''''''Line...
8
by: Carel Lotz | last post by:
H We have ported our VB 6 application into VB .NET but are still integrating with a few COM + applications written in VB6 running on our application server (Win 2000 Server). We have the proxies...
5
by: Bob | last post by:
I am displaying a form with a datagrid populated from a select of database records which now exceed 12,000 when I select them all. The form displays just fine with all 12,000+ entries but when I...
1
by: Bob | last post by:
I am displaying a form with a datagrid populated from a select of database records which now exceed 12,000 when I select them all. The form displays just fine with all 12,000+ entries but when I...
6
by: B. Penn | last post by:
Hi, I was testing pointers and found that I could still dereference a pointer and access the value/variable it pointed to after deleting it, which confused me for "the variable it pointed to is...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: CM | last post by:
Hi there: I have a web project which can be open and run without problem. I didn't open the web application for a period and during which I didn't modified any IIS items, but now I cannot open any...
4
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service...
2
by: Christophe | last post by:
class A {} class B {} interface MyInterface { void method(A a); void method(B b); }
7
by: shanemh | last post by:
I'm starting out with c++ and for some reason I cant get my brain around this one: If I have the following: void Foo (someClass& x) {} int Main (void) {
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.