473,473 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

non static error message need help thanx guys

5 New Member
hi there guys
im currently doing an assessment and have found this non static error which im stuck at here is my code for the class i know its ugly lol but the teacher started us off lol

public class Player
{
private String name;
private World world;
private int unplacedArmies;
private int placedArmies;
private int turn;

public Player(String name, World world)
{
placedArmies();
unplacedArmies();
startTurn();
name();
}

/**
* Return the number of territories that this player owns.
*/
(ignore this bit ) public int territoryCount()
{
// You should not modify this method.
//
// Note: This code is very ugly because we haven't learnt about
// arrays and loops yet.
//
// You should NEVER write code like this! ;-)
//
int count = 0;
if (world.africa().territory1().owner() == this) count++;
if (world.africa().territory2().owner() == this) count++;
if (world.africa().territory3().owner() == this) count++;
if (world.africa().territory4().owner() == this) count++;
if (world.euroAsia().territory1().owner() == this) count++;
if (world.euroAsia().territory2().owner() == this) count++;
if (world.euroAsia().territory3().owner() == this) count++;
if (world.euroAsia().territory4().owner() == this) count++;
if (world.australia().territory1().owner() == this) count++;
if (world.australia().territory2().owner() == this) count++;
if (world.australia().territory3().owner() == this) count++;
if (world.australia().territory4().owner() == this) count++;
if (world.northAmerica().territory1().owner() == this) count++;
if (world.northAmerica().territory2().owner() == this) count++;
if (world.northAmerica().territory3().owner() == this) count++;
if (world.northAmerica().territory4().owner() == this) count++;
if (world.southAmerica().territory1().owner() == this) count++;
if (world.southAmerica().territory2().owner() == this) count++;
if (world.southAmerica().territory3().owner() == this) count++;
if (world.southAmerica().territory4().owner() == this) count++;

return count;
}




public void startTurn()
{
turn++;
unplacedArmies = (territoryCount() /3);
System.out.println(name + "'s turn #" + turn++);
System.out.println("you have" + placedArmies + "armies placed.");
System.out.println("you have" + unplacedArmies + "armies to be placed.");
}

(this is where the error is)
public void placeArmy(Territory territory)
{
placedArmies = placedArmies + 1;
unplacedArmies = unplacedArmies - 1;
Territory.armies() = Territory.armies() + 1; }

the last line is where i get the message saying "non static error armies() cannot be referenced from a static context

public void attack(Territory myTerritory, Territory enemyTerritory)
{
}

public String name()
{
return name;
}

public int placedArmies()
{
return placedArmies = 0;
}

public int unplacedArmies()
{
return unplacedArmies = 6;
}
}
Apr 8 '08 #1
2 1393
Laharl
849 Recognized Expert Contributor
Assuming that your Territory class has a method called armies(), you can't call it that way unless it's declared with the static keyword (don't do that unless you know what it means). Instead, create an instance and then call the method.

Expand|Select|Wrap|Line Numbers
  1. Territory t = new Territory();
  2. t.armies();
  3.  
Apr 8 '08 #2
BigDaddyLH
1,216 Recognized Expert Top Contributor
Also realize that in that method Territory is the class and territory with a small 't' is the reference. Java is case-sensitive.
Apr 8 '08 #3

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

Similar topics

5
by: Phil Powell | last post by:
select event_date, event_name, event_text, event_is_public, event_is_reserved, event_img_path, event_img_alt, event_member_id, event_is_email_notify from event where show_entry = '1' and...
4
by: raghavendra | last post by:
Hi , A static member can be accessed only by another static method....but the vice-versa is not true....Can anyone pls explain me the logic behind this... Also in a project, if we have too many...
2
by: Lady_A | last post by:
Hi, I need to add a reference to a static library (*.lib) to a COM/ATL project in VS.NET. Apparently if this library is not in my solution that is not possible using the ordinary way : Add...
12
by: dual0 | last post by:
Hello, I found some function like void static foo(...){ .... } what does the static keyword stand for? what is a static function?
3
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /*...
17
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
1
by: toefraz | last post by:
Hey, guys. I have an assignment to work with static data members with numbers. I've done all the programming needed, but I keep getting this error when I try to compile: 1>Number.obj : error...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.