Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read a txt into a textarea

 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got a desktop program that has a menu bar and a textArea, wen i presS the button on the menubar the folowing actionperformed happend:



WHAT I WANT IS TO OPEN MY TXT FILE BY PRESSING THE MENU BAR BUTTON AND READ IT AND PUT THE READING ON THE TEXTAREA IN THE APLICATION, BUT THAT HASNT BEEN THE RESULT, I WANNA KNOW WERE IS THE ISSUE
THANKS RANCHERSS!!!
 
Paul Clapham
Sheriff
Posts: 21300
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a good chance that some kind of exception is being thrown. However you will never know, because your code ignores exceptions. Try this instead:



However, having said that I suspect your problem is that your file path is nothing like an actual Windows file path. Where did all those colons (:::) come from?

And finally you don't need to write the code yourself to read from the file and write it into the text area. You can just use a method from the standard API:


 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made the changes but still nothing

private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {
try{
FileReader Fichero=new FileReader("C:\\Documents and Settings\\Chelo\\Mis documentos\\NetBeansProjects\\Obliga\\src\\presentacion\\Grupo.txt");
BufferedReader leer=new BufferedReader(Fichero);
while((Text=leer.readLine())!=null){
jTextArea1.append(Text+ "\n"); //append Concatena la linea leida
}
leer.close();


}catch(IOException e){
e.printStackTrace();
};
}
 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain me better how is that ai can use the standar api for this trouble?

THANK YOU FOR THE ANSWERS!!!
 
Paul Clapham
Sheriff
Posts: 21300
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcelo Bordolli wrote:I made the changes but still nothing


Does that code run when you click on whatever it is?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> jMenu2ActionPerformed

is jMenu2 a JMenu?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you posted has syntax errors. You should check them before going into functionality.
 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i use netbeans and the code compiles fine it just dont do as supose
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can't compile fine, since you use variable that you didn't declare.
Do you get any exception? If so, can you copy the message you get?
 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i forgot to put them but i did declare all the variables. and no exception happend.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Than it probably means the file you are reading is empty.

EDIT: It is a good practice to use Lower Camel Case for naming your variables. Or at least stick to just one naming convention.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should have taken the hint from my question.
the solution is in that hint
 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the file contains the following:


Alfredo Garcia 34353454
Richard Blemen 23525342
Mick Jagger 24523523
Robert Pattinson 65434518
Hayden Pannetiere 36486712
Alice Eve 97246590
Hugo Beaven 28288282
Beavis Acdc 54545445
Buthead Acdc 12121221
Mathias Oviedo 78787887
Marcos Viera 29292992
Wesker Almond 33333333
Trinity Gogo 22222222
Tia Carrera 44444444
Kristen Stweart 66666666
Charlize Theron 77777777
Denzel Washington 99999999
Angus Young 23312323
Malcom Young 23311332
Jhon Lennon 57575775
Jason Statam 83838383
Mario Bros 91291291
Luigi Bros 48297538
Amy Adams 98239832
Isla Fisher 20202020

and you are right whit the naming conventions i should stick whit one
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:you should have taken the hint from my question.
the solution is in that hint

Missed that one, thought the listener is for JMenuItem. That's the problem, Marcelo Bordolli.
 
Paul Clapham
Sheriff
Posts: 21300
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:Than it probably means the file you are reading is empty.


We don't even know if that code is being executed. (I asked but received no answer.)
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Kemal Sokolovic wrote:Than it probably means the file you are reading is empty.


We don't even know if that code is being executed. (I asked but received no answer.)


I always suppose people run it through debugger to at least make sure execution comes to the code they are asking for, before posting a question like this. Guess that's not the case.
 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FIXED!!! THE ISSUE WAS SO DUMB
I was pleacing the code in the wrong place, i change it to jmenuitem and it works perfectly fine

Thank you all , Paul
Kemal and the rest!!!

I have millions of code here so i guess in one point all start to look a like, Thank you all!!
 
Marcelo Bordolli
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Michael , also missed his post!!
 
Paul Clapham
Sheriff
Posts: 21300
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:I always suppose people run it through debugger to at least make sure execution comes to the code they are asking for, before posting a question like this. Guess that's not the case.


You might think so, but quite often beginners produce this sort of thing on the first day after they install Netbeans, and they have no idea how to use Netbeans for debugging. Or even what debugging is, for that matter.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You might think so, but quite often beginners produce this sort of thing on the first day after they install Netbeans, and they have no idea how to use Netbeans for debugging. Or even what debugging is, for that matter.

Apparently that is the case, I'll keep that in mind.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic