• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Calling a method  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to call a method from a Student class that calculates a hash code for a Storage class.I am getting a cannot resolve symbol error in the Storage class and can see nothing wrong with the line.It's probably something minor but I need another set of eyes.
Cheers.
The code:

public class Student
{
String name;
String course;
int hashIndex;
public Student(String name,String course)
{

this.name = name;
this.course = course;

}

public String getName()

{

return name;
}

public String getCourse()

{
return course;

}

public int calcHash(int maxNum)

{
int hashTotal = 0;
int hashIndex = 0;
for(int i = 0; i<name.length();i++)
{

char letter = name.charAt(i);
int asciiValue = letter;
hashTotal = hashTotal + asciiValue;
hashIndex = hashTotal % maxNum;
}

return hashIndex;
}
}
public class Storage
{

int maxNum = 4;
Storage Store = new Storage();
Storage StArray[] = new Storage[4];
public void getHash(String name[])
{
for(int hashIndex=0;hashIndex<maxNum;hashIndex++)
StArray[hashIndex]=Store.calcHash(maxNum);

}
}
I am getting the error;:
Storage.java:10:cannot resolve symbol
symbol :method calcHash (int)
location:class Storage
StArray[hashIndex]=Store.calcHash(maxNum);
 
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Storage class does not have a calcHash() method.

Henry
 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see a few things:

- The method calchash appears to be a method of class Student, yet you're invoking it as though it were a method of class Storage.

- I recommend using lower case names for objects because seeing an upper case name makes me think "oh, that's a class, so it must be a static method call", when in fact it's not. This is standard coding convention in Java.

- I see no main method to run this from.

- Please please use UBB CODE tags to enclose your code excerpts. Doing so preserves the formatting, making the code much easier to read.

Hope that helps. Good luck!
 
Alan Arkwell
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry here is the main method.

import javax.swing.JOptionPane;
public class MainProg
{
public static void main(String[] args)
{

String[] name = new String[4];
String[] course = new String[4];
int lp = 0;
int maxNum = 4;
System.out.println("Name\t\t\tCourse");

for(lp=0;lp<name.length;lp++)
{

name[lp] = JOptionPane.showInputDialog("Enter name");
}

for(lp=0;lp<course.length;lp++)
{

course[lp] = JOptionPane.showInputDialog("Enter course");

}
for(lp=0;lp<4;lp++)
{
System.out.println(name[lp]+"\t\t"+course[lp]);

}

System.exit(0);
}


}
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he meant you should actually put your code inside the code tags. But anyway, the problem is not in the main method it's as has been described. The calcHash method is in Student, but you calling it as if it's in Storage. So when it looks for calcHash in Storage it can't find it and gives you the error you see.
 
Alan Arkwell
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I see that now....sorry about the tags!!
 
Alan Arkwell
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried using a Student object instead.Doesn't seem to work
Error is:
Student(java.lang.String.jav.lang.String)in Student cannot be applied to()
Student stud = new Student();
^
class Storage
{

int maxNum = 4;
Student stud = new Student();
Storage StArray[] = new Storage[4];
public void getHash(String name[])
{

for(int hashIndex=0;hashIndex<maxNum;hashIndex++)
StArray[hashIndex]=stud.calcHash(maxNum);

}
}
 
Alan Arkwell
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll sort the tabs out eventually by the way
Alan
 
Henry Wong
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Student(java.lang.String.jav.lang.String)in Student cannot be applied to()
Student stud = new Student();



Take a look at your own source code... You designed student to take a name and a course.

Henry
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!