• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:31
CEST 13:31
KST 20:31
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 1 - Final Week6[ASL19] Finals Recap: Standing Tall12HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Esports World Cup 2025 - Brackets Revealed10Weekly Cups (July 7-13): Classic continues to roll4Team TLMC #5 - Submission extension3Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced7
StarCraft 2
General
The GOAT ranking of GOAT rankings Who will win EWC 2025? Weekly Cups (July 7-13): Classic continues to roll Esports World Cup 2025 - Brackets Revealed Team TLMC #5 - Submission extension
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event $5,100+ SEL Season 2 Championship (SC: Evo) WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
External Content
Mutation # 482 Wheel of Misfortune Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome
Brood War
General
Flash Announces (and Retracts) Hiatus From ASL BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Starcraft in widescreen A cwal.gg Extension - Easily keep track of anyone
Tourneys
[Megathread] Daily Proleagues Cosmonarchy Pro Showmatches CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile Nintendo Switch Thread Stormgate/Frost Giant Megathread CCLP - Command & Conquer League Project The PlayStation 5
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2025! Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 2024 - 2025 Football Thread NBA General Discussion NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 533 users

The Big Programming Thread - Page 98

Forum Index > General Forum
Post a Reply
Prev 1 96 97 98 99 100 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Son of Gnome
Profile Blog Joined October 2010
United States777 Posts
Last Edited: 2011-12-09 22:44:27
December 09 2011 22:43 GMT
#1941
Hey guys I am working on some homework my computer science homework and I can't for the life of me get this to work. I ma supposed to make a program that simulates a card game of some kind. I got most of the other functions working fine I believe but I can't get my moveCard function to work.

here is my current code.
+ Show Spoiler +
# Note: cards are represented as 2-character strings, e.g.,
# "2C", "9S", "QH", "TD", "AC"

from random import randint, shuffle

class DeckOfCards:
def __init__(self):
"""Initializes a new deck of cards."""
ranks = "23456789TJQKA"
suits = "CDHS"
self.cards = [r+s for r in ranks for s in suits]

def shuffle(self):
"""Shuffles the cards into a random order."""
shuffle(self.cards)

def dealCard(self):
"""Removes the top/last card in the deck & returns it."""
if self.numCards() > 0:
return self.cards.pop()
else:
return ""

def addCard(self, card):
"""Adds the specified card to the bottom/front of the deck."""
self.cards.insert(0, card)

def numCards(self):
"""Returns the number of cards remaining in the deck."""
return len(self.cards)

def __str__(self):
"""Returns the string representation of the deck."""
return ' '.join(self.cards)

#########

class RowOfCards:
def __init__(self):
"""Initializes an empty row (list) of cards."""
self.cards = []

def addAtEnd(self, card):
"""Adds the specified card to the end of the row (list)."""
self.cards.append(card)

def moveCard(self, card, numSpots):
"""Moves the specified card numSpots to the left."""
self.cards.index(card)
(i for i in list if card == self)
print i
self.cards.remove(i)
self.cards.insert(i - numSpots, card)


def numCards(self):
"""Returns the number of cards in the row (list)."""
return len.self.cards

def __str__(self):
"""Returns the string representation of the deck (list)."""
return ' '.join(self.cards)


here is all I have so far, from what I have seen and what my classmates say the other functions look fine its just moveCard that is no working.

here is the error message that occurs.
+ Show Spoiler +
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
row.moveCard('4C', 1)
File "C:/Users/pjlaweejay/Desktop/csc/python/cards1.py", line 55, in moveCard
(i for i in list if card == self)
TypeError: 'type' object is not iterable
>>> row.moveCard('4C', '1')
Whatever happens, happens
Son of Gnome
Profile Blog Joined October 2010
United States777 Posts
December 09 2011 23:02 GMT
#1942
I looked at it and I am lost by what type....
Whatever happens, happens
Millitron
Profile Blog Joined August 2010
United States2611 Posts
December 10 2011 02:40 GMT
#1943
On December 10 2011 07:43 Son of Gnome wrote:
Hey guys I am working on some homework my computer science homework and I can't for the life of me get this to work. I ma supposed to make a program that simulates a card game of some kind. I got most of the other functions working fine I believe but I can't get my moveCard function to work.

here is my current code.
+ Show Spoiler +
# Note: cards are represented as 2-character strings, e.g.,
# "2C", "9S", "QH", "TD", "AC"

from random import randint, shuffle

class DeckOfCards:
def __init__(self):
"""Initializes a new deck of cards."""
ranks = "23456789TJQKA"
suits = "CDHS"
self.cards = [r+s for r in ranks for s in suits]

def shuffle(self):
"""Shuffles the cards into a random order."""
shuffle(self.cards)

def dealCard(self):
"""Removes the top/last card in the deck & returns it."""
if self.numCards() > 0:
return self.cards.pop()
else:
return ""

def addCard(self, card):
"""Adds the specified card to the bottom/front of the deck."""
self.cards.insert(0, card)

def numCards(self):
"""Returns the number of cards remaining in the deck."""
return len(self.cards)

def __str__(self):
"""Returns the string representation of the deck."""
return ' '.join(self.cards)

#########

class RowOfCards:
def __init__(self):
"""Initializes an empty row (list) of cards."""
self.cards = []

def addAtEnd(self, card):
"""Adds the specified card to the end of the row (list)."""
self.cards.append(card)

def moveCard(self, card, numSpots):
"""Moves the specified card numSpots to the left."""
self.cards.index(card)
(i for i in list if card == self)
print i
self.cards.remove(i)
self.cards.insert(i - numSpots, card)


def numCards(self):
"""Returns the number of cards in the row (list)."""
return len.self.cards

def __str__(self):
"""Returns the string representation of the deck (list)."""
return ' '.join(self.cards)


here is all I have so far, from what I have seen and what my classmates say the other functions look fine its just moveCard that is no working.

here is the error message that occurs.
+ Show Spoiler +
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
row.moveCard('4C', 1)
File "C:/Users/pjlaweejay/Desktop/csc/python/cards1.py", line 55, in moveCard
(i for i in list if card == self)
TypeError: 'type' object is not iterable
>>> row.moveCard('4C', '1')

Where do you initialize "i"? I think your problem MIGHT be that you never define 'i', but I can't say with 100% certainty as I've never worked with Python.

If your other classmates say the other functions are good, what do they (or better yet, the proff) say about moveCard?
Who called in the fleet?
Demonhunter04
Profile Joined July 2011
1530 Posts
December 10 2011 03:36 GMT
#1944
Hi, I'm having difficulty with another program. Basically, I need to write a program that validates credit card numbers. The instructions require the numbers to be provided by user input and stored as long integers. However, since I'm on a 32-bit system, longs can't hold 13-16 digit credit card numbers. I tried to use a double, but on compilation it said "invalid operands for binary operation" for a modulus operation. What can I do?
"If you don't drop sweat today, you will drop tears tomorrow" - SlayerSMMA
Son of Gnome
Profile Blog Joined October 2010
United States777 Posts
December 10 2011 03:46 GMT
#1945
On December 10 2011 11:40 Millitron wrote:
Show nested quote +
On December 10 2011 07:43 Son of Gnome wrote:
Hey guys I am working on some homework my computer science homework and I can't for the life of me get this to work. I ma supposed to make a program that simulates a card game of some kind. I got most of the other functions working fine I believe but I can't get my moveCard function to work.

here is my current code.
+ Show Spoiler +
# Note: cards are represented as 2-character strings, e.g.,
# "2C", "9S", "QH", "TD", "AC"

from random import randint, shuffle

class DeckOfCards:
def __init__(self):
"""Initializes a new deck of cards."""
ranks = "23456789TJQKA"
suits = "CDHS"
self.cards = [r+s for r in ranks for s in suits]

def shuffle(self):
"""Shuffles the cards into a random order."""
shuffle(self.cards)

def dealCard(self):
"""Removes the top/last card in the deck & returns it."""
if self.numCards() > 0:
return self.cards.pop()
else:
return ""

def addCard(self, card):
"""Adds the specified card to the bottom/front of the deck."""
self.cards.insert(0, card)

