Object for read-method

Hi all,

I got this piece of code:

ontvangen.read(new FileWriter(Map), ?);

Java wants a Object at the ?'s, but i don't know what kind of Object and how to create it :S

Could anybody help me and give me some code for making the right Object so it would work at all?

Ty, Jasper Kouwenberg

[357 byte] By [Jasper91a] at [2007-11-26 13:56:40]
# 1
What class is "ontvangen" declared as? It's not obvious what method you are trying to call. You'll get a better answer if we know what the method expects.
doremifasollatidoa at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 2

>> What class is "ontvangen" declared as?

You can find that out byString className = ontvangen.getClass ().getName ();

(or getSimpleName if you're not interested in the package name)

BTW. you can get help faster if you translate class and variable names in English - in this case, received - then the majority of readers will have an idea of what your code is trying to do.

levi_ha at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 3
"BTW. you can get help faster if you translate class and variable names in English - in this case, received - then the majority of readers will have an idea of what your code is trying to do."HuH?~Bill
abillconsla at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 4
> HuH?> > ~BillThe word "ontvangen" is Ducth for "received".
prometheuzza at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 5
>> HuH?I'm sorry, let me clarify: ontvangen is Dutch for the English received. And I'm Dutch.Of course it's also possible that the word exists in yet another foreign language, but I highly doubt it.Edit - man, I'm slow.
levi_ha at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 6

> >> What class is "ontvangen" declared as?

>

> You can find that out byString className =

> ontvangen.getClass ().getName ();

(or

> getSimpleName if you're not interested in the package name)

I would have assumed he could have looked at the source code and told me, without adding additional code.

> BTW. you can get help faster if you translate class

> and variable names in English - in this case,

> received - then the majority of readers will

> have an idea of what your code is trying to do.

Not necessarily helpful to translate names to English. And, even if he does that, he shouldn't try to retype the variables in the actual code. He should cut and paste the actual code, then maybe translate a few important variables as supporting text for the post (often don't even need that). Changing the actual code is too prone to errors. In this case, knowing the class of ontvangen is much more important than knowing what the word itself means.

doremifasollatidoa at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 7

> BTW. you can get help faster if you translate class

> and variable names in English - in this case,

> received - then the majority of readers will

> have an idea of what your code is trying to do.

I googled ontvangen, pressing the "I'm feeling lucky" button and it took me directly to a Wikipedia page that gave the translation for this word. (Now I know it's Dutch, too, although I don't know what "strong verbs" are...)

I agree that a post will get more attention if it's in English, but sometimes enlightenment is only a google away.

DrLaszloJamfa at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 8

>> I would have assumed he could have looked at the source code and

>> told me, without adding additional code.

Yeah, of course. But if he couldn't, he could print the class name.

>> Not necessarily helpful to translate names to English.

I disagree. But I also disagree with coding in your own language, BTW. If you code in English you wouldn't even need to translate to find help on the internet.

levi_ha at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 9

> I googled ontvangen, pressing the "I'm feeling

> lucky" button and it took me directly to a Wikipedia

> page that gave the translation for this word. (Now I

> know it's Dutch, too, although I don't know what

> "strong verbs" are...)

A strong verb is a verb whereby (usually) a vowel changes in it's past-simple or past-participle.

ik ontvang (I receive)

ik ontving (I received)

ik heb ontvangen (I have received)

prometheuzza at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 10

> (Now I know it's Dutch, too, although I don't know what "strong verbs" are...)

They're irregular verbs."ontvangen, ontving, ontvangen". Compare this

to, say, "walk, walked, walked" (regular) and "send, sent, sent" (irregular)

"en wat woue ze nou nog dat we zagen?" (local humour, don't pay any

attention to it please ;-)

kind regards,

Jos (net effe m'n trui gerolen)

JosAHa at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 11

>> I googled ontvangen, pressing the "I'm feeling lucky" button and it took me

>> directly to a Wikipedia page that gave the translation for this word. (Now I

>> know it's Dutch, too, although I don't know what "strong verbs" are...)

"Strong verbs" have an irregular past tense. The past tense of programmeren is programmeerde, for instance. For sterke werkwoorden (your strong verbs) the vowel changes (lopen -> liep). This can be compared with English' see -> saw.

[In case your interested :)]

>> I agree that a post will get more attention if it's in English, but sometimes

>> enlightenment is only a google away.

Yeah, but how many posters are willing to google? I bet more than 90% just skip those questions, with or without duke dollars.

levi_ha at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 12

> >> Not necessarily helpful to translate names to English.

>

> I disagree. But I also disagree with coding in your

> own language, BTW. If you code in English you

> wouldn't even need to translate to find help on the

> internet.

Okay, so since you know what "ontvangen" means, do you know how to answer his question as to what Object he needs? I doubt it. However, if you knew what class the variable was, you'd have a much better chance of figuring it out. I am a native English speaker, so I code in English. But, if a Dutch software company wants to write all their code in Dutch, it makes sense to me (I wouldn't be able to read it, but they would). Not everyone can read/write English as well as they read/write Dutch. Why give them more trouble? They shouldn't write their code a different way in the off chance that they'll need help on the internet. They should write in Dutch if it is easier for them, and then only worry about translations when and if they need help.

