473,326 Members | 2,175 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,326 software developers and data experts.

denotes 'field' where 'class' expected error

Hello All:

I have created the following field within a class definition:

Class User
{
// fields
private RoleInfo roleInfo =
RoleInfo.GetRoleInfo(Thread.CurrentPrincipal.Ident ity.Name);

// remaining class definition
. . .
}

In a method defined in the User class, I attempt to invoke a method on the
roleInfo object:

// method in user class
public static User NewUser()
{
boolean Result = roleInfo.RolePrivilegeInfoCollection.Includes("Use r",
"Add")

// remaining method
. . .
}

When I attempt to compile the above method, I receive an error message
stating that "roleInfo denotes a field where a class was expected". I
notice that if RoleInfo is instantiated in the NewUser method instead of as
a field within the User class, the code compiles fine - but I would prefer
to only create one instance of RoleInfo that can be used throughout the User
class instead of creating an instance each time it is needed.

Any ideas on what may be causing this error?

Thanks!

Chris
Nov 15 '05 #1
4 4840
Hi.

You are trying to access an instance field (roleInfo) from a static method.

I think you should declare the roleInfo field as static.

Have a nice day
GV
"ChrisB" <pl****************@thanks.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hello All:

I have created the following field within a class definition:

Class User
{
// fields
private RoleInfo roleInfo =
RoleInfo.GetRoleInfo(Thread.CurrentPrincipal.Ident ity.Name);

// remaining class definition
. . .
}

In a method defined in the User class, I attempt to invoke a method on the
roleInfo object:

// method in user class
public static User NewUser()
{
boolean Result = roleInfo.RolePrivilegeInfoCollection.Includes("Use r",
"Add")

// remaining method
. . .
}

When I attempt to compile the above method, I receive an error message
stating that "roleInfo denotes a field where a class was expected". I
notice that if RoleInfo is instantiated in the NewUser method instead of as a field within the User class, the code compiles fine - but I would prefer
to only create one instance of RoleInfo that can be used throughout the User class instead of creating an instance each time it is needed.

Any ideas on what may be causing this error?

Thanks!

Chris

Nov 15 '05 #2
Your NewUser method is static and the field roleInfo is non-static. static
methods can only see other static methods and fields. I assume you meant
roleInfo to be static as well?

Regards
Lee

"ChrisB" <pl****************@thanks.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hello All:

I have created the following field within a class definition:

Class User
{
// fields
private RoleInfo roleInfo =
RoleInfo.GetRoleInfo(Thread.CurrentPrincipal.Ident ity.Name);

// remaining class definition
. . .
}

In a method defined in the User class, I attempt to invoke a method on the
roleInfo object:

// method in user class
public static User NewUser()
{
boolean Result = roleInfo.RolePrivilegeInfoCollection.Includes("Use r",
"Add")

// remaining method
. . .
}

When I attempt to compile the above method, I receive an error message
stating that "roleInfo denotes a field where a class was expected". I
notice that if RoleInfo is instantiated in the NewUser method instead of as a field within the User class, the code compiles fine - but I would prefer
to only create one instance of RoleInfo that can be used throughout the User class instead of creating an instance each time it is needed.

Any ideas on what may be causing this error?

Thanks!

Chris

Nov 15 '05 #3
Yes, that was the issue.

Thanks,
Chris

"Gianluca Varenni" <va*****@polito.it> wrote in message
news:QX********************@news4.tin.it...
Hi.

You are trying to access an instance field (roleInfo) from a static method.
I think you should declare the roleInfo field as static.

Have a nice day
GV
"ChrisB" <pl****************@thanks.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hello All:

I have created the following field within a class definition:

Class User
{
// fields
private RoleInfo roleInfo =
RoleInfo.GetRoleInfo(Thread.CurrentPrincipal.Ident ity.Name);

// remaining class definition
. . .
}

In a method defined in the User class, I attempt to invoke a method on the roleInfo object:

// method in user class
public static User NewUser()
{
boolean Result = roleInfo.RolePrivilegeInfoCollection.Includes("Use r", "Add")

// remaining method
. . .
}

When I attempt to compile the above method, I receive an error message
stating that "roleInfo denotes a field where a class was expected". I
notice that if RoleInfo is instantiated in the NewUser method instead of

as
a field within the User class, the code compiles fine - but I would prefer to only create one instance of RoleInfo that can be used throughout the

User
class instead of creating an instance each time it is needed.

Any ideas on what may be causing this error?

Thanks!

Chris


Nov 15 '05 #4

"Gianluca Varenni" <va*****@polito.it> wrote in message
news:QX********************@news4.tin.it...
Hi.

You are trying to access an instance field (roleInfo) from a static method.
I think you should declare the roleInfo field as static.

Have a nice day
GV
"ChrisB" <pl****************@thanks.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hello All:

I have created the following field within a class definition:

Class User
{
// fields
private RoleInfo roleInfo =
RoleInfo.GetRoleInfo(Thread.CurrentPrincipal.Ident ity.Name);

// remaining class definition
. . .
}

In a method defined in the User class, I attempt to invoke a method on the roleInfo object:

// method in user class
public static User NewUser()
{
boolean Result = roleInfo.RolePrivilegeInfoCollection.Includes("Use r", "Add")

// remaining method
. . .
}

When I attempt to compile the above method, I receive an error message
stating that "roleInfo denotes a field where a class was expected". I
notice that if RoleInfo is instantiated in the NewUser method instead of

as
a field within the User class, the code compiles fine - but I would prefer to only create one instance of RoleInfo that can be used throughout the

User
class instead of creating an instance each time it is needed.

Any ideas on what may be causing this error?

Thanks!

Chris


Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Heavey | last post by:
I create a class which would hold my static methods (methods I want to call without having to instantiate the class). I then attempted to use it in another class and I get the following error...
4
by: loserdude84 | last post by:
Hi I keep getting the good old error 'Object Expected Error' on a site I recently built. I am really struggling with this one. Object Expected Error Line 66 <div...
10
Dököll
by: Dököll | last post by:
I don't want you nice guys to waste your too much of your time, and confused me in the process. I am hoping you can explain it to me like I am 2 years old, that's it. Hoping to get a handle...
1
by: finizaini | last post by:
I'm receiving an "Object Expected" Error (Line:309, Char:0). I'm confused as to what is happening.Also, I can't run this code using other browser such as Fire Fox. Thispage only can view using IE....
2
by: camzgon121 | last post by:
Hi guys, I have this code and when I try to compile and run it gives me an <identifier> expected error. The code with the irrelevant parts taken out. package ACCOUNT; import...
2
by: tridirk | last post by:
Hi; I am getting a Objceted Expected Error on my forum site. I can't find what is wrong? Line: Char: Error: Object expected Code:0 the site is My SMF Forum
4
by: krinz10 | last post by:
Hi, I am doing an apartment rentals program but i need to bubble sort the array of a user defined class customerDetails (this entails all the details of the customer) However, when i am calling that...
0
by: kirthi kumari | last post by:
i donot find any errors,but for almost 18lines of the code am getting an error saying "class,interface or enum expected error".please look at the code below package NQ; import...
1
by: Alex Dransfield | last post by:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace FindFactors { class Program {
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.