def numCards(self):
"""Returns the number of cards remaining in the deck."""
return len(self.cards)

def __str__(self):
"""Returns the string representation of the deck."""
return ' '.join(self.cards)

#########

class RowOfCards:
def __init__(self):
"""Initializes an empty row (list) of cards."""
self.cards = []

def addAtEnd(self, card):
"""Adds the specified card to the end of the row (list)."""
self.cards.append(card)

def moveCard(self, card, numSpots):
"""Moves the specified card numSpots to the left."""
self.cards.index(card)
(i for i in list if card == self)
print i
self.cards.remove(i)
self.cards.insert(i - numSpots, card)


def numCards(self):
"""Returns the number of cards in the row (list)."""
return len.self.cards

def __str__(self):
"""Returns the string representation of the deck (list)."""
return ' '.join(self.cards)


here is all I have so far, from what I have seen and what my classmates say the other functions look fine its just moveCard that is no working.

here is the error message that occurs.
+ Show Spoiler +
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
row.moveCard('4C', 1)
File "C:/Users/pjlaweejay/Desktop/csc/python/cards1.py", line 55, in moveCard
(i for i in list if card == self)
TypeError: 'type' object is not iterable
>>> row.moveCard('4C', '1')

Where do you initialize "i"? I think your problem MIGHT be that you never define 'i', but I can't say with 100% certainty as I've never worked with Python.

If your other classmates say the other functions are good, what do they (or better yet, the proff) say about moveCard?


Prof isnt here atm and doesnt answer emails over the weekend. moveCard I think I may have figured out, right here.

+ Show Spoiler +
def moveCard(self, card, numSpots):
"""Moves the specified card numSpots to the left."""
abc = self.cards.index(card)
if abc - numSpots >= 0:
self.cards.insert(abc-numSpots, card)
self.cards.pop(abc+1)

My friend says there is an issue with it however, that is that the card doesn'nt get deleted. if four cards are in a list and you move one on top of another, there is still four cards. Not sure how to fix that however.
Whatever happens, happens
ClysmiC
Profile Blog Joined December 2010
United States2192 Posts
Last Edited: 2011-12-10 03:47:11
December 10 2011 03:46 GMT
#1946
On December 10 2011 12:36 Demonhunter04 wrote:
Hi, I'm having difficulty with another program. Basically, I need to write a program that validates credit card numbers. The instructions require the numbers to be provided by user input and stored as long integers. However, since I'm on a 32-bit system, longs can't hold 13-16 digit credit card numbers. I tried to use a double, but on compilation it said "invalid operands for binary operation" for a modulus operation. What can I do?

I don't know what language you're working in, but if you're working in Java, perhaps you could read in the numbers as a String and use a combination of substring and parseDouble to store the large number in two separate double variables, that you would validate separately.

(This is probably possible in other languages too, but I'm only in my first year of CS courses so I'm only familiar with Java atm)
Demonhunter04
Profile Joined July 2011
1530 Posts
December 10 2011 04:28 GMT
#1947
On December 10 2011 12:46 ClysmiC wrote:
Show nested quote +
On December 10 2011 12:36 Demonhunter04 wrote:
Hi, I'm having difficulty with another program. Basically, I need to write a program that validates credit card numbers. The instructions require the numbers to be provided by user input and stored as long integers. However, since I'm on a 32-bit system, longs can't hold 13-16 digit credit card numbers. I tried to use a double, but on compilation it said "invalid operands for binary operation" for a modulus operation. What can I do?

I don't know what language you're working in, but if you're working in Java, perhaps you could read in the numbers as a String and use a combination of substring and parseDouble to store the large number in two separate double variables, that you would validate separately.

(This is probably possible in other languages too, but I'm only in my first year of CS courses so I'm only familiar with Java atm)


Sorry I forgot to mention, I'm working in C. I have to use a long integer, and from what I found, longs hold up to 20 digits on 64 bit OSs. Is there any way to test if this program would work on a 64 bit OS without actually having access to one?
"If you don't drop sweat today, you will drop tears tomorrow" - SlayerSMMA
Son of Gnome
Profile Blog Joined October 2010
United States777 Posts
Last Edited: 2011-12-10 04:55:33
December 10 2011 04:55 GMT
#1948
Got that assignment done thank God lol. Stuck on this one now