doremifasollatidoa at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 13

"Not necessarily helpful to translate names to English. And, even if he does that, he shouldn't try to retype the variables in the actual code. He should cut and paste the actual code, then maybe translate a few important variables as supporting text for the post (often don't even need that). Changing the actual code is too prone to errors. In this case, knowing the class of ontvangen is much more important than knowing what the word itself means."

Yes this is what I meant too ... I just went for HuH for affect ;o). Everyone learns slightly differently, but the overriding factor IMO is that it's not fair to expect a non-native-English-speaker to recode variable names to English, and usually not very helpful anyway.

~Bill

abillconsla at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 14

> >> I agree that a post will get more attention if it's in English, but sometimes

> >> enlightenment is only a google away.

>

> Yeah, but how many posters are willing to google? I

> bet more than 90% just skip those questions, with or

> without duke dollars.

I would Google the names if I thought it was relevant, and I have done so many times. But, many times the meanings are not needed in order to figure out what the code problem is.

doremifasollatidoa at 2007-7-8 1:36:17 > top of Java-index,Java Essentials,Java Programming...
# 15
> Yes this is what I meant too ... I just went for HuH for affect ;o).Since we are talking about using English here, it should be "effect". ;-)
doremifasollatidoa at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 16

>> Okay, so since you know what "ontvangen" means, do you know how to

>> answer his question as to what Object he needs? I doubt it.

Not in this case, no, I'll give you that.

>> However, if you knew what class the variable was, you'd have a much

>> better chance of figuring it out. I am a native English speaker, so I code in

>> English. But, if a Dutch software company wants to write all their code in

>> Dutch, it makes sense to me (I wouldn't be able to read it, but they

>> would). Not everyone can read/write English as well as they read/write

>> Dutch. Why give them more trouble? They shouldn't write their code a

>> different way in the off chance that they'll need help on the internet. They

>> should write in Dutch if it is easier for them, and then only worry about

>> translations when and if they need help.

How about outsourcing? Or being able to hire non-Dutch speakers?

I happen to work for a Dutch software company and what we (try to) do is program in English (getters/setters, English Javadoc), but keep the domain names (the ones that you discuss with customers) in Dutch. This works out fairly well.

levi_ha at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 17

> > (Now I know it's Dutch, too, although I don't know

> what "strong verbs" are...)

>

> They're irregular verbs."ontvangen, ontving,

> ontvangen".

A strong verb is a special kind of irregular verb, right?

> "en wat woue ze nou nog dat we zagen?" (local humour,

> don't pay any

> attention to it please ;-)

>

> kind regards,

>

> Jos (net effe m'n trui gerolen)

It giet oan, Jos!

; )

prometheuzza at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 18

> > Yes this is what I meant too ... I just went for

> HuH for affect ;o).

>

> Since we are talking about using English here, it

> should be "effect". ;-)

Actually I was NOT talking about English - rather I was talking in English about not using English - and in any case you are incorrect sir.

~Bill

abillconsla at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 19

> > > Yes this is what I meant too ... I just went

> for

> > HuH for affect ;o).

> >

> > Since we are talking about using English here, it

> > should be "effect". ;-)

>

> Actually I was NOT talking about English - rather I

> was talking in English about not using English - and

> in any case you are incorrect sir.

"effect" is certainly not wrong here (and is more common). See #3 here:

http://dictionary.cambridge.org/define.asp?key=24851&dict=CALD

"affect" is usually only used as a noun when talking about psychology.

doremifasollatidoa at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 20

> > > > Yes this is what I meant too ... I just

> went

> > for

> > > HuH for affect ;o).

> > >

> > > Since we are talking about using English here,

> it

> > > should be "effect". ;-)

> >

> > Actually I was NOT talking about English - rather

> I

> > was talking in English about not using English -

> and

> > in any case you are incorrect sir.

>

> "effect" is certainly not wrong here (and is more

> common). See #3 here:

> http://dictionary.cambridge.org/define.asp?key=24851&d

> ict=CALD

>

> "affect" is usually only used as a noun when talking

> about psychology.

I did not say you would be entirely wrong to use effect, only that you were incorrect in insisting that I was wrong in using affect. These two are clear in some instances and very murky in others. At any rate, I don't care enough about it to carry this on any further. And if by concensus I end up as the one in the wrong, so be it - it was not at center of the point I was attempting to make ; which point BTW is not one that in itself I care all that much about either. I just wished to enter my own 2cents worth. I did and now I bow out. Best regards,

