Java Compiler Error Int Cannot Be Dereferenced
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of int cannot be dereferenced tostring this site About Us Learn more about Stack Overflow the company Business Learn int cannot be dereferenced meaning more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question int cannot be dereferenced compareto x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up
Int Cannot Be Dereferenced Length
Error of int cannot be dereferenced? up vote 0 down vote favorite I am getting an error with this constructor, and i have no idea how to fix? I am a beginner at java. This is from an example exercise that i was trying to learn: /** * Create an array of size n and store a copy of the contents of the * int cannot be dereferenced equals java input argument * @param intArray array of elements to copy */ public IntArray11(int[] intArray) { int i = 0; String [] Array = new String[intArray.length]; for(i=0; i
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the boolean cannot be dereferenced java company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Int Cannot Be Converted To String
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million
Int Cannot Be Dereferenced Hashcode
programmers, just like you, helping each other. Join them; it only takes a minute: Sign up New to Java and have the error “int cannot be dereferenced” up vote 5 down vote favorite I'm new to http://stackoverflow.com/questions/28213083/error-of-int-cannot-be-dereferenced java and I've been working on this exercise for a while, but keep receiving the error: int cannot be dereferenced. I saw couple of similar questions but still cannot figure out my own case. Here is the complete codes: package inclass; class OneInt { int n; OneInt(int n) { this.n = n; } @Override public boolean equals(Object that) { if (that instanceof OneInt) { OneInt thatInt = (OneInt) that; return n.equals(thatInt.n); // error happens http://stackoverflow.com/questions/15857377/new-to-java-and-have-the-error-int-cannot-be-dereferenced here } else { return false; } } public static void main(String[] args) { Object c = new OneInt(9); Object c2 = new OneInt(9); System.out.println(c.equals(c2)); System.out.println(c.equals("doesn't work")); } } Thank you very much for helping me with this little trouble. java share|improve this question edited Apr 7 '13 at 0:08 paulsm4 57.5k67192 asked Apr 7 '13 at 0:04 Tian 3313 add a comment| 2 Answers 2 active oldest votes up vote 7 down vote accepted equals is a method of a class. int is a primitive, not a class. Simply use == instead: return n == thatInt.n; share|improve this answer answered Apr 7 '13 at 0:06 Dukeling 36.4k94080 add a comment| Did you find this question interesting? Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox (see an example). Subscribed! Success! Please click the link in the confirmation email to activate your subscription. up vote 4 down vote To compare ints, just use the == operator: if (n == thatInt.n) Note that int is not a class, so you can never use the . operator with an int variable. share|improve this answer answered Apr 7 '13 at 0:06 Code-Apprentice 27.6k353121 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Goo
MUZ140721 Bothwell Nhidza MUZ140721 Bothwell Nhidza 4,286 https://teamtreehouse.com/community/int-cannot-be-dereferenced Points Int cannot be dereferenced I am trying to convert the above code to string but all methods are producing an http://www.dreamincode.net/forums/topic/249301-int-cannot-be-dereferenced-method-not-working/ error LandingActivity.java import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class LandingActivity extends Activity { public Button mThrustButton; public TextView cannot be mTypeLabel; public EditText mPassengersField; public Spaceship mSpaceship; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_landing); mThrustButton = (Button)findViewById(R.id.thrustButton); mTypeLabel = (TextView)findViewById(R.id.typeTextView); mPassengersField = (EditText)findViewById(R.id.passengersEditText); mSpaceship=new Spaceship("FIREFLY"); mTypeLabel.setText(mSpaceship.getType()); mPassengersField.setText((mSpaceship.getNumPassengers()).toString()); // Add your code here! } } Spaceship.java public class Spaceship { private String mType; int cannot be private int mNumPassengers = 0; public String getType() { return mType; } public void setType(String type) { mType = type; } public int getNumPassengers() { return mNumPassengers; } public void setNumPassengers(int numPassengers) { mNumPassengers = numPassengers; } public Spaceship() { mType = "SHUTTLE"; } public Spaceship(String type) { mType = type; } } Evan Anger Treehouse Guest Teacher Evan Anger Evan Anger Treehouse Guest Teacher >1y ago Doing a quick pass through on the code, can you call out what line of code is giving you the "Int cannot be deferenced" compile error? This will aid others in helping with a solution. 1 Answer James Simshaw 28,723 Points James Simshaw James Simshaw 28,723 Points over 1 year ago Hello, ints are a primative type and
1 of 1 New Topic/Question Reply 3 Replies - 3610 Views - Last Post: 30 September 2011 - 03:34 PM Rate Topic: #1 qwertyer New D.I.C Head Reputation: 0 Posts: 2 Joined: 30-September 11 int cannot be dereferenced (Method not working) Posted 30 September 2011 - 03:11 PM I don't have a class in java anymore, so I was just trying out a problem for fun. It turns out I don't remember as much as I'd like. Could someone help figure out what I'm doing wrong? I don't understand how to make the method .isLegal work. public class Legal { public boolean isLegal(int n) { boolean legal = false; if (n>=3&&n<=8) legal = true; return legal; } public static void main(String[] args) { int x; x.isLegal(3); //error here int cannot be dereferenced } } Is This A Good Question/Topic? 0 Back to top MultiQuote Quote + Reply Replies To: int cannot be dereferenced (Method not working) #2 GregBrannon D.I.C Lover Reputation: 2250 Posts: 5,340 Joined: 10-September 10 Re: int cannot be dereferenced (Method not working) Posted 30 September 2011 - 03:16 PM Interesting error that I haven't seen before. There are several problems, but it's difficult to say which are applicable without knowing what you were trying to do. This is one way to make it work, but I'm not sure it's what you mean to do. public class Legal { public static boolean isLegal(int n) { boolean legal = false; if (n>=3&&n<=8) legal = true; return legal; } public static void main(String[] args) { boolean x; x = Legal.isLegal(3); } } Or, maybe you meant: public class Legal { public boolean isLegal(int n) { boolean legal = false; if (n>=3&&n<=8) legal = true; return legal; } public static void main(String[] args) { Legal x = new Legal(); boolean y = x.isLegal(3); } } This post has been edited by GregBrannon: 30 September 2011 - 03:21 PM Was This Post Helpful? 1 Back to top MultiQuote Quote + Reply #3 Fuzzyness Comp Sci Student Reputation: 669 Posts: 2,438 Joined: 06-March 0