+ Show Spoiler +
from cards import DeckOfCards, RowOfCards

def skip3():
"""Basic framework for playing Skip3 Solitaire."""
print "Welcome to Skip3 Solitaire."

deck = DeckOfCards()
deck.shuffle()
row = RowOfCards()

response = ""
while response != "q":
print row, "\n"

response = raw_input("Action? ")
responseWords = response.split()
firstLetter = responseWords[0][0].lower()

if firstLetter == "d":
row.addAtEnd(deck.dealCard())
else print "ERROR"
elif firstLetter == "m":
row.moveCard(responseWords[1].upper(), 1)
elif firstLetter == "s":
row.moveCard(responseWords[1].upper(), 3)
elif firstLetter == "q":
print "Thanks for playing."
print DeckOfCards()
else:
print "Unknown command"


I am trying to make it so if the rules arent fulfilled or the deck is empty the game presents an error message of some kind. I know I need to have the program read something I am just unsure of what and how to go about doing it.
Whatever happens, happens
Craton
Profile Blog Joined December 2009
United States17249 Posts
December 10 2011 05:00 GMT
#1949
An important part of homework is learning how to research your own problems. You'll never learn anything if you just ask for help every time.
twitch.tv/cratonz
tec27
Profile Blog Joined June 2004
United States3696 Posts
December 10 2011 05:02 GMT
#1950
On December 10 2011 14:00 Craton wrote:
An important part of homework is learning how to research your own problems. You'll never learn anything if you just ask for help every time.

Seriously.

This isn't the "I have a programming assignment, help me!" thread. If thats all your here for, please kindly leave. Just as TL is against homework threads, we are against mucking up perfectly good threads with all of your homework assignments.

And on top of everything else, you're posting a whitespace-significant language outside of code tags... sigh.
Can you jam with the console cowboys in cyberspace?
Son of Gnome
Profile Blog Joined October 2010
United States777 Posts
December 10 2011 05:05 GMT
#1951
I was just asking for help... Sorry if it offended anyone I'm kind of lost when it comes to this, and tend to look to the people of TL for advice sometimes sorry for that I guess....
Whatever happens, happens
Demonhunter04
Profile Joined July 2011
1530 Posts
December 10 2011 05:08 GMT
#1952
I know this isn't directed at me, but I've been doing tons of research and looking up of things for days. I came here as a last resort.
"If you don't drop sweat today, you will drop tears tomorrow" - SlayerSMMA
tec27
Profile Blog Joined June 2004
United States3696 Posts
Last Edited: 2011-12-10 05:20:28
December 10 2011 05:19 GMT
#1953
On December 10 2011 14:08 Demonhunter04 wrote:
I know this isn't directed at me, but I've been doing tons of research and looking up of things for days. I came here as a last resort.

Your posts are fine. Its easy to tell when someone has done their due diligence and when someone hasn't. My problem is with people that write up a simple program, come upon some problem and then immediately hop over to this thread to make someone else solve it for them. *Especially* if said problems are highly specific to a homework assignment and will be of little to no use to anyone else in the future.

As for your issue, you may want to try a 'long long'. I think its really weird to want to store a CC# like that, because although they are all numbers, they aren't really a number per se. Like, you wouldn't ever want to add 2 credit card numbers together, etc. Just like I wouldn't store a phone number as an int, I wouldn't store a CC# that way. But I guess you don't really have much choice in the matter
Can you jam with the console cowboys in cyberspace?
Demonhunter04
Profile Joined July 2011
1530 Posts
December 10 2011 05:51 GMT
#1954
On December 10 2011 14:19 tec27 wrote:
Show nested quote +
On December 10 2011 14:08 Demonhunter04 wrote:
I know this isn't directed at me, but I've been doing tons of research and looking up of things for days. I came here as a last resort.

Your posts are fine. Its easy to tell when someone has done their due diligence and when someone hasn't. My problem is with people that write up a simple program, come upon some problem and then immediately hop over to this thread to make someone else solve it for them. *Especially* if said problems are highly specific to a homework assignment and will be of little to no use to anyone else in the future.

