• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

file cannot be resolved to a type  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys, I have a Problem with this class. Eclipse says:

Multiple markers at this line
- Return type for the method is
missing
- file cannot be resolved to a
type





the rest seems to be ok, as Eclipse shows no mistakes:


// Snip large piece of code


Can you give me please give me a hint so that I can run the program???
 
Sheriff
Posts: 23866
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is the signature of your method? Then just look at it. The name of the method is "File". What type does it return? You don't say. Perhaps you meant it should return a File? If so, then you need to give the method a name. Or if you don't want it to return anything, you should declare it as "public void".

And its parameter is of type "file". Where do you import that? It isn't part of the standard Java API. Perhaps you meant "File" instead of "file"? They aren't the same thing.

That was what the two error messages meant. You don't have to look at the other 300 lines of code for that.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I edited your post because there is no need to post that much code. The first example was plenty. You are defining a method without a return type which isn't possible unless it's an constructor.
 
Sheriff
Posts: 21463
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

enrique garcia wrote:


If I read this one line, without anything else, I see this as:
- a constructor
- of a class called File
- with a parameter of type file
- called dir

Now I doubt this is what you want. First of all, you call methods on dir that I recognize from java.io.File. So that should be "public File(File dir)". The other error tells me that this is not a constructor at all. In other words, the class this code is in is not called File. So you must either make it a constructor of the class, or add a return type. In this case, "void" would seem to fit. You then get "public void File(File dir)". While this should compile I still recommend you rename that method, for two reasons:
1) method names should start with a lowercase letter.
2) it will cause confusion with the File class you are using.
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, so I changed the name into QuizKarte



unfortunately the Eclipse seems to complain now with this message:

QuizKarte cannot be resolved to a variable



but there is a class called QuizKarte with strings in it, at the beginning of the code?!
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sourcecode
 
author
Posts: 23811
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

enrique garcia wrote:

QuizKarte cannot be resolved to a variable



but there is a class called QuizKarte with strings in it, at the beginning of the code?!



Eclipse is likely complaining about line 8. You are using a variable name QuizKarte, and you don't seem to have a declaration for it. And classes and variables are two different things -- just because you have a class name QuizKarte doesn't mean that there is an implicite instance of it somewhere.

Henry
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this means I have to cast QuizKarte somehow, right?

Eclipse is likely complaining about line 8. You are using a variable name QuizKarte, and you don't seem to have a declaration for it. And classes and variables are two different things -- just because you have a class name QuizKarte doesn't mean that there is an implicite instance of it somewhere.



Now, the string in QuizKarte should be available - which I am quiet sure wasn't before:




So, when I set a cast for QuizKarte it works? Could it be something like this?

 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
omg I think I got it !

Now, the only thing I have done wrong is here

the compiler says

meineQuizkarte cannot be resolved to a type, objectOutputStream cannot be resolved, fileWriter cannot be resolved



How comes the ObjectOutputStream doesn't get the stuff?
 
Paul Clapham
Sheriff
Posts: 23866
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Henry Wong wrote:You are using a variable name QuizKarte, and you don't seem to have a declaration for it. And classes and variables are two different things -- just because you have a class name QuizKarte doesn't mean that there is an implicite instance of it somewhere.



Just like before. Same error.
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, I guess there are a lot of mistakes. I am reading the HeadFirst book from O'Reilly. This is also the very first time I am doing any programming. I am trying to fix this class for 3 days now. Can anyone please give me a link to the entire (working) code of quizcard from chapter 14, HeadFirst, O'Reilly?
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll find all samples here.

From what I see, you are mixing variable names and class names. A variable has a type, a name and a value. For example, "String name = null", The variable called "name" is of type "String", and its value is null.

1. meineQuizkarte eins = (Quizkarte) zeile; -> Remember the thing above ? "meineQuizkarte eins", this can't be. The variable "eins" is of type "meineQuizkarte" ? Where is this type coming from ? Shouldn't that be "Quizkarte", as you are casting "zeile" to Quizkarte.

2. objectOutputStream.writeObject(QuizKarte); -> This cannot be. You have to pass a variable to the writeObject method. Maybe "eins" ? I don't know what you want to do, so I can't tell for sure.

3. You are mixing "QuizKarte" and "Quizkarte". Remember that Java is case-sensitive.
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"eins" is the german word for "one", "zeile" means "line"

basically, what I want to do is put a string into a text file, store this file in a file object and then making it possible to read from this text file. This casting thing is really confusing. I think I will not change any code from now on until I get it clear which class is where and does what. Also your second point looks interessting, I will bear that in mind
 
Henry Wong
author
Posts: 23811
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

enrique garcia wrote:This casting thing is really confusing. I think I will not change any code from now on until I get it clear which class is where and does what. Also your second point looks interessting, I will bear that in mind



These are not errors that are related to casting. What you are showing us are compile errors -- using classes that don't exist and using variables that you never declared.

Henry
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, what I need is some kind of text-string for that what is written on the cards. I already had a try with something like this:



Christophe Verré wrote:You'll find all samples here.



unfortunately this site doesn't give any hint regarding how to set up the text string for the quiz cards.



Edit: This is how my code looks like now
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put
into the quizcard file. The compiler says "Unreachable code". So I have to put this string somewhere else. But where and how?
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hum.. When a class is never used locally (The type Textdatei is never used locally), what can I do? I tried to implement the class, but this doesn't work?
 
enrique garcia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I resolve one problem 10 new errors appear. Always

Edit: Now the compiler says 3 times

Illegal modifier for the local class NaechsteKarteListener; only abstract or final is permitted




And, what is very confusing: new mistakes appeared, which where no mistakes before:

The field kartenListe is defined in an inherited type and an enclosing
scope




The only thing I changed was to insert a class with a text file before the BufferedReader is declared (at least it looks that I did that ok)
 
Marshal
Posts: 61691
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not allowed to use the keywords public private protected and static inside a method.
 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you need to do a step back and first play with some simpler examples. When you try to write a longer, more complicated program and you get lots of errors at once, and you don't understand some of the basic concepts very well, it will be very hard to fix all those problems.

I recommend that you first learn exactly how classes, objects, variables, methods etc. work in Java, by creating small and simple programs that focus on one concept at a time. When you understand all that, then you can try to make a longer program that uses all those concepts.

Have a look at Oracle's Java Tutorials, where all the concepts are very well explained. Especially look at the chapters in Learning the Java Language and after that at Essential Classes.

Don't try to learn too much at once.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!