|
BufferedReader should return null when you reach the end of the file. It sounds very odd that you are getting an empty String. Can you post a snippet of code to show how you are using the BufferedReader.
|
|
|
|
|
I just tried this:
BufferedReader in = new BufferedReader(new FileReader("test.txt"));
String str;
while ((str = in.readLine()) != null)
{
System.out.format("%s%n", str);
}
in.close();
and it works correctly, returns empty string for blank line, and null for EOF. Can you show your code?
|
|
|
|
|
I am using like this:
temp = bufferedReader.readLine();
if(temp==null)
The only difference is that u are directly using in while loop amd i assigning variable.
When I did like u did then its working for me.Thx for ur Help.
Regards
Yogesh
|
|
|
|
|
yogeshs wrote: The only difference is that u are directly using in while loop amd i assigning variable.
This makes no difference; I tried it with assigning to a variable and it works just the same. There must be something else wrong with your code.
|
|
|
|
|
May b or not.But now it is working.
Anyway,thx for ur help.
|
|
|
|
|
I'm writing a program using BlueJ. I created a jar file and set the Main class to the desired class. When I run the jar in Explorer I get an error window saying "Java Virtual Machine Launcher. Fatal Exception occured. Program will exit." I have a Main method which instantiates a class which extends JFrame. I wrapped that in a try-catch block to see if there was an error on my code. The message still appears. Is there a way to get a more verbose error?
*Edit*
Okay I ran it on my linux machine and this is the error:
jordanwb@jordanwb-laptop:/media/DEFB-0C36/PhpDesigner$ java PhpDesigner.jar
Exception in thread "main" java.lang.NoClassDefFoundError: PhpDesigner/jar
Caused by: java.lang.ClassNotFoundException: PhpDesigner.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: PhpDesigner.jar. Program will exit.
So it can't fine the class, but how do I go about fixing that? Apparently the compiler and BlueJ can find the MainWindow class but the virtual machine can't.
modified on Thursday, January 7, 2010 4:16 PM
|
|
|
|
|
Jordanwb wrote: jordanwb@jordanwb-laptop:/media/DEFB-0C36/PhpDesigner$ java PhpDesigner.jar
I think that should be:
java -jar PhpDesigner.jar
|
|
|
|
|
jordanwb@jordanwb-laptop:/media/DEFB-0C36/PhpDesigner$ java -jar PhpDesigner.jar
Exception in thread "main" java.lang.NoSuchMethodError: main
The main method does exist in the startup class.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class MainWindow extends JFrame implements ActionListener
{
private JMenuBar main_menu;
private JMenu file_menu;
private JMenuItem new_project, open_project, save_project, save_project_as, quit;
private JMenu objects_menu;
private JMenuItem add_folder, add_file, add_class, add_interface, add_function, add_parameter, add_field;
private JPanel php_object_manager;
public MainWindow()
{
super ("PhpDesigner");
this.setSize (800, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.new_project = new JMenuItem("New Project", new ImageIcon ("./Images/document-new.png"));
this.new_project.addActionListener (this);
this.open_project = new JMenuItem("Open Project", new ImageIcon ("./Images/document-open.png"));
this.open_project.addActionListener (this);
this.save_project = new JMenuItem("Save Project", new ImageIcon ("./Images/document-save.png"));
this.save_project.addActionListener (this);
this.save_project_as = new JMenuItem("Save Project As", new ImageIcon ("./Images/document-save-as.png"));
this.save_project_as.addActionListener (this);
this.quit = new JMenuItem("Quit", new ImageIcon ("./Images/system-log-out.png"));
this.quit.addActionListener (this);
this.file_menu = new JMenu ("File");
this.file_menu.add (this.new_project);
this.file_menu.addSeparator();
this.file_menu.add (this.open_project);
this.file_menu.add (this.save_project);
this.file_menu.add (this.save_project_as);
this.file_menu.addSeparator();
this.file_menu.add (this.quit);
this.main_menu = new JMenuBar ();
this.main_menu.add (this.file_menu);
this.getContentPane().add (this.main_menu, BorderLayout.NORTH);
this.add_folder = new JMenuItem ("Add Folder");
this.add_file = new JMenuItem ("Add File");
this.add_class = new JMenuItem ("Add Class");
this.add_interface = new JMenuItem ("Add Interface");
this.add_function = new JMenuItem ("Add Function");
this.add_parameter = new JMenuItem ("Add Parameter");
this.add_field = new JMenuItem ("Add Field");
this.objects_menu = new JMenu ("Objects");
this.objects_menu.add (this.add_folder);
this.objects_menu.add (this.add_file);
this.objects_menu.add (this.add_class);
this.objects_menu.add (this.add_interface);
this.objects_menu.add (this.add_function);
this.objects_menu.add (this.add_parameter);
this.main_menu.add (this.objects_menu);
this.setVisible (true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource ();
if (source == this.new_project) { }
else if (source == this.save_project) { }
else if (source == this.save_project_as) { }
else if (source == this.quit)
{
System.exit(0);
}
}
public static void main ()
{
new MainWindow ();
}
}
|
|
|
|
|
How did you create your 'jar'; did you use a correct manifest file to identify the class containing the main() method?
|
|
|
|
|
I used BlueJ to create the jar which I believe creates the manifest file for me.
|
|
|
|
|
Jordanwb wrote: I used BlueJ
I'm afraid I know nothing about BlueJ so you need to go to the documentation to check it out. Alternatively you could deconstruct the jar file and check the files yourself.
|
|
|
|
|
This is the content of the manifest file:
Main-Class:MainWindow
|
|
|
|
|
Sorry, that looks OK, I'm not sure what else to suggest.
|
|
|
|
|
I added String[] args to the args of main () and it works.
|
|
|
|
|
Interesting; I actually wondered about that yesterday, but did not bother to test it out.
To paraphrase Sherlock Holmes: "When you have eliminated the impossible, whatever remains, however improbable, must be the answer".
|
|
|
|
|
It sortof makes sense. Java apps are capable of processing arguments, altough they're infrequently used on Windows. Another thing I forgot was that the first letter of a method is always lowercase. I had to rename Main (String[]) to main (String[]).
|
|
|
|
|
Jordanwb wrote: It sortof makes sense.
As with most things in IT.
|
|
|
|
|
I had upgraded QuickBooks 2009 to 2010 edition for my dad. The conversion started off at taking four hours, then down t 2 and a half hours, down to twelve minutes then down to 3. The whole process took around 2 minutes.
|
|
|
|
|
Umm, I think maybe this belongs to an alternative thread.
|
|
|
|
|
Hello Friends
I m using MouseZoom in my application and it is zoooming fine but when I zoom Out with mouse wheel then after zooming up to a certain point the image becomes invisible and then I have to again zoomin then it comes in.I dont want to make that image invisible when i do zoom out.
Do u have any Ideas?
Thanks & Regards
Yogesh
|
|
|
|
|
please mail the java coding for Packet Scheduler with Packetized Ordered Round Robin Scheduling
|
|
|
|
|
thileebandr wrote: please mail the java coding ...
That's not the way it works here. Show us what you have tried and what is not working, and people will try and help. If you want someone to do your work for you then try the Jobs forum.
|
|
|
|
|
hello Friends
I m reading a file using tokenizer and in that i am reading some bitmap paths but I dont know after reading all the paths it starts again and gives me this exception:
java.net.MalformedURLException: unknown protocol: e
eVEN i M using the condition of tokenizer.TT_EOF
Please suggest me y this exception is coming?
Thanks
Yogesh
|
|
|
|
|
Hint: MalformedURLException
It looks as though the URL you are using contains some invalid formatting or characters. Take a look at the content and see what is wrong with it.
|
|
|
|
|
thx for ur reply.
I want to know how can we read a .tga extension image file using imageIO.read.
I am reading .jpeg file but it is not reading .tga file.
I am doing like this:
String imageFilename = "c:\\sample.jpg";
imageIO.read(new File(imageFilename));
Any Ideas for rading .tga file?
Thanks in Advance
Yogesh
|
|
|
|