7 Replies - 2637 Views - Last Post: 19 October 2012 - 11:16 AM Rate Topic: -----

#1 Pahan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-October 12

when I compile "class, interface or enum expected " error app

Posted 18 October 2012 - 09:30 PM

when I compile "class, interface or enum expected " error appears.what is this error?I'm really new to java.
Is This A Good Question/Topic? 0
  • +

Replies To: when I compile "class, interface or enum expected " error app

#2 SwiftStriker00  Icon User is offline

  • No idea why my code works
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,599
  • Joined: 25-December 08

Re: when I compile "class, interface or enum expected " error app

Posted 18 October 2012 - 11:21 PM

Without posting your code its hard to say. Take a look at this tutorial i made (specifically number 10):


Java Errors, A Beginners Guide

This post has been edited by SwiftStriker00: 18 October 2012 - 11:22 PM

Was This Post Helpful? 0
  • +
  • -

#3 lameraz  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 07-May 10

Re: when I compile "class, interface or enum expected " error app

Posted 19 October 2012 - 01:50 AM

Check if you have all imports.
- missing semicolon ";"
- forgot or mis-spelled words

Compiler will tell you in which line the error is.
Was This Post Helpful? 0
  • +
  • -

#4 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: when I compile "class, interface or enum expected " error app

Posted 19 October 2012 - 08:10 AM

You really need to post your code in order to get some accurate help...

In Java everything is an object... And looking at the error you got, I think you are using a data member or a method out of a class, enum, or interface... That is, they are not inside any of them, or perhaps you might have got a wrong syntax declaring them...

Hope This Helps!
Was This Post Helpful? 1
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7958
  • View blog
  • Posts: 13,571
  • Joined: 19-March 11

Re: when I compile "class, interface or enum expected " error app

Posted 19 October 2012 - 08:21 AM

View PostAKMafia001, on 19 October 2012 - 10:10 AM, said:

You really need to post your code in order to get some accurate help...

And looking at the error you got, I think you are using a data member or a method out of a class, enum, or interface... That is, they are not inside any of them, or perhaps you might have got a wrong syntax declaring them...


Correct on both counts.

Quote

In Java everything is an object...


This is not exactly true. There's a distinction between objects, primitives, and methods. Primitives are simple values, like 1, 4.5, 'a', or true. Methods are bundles of functionality which can perform actions (working on objects or primitives) and evaluate to a single value or to no value (ie, void). Objects are composed bundles of data and funcitonality, built up of primitives and methods and other objects (which can be instances of the same object).

In java, these are all quite different. for example, 1.add(5) returns an error in Java, because primitives don't have methods like objects do, and you can't pass a method as a value in java because methods are not "first-class citizens" in Java. This is not the case in all languages.
This is all tangential, of course, but interesting.
Was This Post Helpful? 1
  • +
  • -

#6 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: when I compile "class, interface or enum expected " error app

Posted 19 October 2012 - 10:50 AM

jon.kiparsky, You are correct. I think I meant to say that things conclude to objects in java, maybe. Like we create some interfaces and implement them in classes, classes have their own stuff too and in the end they are encapsulated... Hence, maybe the correct statement would be, In Java everything is bundled into a class. Which would be true for the context of the OP.

Thanks...
Was This Post Helpful? 1
  • +
  • -

#7 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7958
  • View blog
  • Posts: 13,571
  • Joined: 19-March 11

Re: when I compile "class, interface or enum expected " error app

Posted 19 October 2012 - 10:56 AM

Quote

Hence, maybe the correct statement would be, In Java everything is bundled into a class.


I see what you're saying now. Yes, this is definitely true: everything in Java lives in a class.
So what you mean is that you can't have a variable declared outside of the scope of a class definition - this is correct, and it would certainly cause the cited error.
Was This Post Helpful? 1
  • +
  • -

#8 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: when I compile "class, interface or enum expected " error app

Posted 19 October 2012 - 11:16 AM

View Postjon.kiparsky, on 19 October 2012 - 10:56 PM, said:

So what you mean is that you can't have a variable declared outside of the scope of a class definition - this is correct, and it would certainly cause the cited error.


Yup that's what I meant... ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1