~Bill

abillconsla at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 21
BTW: ontvangen is a JTextArea
Jasper91a at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 22
> BTW: ontvangen is an JTextAreaThere is no such method in JTextArea. There is a read method inhereted from JTextComponent, but it takes a Reader and an Object as a parameter, not a Writer and an Object. You can probably provide a String as Object.
prometheuzza at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 23

> BTW: ontvangen is a JTextArea

From the v5.0 API doco:

read

public void read(Reader in,

Object desc)

throws IOException

Initializes from a stream. This creates a model of the type appropriate for

the component and initializes the model from the stream. By default this will

load the model as plain text. Previous contents of the model are discarded.

Parameters:

in - the stream to read from

desc - an object describing the stream; this might be a string, a File, a

URL, etc. Some kinds of documents (such as html for example) might be

able to make use of this information; if non-null, it is added as a property of

the document

Throws:

IOException - as thrown by the stream being used to initialize

So, what happens if you try null?

abillconsla at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 24
look at this: http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/JTextComponent.html#read(java.io.Reader,%20java.lang.Object)(select whole URL)
Jasper91a at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 25

> > BTW: ontvangen is an JTextArea

>

> There is no such method in JTextArea. There is a read

> method inhereted from JTextComponent, but it takes a

> Reader and an Object as a parameter, not a Writer and

> an Object. You can probably provide a String as

> Object.

Good catch - I missed that one!

abillconsla at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 26
but still thx for your help! :P
Jasper91a at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 27

> BTW: ontvangen is a JTextArea

Great! That or JEditorPane was my closest guess based on the Index of the API (looked at all "read" methods that took an Object). But, your first argument is wrong--it should be a Reader, not a Writer. So, I wasn't sure.

[url]http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/JTextComponent.html#read(java.io.Reader, java.lang.Object)[/url]

First, note that 'read' is inherited from JTextComponent, so that's where you need to look for it in the API (the above link). Look at the JEditorPane's read method for info about using an HTMLDocument. I think the same info applies to JTextComponent.

doremifasollatidoa at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 28
> but still thx for your help! :PSo now, after you're done razzing us, what will you do? :o}~Bill
abillconsla at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 29
It works guys! Thx to you all, i'll try to give everybody 1 (or more) DD's!Ty, Jasper
Jasper91a at 2007-7-21 15:58:44 > top of Java-index,Java Essentials,Java Programming...
# 30

As the API says, it will store the value as a property of the document. It isn't completely obvious from the API, but it is stored using the following key (as seen in the source code):

Document.StreamDescriptionProperty

So, you can retrieve the value using:

Object desc = ontvangen.getDocument().getProperty(Document.StreamDescriptionProperty);

But, you probably wouldn't ever retrieve that yourself. As the API says, some documents (such as HTML) will use the information.

doremifasollatidoa at 2007-7-21 15:58:49 > top of Java-index,Java Essentials,Java Programming...
# 31

> I did not say you would be entirely wrong to use effect, only that you were incorrect in insisting

> that I was wrong in using affect. These two are clear in some instances and very murky in others. At any

> rate, I don't care enough about it to carry this on any further. And if by concensus I end up as the one

> in the wrong, so be it - it was not at center of the point I was attempting to make ; which point BTW is

> not one that in itself I care all that much about either. I just wished to enter my own 2cents worth. I

> did and now I bow out.

Sorry for the confusion. I know it wasn't the center of your point. Your two cents were as valid as anyone else's (including mine). I'll bow out, too. Best regards to you, too.

doremifasollatidoa at 2007-7-21 15:58:49 > top of Java-index,Java Essentials,Java Programming...
# 32

> > I did not say you would be entirely wrong to use

> effect, only that you were incorrect in insisting

> > that I was wrong in using affect. These two are

> clear in some instances and very murky in others. At

> any

> > rate, I don't care enough about it to carry this on

> any further. And if by concensus I end up as the one

> > in the wrong, so be it - it was not at center of

> the point I was attempting to make ; which point BTW

> is

> > not one that in itself I care all that much about

> either. I just wished to enter my own 2cents worth.

> I

> > did and now I bow out.

>

> Sorry for the confusion. I know it wasn't the center

> of your point.

Not a problem at all.

> Your two cents were as valid as anyone else's

> (including mine). I'll bow out, too.

Why thank you sir

> Best regards to you, too.

Be well.

~Bill

null

abillconsla at 2007-7-21 15:58:49 > top of Java-index,Java Essentials,Java Programming...
# 33
Thanks for dukes.
abillconsla at 2007-7-21 15:58:49 > top of Java-index,Java Essentials,Java Programming...