• Post Reply Bookmark Topic Watch Topic
  • New Topic

int cannot be referenced  RSS feed

 
Chris Domang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hidey ho! i'm trying out this new program and i can't seem to get past one particular debug error: the "int cannot be dereferenced error" when using the toString() method. my abilities in java are "begginer" at best by the way (if that isn't obvious by the code below). here's the code:

import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.applet.*;
import java.awt.*;

public class chrisdreqAPPLET extends Applet
{
public void paint(Graphics grap)
{
int blarG;
Date presentDate = new Date(); //declaration, variable, construction
Calendar myFormat = new GregorianCalendar(); //declaration, variable, construction with modifer
blarG = 288 - myFormat.get(Calendar.DAY_OF_YEAR);
grap.drawString("Omnipen Inc.",150,70);
grap.drawString("Sorry, our page is not yet operational.",140,120);
grap.drawString("The expected date of completion is October 15, or " + blarG.toString() + " days from today.",130,130);
}
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

Welcome to JavaRanch!

In Java, to dereference a variable "x" basically means to write "x dot something". You've dereferenced "blarG" by calling an imaginary method blarG.toString() . ints don't have methods, and they can't be dereferenced; hence the message.

First, to fix this error: just use blarG in place of blarG.toString(). The "+" operator knows how to catenate Strings with ints, double, longs, and every other data type, so this will work fine.

Second, please run, don't walk, over here and read our JavaRanch Campfire Story about Java variables -- it'll larn ya right.
 
Chris Domang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest, you are a god among men.

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