As for your issue, you may want to try a 'long long'. I think its really weird to want to store a CC# like that, because although they are all numbers, they aren't really a number per se. Like, you wouldn't ever want to add 2 credit card numbers together, etc. Just like I wouldn't store a phone number as an int, I wouldn't store a CC# that way. But I guess you don't really have much choice in the matter


O_o I did not know you could create long longs. How exactly does that work?
"If you don't drop sweat today, you will drop tears tomorrow" - SlayerSMMA
tec27
Profile Blog Joined June 2004
United States3696 Posts
December 10 2011 06:53 GMT
#1955
On December 10 2011 14:51 Demonhunter04 wrote:
Show nested quote +
On December 10 2011 14:19 tec27 wrote:
On December 10 2011 14:08 Demonhunter04 wrote:
I know this isn't directed at me, but I've been doing tons of research and looking up of things for days. I came here as a last resort.

Your posts are fine. Its easy to tell when someone has done their due diligence and when someone hasn't. My problem is with people that write up a simple program, come upon some problem and then immediately hop over to this thread to make someone else solve it for them. *Especially* if said problems are highly specific to a homework assignment and will be of little to no use to anyone else in the future.

As for your issue, you may want to try a 'long long'. I think its really weird to want to store a CC# like that, because although they are all numbers, they aren't really a number per se. Like, you wouldn't ever want to add 2 credit card numbers together, etc. Just like I wouldn't store a phone number as an int, I wouldn't store a CC# that way. But I guess you don't really have much choice in the matter


O_o I did not know you could create long longs. How exactly does that work?

http://docs.freebsd.org/info/gcc/gcc.info.Long_Long.html

Was added to C in C99 I believe. Basically its a type thats guaranteed to be >= 64bit on any compiler. How it gets handled internally depends on the compiler/OS/machine, but that shouldn't matter too much for your purposes.
Can you jam with the console cowboys in cyberspace?
Millitron
Profile Blog Joined August 2010
United States2611 Posts
December 10 2011 19:19 GMT
#1956
On December 10 2011 15:53 tec27 wrote:
Show nested quote +
On December 10 2011 14:51 Demonhunter04 wrote:
On December 10 2011 14:19 tec27 wrote:
On December 10 2011 14:08 Demonhunter04 wrote:
I know this isn't directed at me, but I've been doing tons of research and looking up of things for days. I came here as a last resort.

Your posts are fine. Its easy to tell when someone has done their due diligence and when someone hasn't. My problem is with people that write up a simple program, come upon some problem and then immediately hop over to this thread to make someone else solve it for them. *Especially* if said problems are highly specific to a homework assignment and will be of little to no use to anyone else in the future.

As for your issue, you may want to try a 'long long'. I think its really weird to want to store a CC# like that, because although they are all numbers, they aren't really a number per se. Like, you wouldn't ever want to add 2 credit card numbers together, etc. Just like I wouldn't store a phone number as an int, I wouldn't store a CC# that way. But I guess you don't really have much choice in the matter


O_o I did not know you could create long longs. How exactly does that work?

http://docs.freebsd.org/info/gcc/gcc.info.Long_Long.html

Was added to C in C99 I believe. Basically its a type thats guaranteed to be >= 64bit on any compiler. How it gets handled internally depends on the compiler/OS/machine, but that shouldn't matter too much for your purposes.

That's pretty awesome.

Alternatively, you could see if C has an equivalent to Java's BigInteger class. Basically, it lets you make an integer practically as large as you want. I'm sure there IS a limit to how big they can be, but its so insanely high it shouldn't matter. Like, I used a BigInteger to store an enormous factorial, it was something like Factorial(16000). It's so efficient too, that the println() to display the int took longer to refresh than the Factorial function took to calculate.
Who called in the fleet?
nakam
Profile Joined April 2010
Sweden245 Posts
December 11 2011 22:32 GMT
#1957
So I'm trying to learn Java (through GWT) but I have a problem with extending classes that I don't understand:
+ Show Spoiler +
public class MainClass implements EntryPoint {
// [1]
MySubClass test = new MySubClass();

public void onModuleLoad() {
// [2]
...Some code...
}
public void someMethod() {
...Some code...
}
}


