Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2007, 06:00 AM
Member
 
Join Date: Jul 2007
Posts: 35
carl is on a distinguished road
Error: cannot be applied to (java.lang.String)
Hi, I've been starting to go through my programs by doing one part at a time so i don't run into as many errors.
Can someone please look over my open/read method?
I'm getting 1 error when i attempt to compile it I've marked in code where it is
It says this when i try to compile

Code:
Prog3test.java:28: openread(java.io.File) in Prog3test cannot be applied to (java.lang.String) String in = openread("input.txt");
Code:
import java.io.*; import B102.*; class Prog3 { public String openread(File inputfile) { System.out.println("Opening File: " + inputfile.getName()); BufferedReader input = null; String line; try { input = new BufferedReader(new FileReader(inputfile)); while((line = input.readLine())!= null) { break; } } catch(IOException in) { System.out.println("There has been an error."); } finally { // closing file, even on exception try { input.close(); } catch (Exception e) {} } return(line); } public static void main(String[] args) { String in = openread("input.txt"); *******error here******* } }
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-05-2007, 07:33 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
// This method takes a File public String openread(File inputfile) // Here you are sending a String to a method // that takes a File. The types do not match. String in = openread("input.txt"); // You could do String in = openread(new File("input.txt"));
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String) baltimore New To Java 2 09-18-2008 08:30 AM
Cast Error Caught (change) Class is really: java.lang.String barney Advanced Java 1 08-02-2007 05:07 PM
Error: javax.swing.AbstractButton cannot be applied to... barney AWT / Swing 1 08-01-2007 07:10 AM
Can't convert java.lang.String to int. Albert AWT / Swing 2 07-13-2007 06:05 PM
Operator < cannot be applied to java.lang.Object, Object Albert Advanced Java 1 07-13-2007 04:19 PM


All times are GMT +3. The time now is 02:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org