And here's the subclass:
+ Show Spoiler +
public class MySubClass extends MainClass {
protected MySubClass() {}
}

I need to have MySubClass extending my MainClass to be able to access the methods in MainClass. But if I use extends MainClass and instantiate the object MySubClass test in [1] I get

[ERROR] [ProjectName] - Failed to create an instance of 'com.google.gwt.projectname.client.MainClass' via deferred binding

when running the code. It does work when instantiating the object in [2], but I don't really want that. I don't see what the problem is and Eclipse seems to think everything is fine.
TL Local Timezone Script - http://www.teamliquid.net/forum/viewmessage.php?topic_id=277156
Millitron
Profile Blog Joined August 2010
United States2611 Posts
December 11 2011 22:49 GMT
#1958
On December 12 2011 07:32 nakam wrote:
So I'm trying to learn Java (through GWT) but I have a problem with extending classes that I don't understand:
+ Show Spoiler +
public class MainClass implements EntryPoint {
// [1]
MySubClass test = new MySubClass();

public void onModuleLoad() {
// [2]
...Some code...
}
public void someMethod() {
...Some code...
}
}


And here's the subclass:
+ Show Spoiler +
public class MySubClass extends MainClass {
protected MySubClass() {}
}

I need to have MySubClass extending my MainClass to be able to access the methods in MainClass. But if I use extends MainClass and instantiate the object MySubClass test in [1] I get

[ERROR] [ProjectName] - Failed to create an instance of 'com.google.gwt.projectname.client.MainClass' via deferred binding

when running the code. It does work when instantiating the object in [2], but I don't really want that. I don't see what the problem is and Eclipse seems to think everything is fine.

What is throwing the error? is it GWT throwing the error or is Eclipse?
Who called in the fleet?
nakam
Profile Joined April 2010
Sweden245 Posts
December 11 2011 22:57 GMT
#1959
On December 12 2011 07:49 Millitron wrote:
Show nested quote +
On December 12 2011 07:32 nakam wrote:
So I'm trying to learn Java (through GWT) but I have a problem with extending classes that I don't understand:
+ Show Spoiler +
public class MainClass implements EntryPoint {
// [1]
MySubClass test = new MySubClass();

public void onModuleLoad() {
// [2]
...Some code...
}
public void someMethod() {
...Some code...
}
}


And here's the subclass:
+ Show Spoiler +
public class MySubClass extends MainClass {
protected MySubClass() {}
}

I need to have MySubClass extending my MainClass to be able to access the methods in MainClass. But if I use extends MainClass and instantiate the object MySubClass test in [1] I get

[ERROR] [ProjectName] - Failed to create an instance of 'com.google.gwt.projectname.client.MainClass' via deferred binding

when running the code. It does work when instantiating the object in [2], but I don't really want that. I don't see what the problem is and Eclipse seems to think everything is fine.

What is throwing the error? is it GWT throwing the error or is Eclipse?

That I cannot really answer. I'm running Eclipse in hosted mode and I get the error when I'm loading the page in the browser (error shows up in Eclipse log).
TL Local Timezone Script - http://www.teamliquid.net/forum/viewmessage.php?topic_id=277156
Millitron
Profile Blog Joined August 2010
United States2611 Posts
December 11 2011 23:18 GMT
#1960
On December 12 2011 07:57 nakam wrote:
Show nested quote +
On December 12 2011 07:49 Millitron wrote:
On December 12 2011 07:32 nakam wrote:
So I'm trying to learn Java (through GWT) but I have a problem with extending classes that I don't understand:
+ Show Spoiler +
public class MainClass implements EntryPoint {
// [1]
MySubClass test = new MySubClass();

public void onModuleLoad() {
// [2]
...Some code...
}
public void someMethod() {
...Some code...
}
}


And here's the subclass:
+ Show Spoiler +
public class MySubClass extends MainClass {
protected MySubClass() {}
}

I need to have MySubClass extending my MainClass to be able to access the methods in MainClass. But if I use extends MainClass and instantiate the object MySubClass test in [1] I get

[ERROR] [ProjectName] - Failed to create an instance of 'com.google.gwt.projectname.client.MainClass' via deferred binding

when running the code. It does work when instantiating the object in [2], but I don't really want that. I don't see what the problem is and Eclipse seems to think everything is fine.

What is throwing the error? is it GWT throwing the error or is Eclipse?

That I cannot really answer. I'm running Eclipse in hosted mode and I get the error when I'm loading the page in the browser (error shows up in Eclipse log).

Can you run it in Eclipse in its normal, not-hosted, mode? If it runs fine on Eclipse locally, then I think you're problem is something to do the interaction between Eclipse and GWT. I know I've had problems before trying to run certain programs from within the IDE; Visual Studio 2007 for instance almost never can load image maps without crashing, because its built-in debugger gets in the way. If you don't get this problem when you run your code locally, rather than on a hosted Eclipse, then it would seem GWT is getting in the way, in the same way the debugger did in my example.
Who called in the fleet?
Prev 1 96 97 98 99 100 1031 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
10:00
Galaxy Open Cup Season 1
CranKy Ducklings129
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 327
StarCraft: Brood War
BeSt 7453
Rain 5035
Mini 909
Light 788
Pusan 730
Zeus 581
Rush 412
Larva 379
firebathero 289
Mind 281
[ Show more ]
EffOrt 237
sSak 56
Shinee 48
Shine 26
NaDa 24
JulyZerg 20
Movie 17
Icarus 17
scan(afreeca) 15
yabsab 11
Noble 8
Bale 7
Dota 2
qojqva2638
XaKoH 541
XcaliburYe375
canceldota130
League of Legends
Dendi989
JimRising 366
Counter-Strike
shoxiejesuss806
x6flipin619
sgares606
byalli228
allub201
PGG 74
Super Smash Bros
Mew2King114
Other Games
singsing1574
B2W.Neo1516
DeMusliM370
crisheroes319
Fuzer 250
Pyrionflax179
SortOf124
Lowko113
Trikslyr29
markeloff13
ArmadaUGS12
Organizations
Other Games
gamesdonequick3692
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH341
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2156
League of Legends
• Jankos789
Upcoming Events
WardiTV European League
4h 29m
ShoWTimE vs sebesdes
Percival vs NightPhoenix
Shameless vs Nicoract
Krystianer vs Scarlett
ByuN vs uThermal
Harstem vs HeRoMaRinE
PiGosaur Monday
12h 29m
uThermal 2v2 Circuit
1d 4h
Replay Cast
1d 12h
The PondCast
1d 22h
WardiTV European League
2 days
Replay Cast
2 days
Epic.LAN
3 days
CranKy Ducklings
3 days
Epic.LAN
4 days
[ Show More ]
CSO Contender
4 days
BSL20 Non-Korean Champi…
4 days
Bonyth vs Sziky
Dewalt vs Hawk
Hawk vs QiaoGege
Sziky vs Dewalt
Mihu vs Bonyth
Zhanhun vs QiaoGege
QiaoGege vs Fengzi
Sparkling Tuna Cup
4 days
Online Event
5 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs Zhanhun
Dewalt vs Mihu
Hawk vs Sziky
Sziky vs QiaoGege
Mihu vs Hawk
Zhanhun vs Dewalt
Fengzi vs Bonyth
Esports World Cup
6 days
ByuN vs Astrea
Lambo vs HeRoMaRinE
Clem vs TBD
Solar vs Zoun
SHIN vs Reynor
Maru vs TriGGeR
herO vs Lancer
Cure vs ShoWTimE
Liquipedia Results

Completed

2025 ACS Season 2: Qualifier
RSL Revival: Season 1
Murky Cup #2

Ongoing

JPL Season 2
BSL 2v2 Season 3
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
BSL20 Non-Korean Championship
Championship of Russia 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters

Upcoming

CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
BSL Season 21
K-Championship
RSL Revival: Season 2
SEL Season 2 Championship
uThermal 2v2 Main Event
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.