Reading into ArrayList problem - what is wrong?

Hi, I am trying to read a list of strings into an ArrayList and am having some problems. I have created a main() which at the moment does nothing, its just to make sure that the array's content is genuine (meaning consistent with the string in the text file) so I am having it simply printed out to screen. The error I am getting is "cannot resolve symbol, variable array" by my compiler (Jcreator). I will paste the code below:
import java.io.*;
import java.util.*;
public class hostList{
public hostList()
try
File input = new File("hosts.txt");
BufferedReader in=new BufferedReader(
     new InputStreamReader(new FileInputStream(input)));
     ArrayList list=new ArrayList();
     String line;
     while((line=in.readLine())!=null)
          list.add(line);
     String[] array=new String[list.size()];
     list.toArray(array);
     in.close();
catch(FileNotFoundException e)
System.err.println("File not found...");
catch(IOException e)
System.err.println("IO Problem");
}//hostLst()
     public static void main (String [] args){
          System.out.println("Array content:");
          System.out.println("array " + array[0]);
          for (int i=0; array[i] !=null; i++)
               System.out.println(array);
     }//main
}//class
Also, how would I use the array objects in another class, say class B. How can I access the arrays in class B so that i can use its methods? eg. array[i].doSomething(); where doSomething() is a method in class B. What libraries would i need to import (if any) ?
Help is appreciated, thanks.

this code wont compile bcas in main method u r not creating the object of this class also the var array is not globally declared hence wont be accesibile outside
u can try this modified code
import java.io.*;
import java.util.*;
public class hostList{
String[] array=null;
public hostList()
try
File input = new File("hosts.txt");
BufferedReader in=new BufferedReader(
new InputStreamReader(new FileInputStream(input)));
ArrayList list=new ArrayList();
String line;
while((line=in.readLine())!=null)
list.add(line);
array=new String[list.size()];
list.toArray(array);
in.close();
catch(FileNotFoundException e)
System.err.println("File not found...");
catch(IOException e)
System.err.println("IO Problem");
}//hostLst()
public static void main (String [] args){
hostList h=new hostList();
System.out.println("Array content:");
System.out.println("array " + h.array[0]);
}//main
}//class

Similar Messages

  • My optical drive will not read any music cds now or recognize a blank cd in the drive. it might read some data discs. what is wrong with it and how do i fix it?

    My optical drive will not read any music cds or recognize a blank cd. it might read some data cds. what is wrong with it and how can i fix it?

    The optics might be dirty. Try running a cleaning CD through it and see if that makes a difference.
    If not, it will have to be replace.
    Allan

  • Internet Expenses problem: What's wrong in this code?

    Hi friends,
    [Apps R12]
    I'm trying to incorporate the person_id of the employees picklist on the first screen that appears to create an expense report (+/oracle/apps/ap/oie/entry/header/webui/GeneralInformationPG+) to the query that retrieves the Expense Template.
    I've extended the VO that contains Templates (oracle.apps.ap.oie.server.ExpenseTemplatesVO) and I'm tryiong to overwrite the setWhereParams method, because there is where appears the logic for the where in Templeates query.
    I wrote:
    public void setWhereParams()
    OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getRootApplicationModule();
    OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)oaapplicationmoduleimpl.getOADBTransaction();
    String s = (String)oadbtransactionimpl.getValue("ApWebGracePeriod");
    Number n = new Number(Integer.parseInt(oadbtransactionimpl.getAppsContext().getProfileStore().getProfile("OIE_EMPLOYEE_ID")));
    setWhereClause(null);
    setWhereClauseParam(0, s);
    setWhereClauseParam(1, s);
    setWhereClauseParam(2, s);
    setWhereClauseParam(3, n);
    but.. although it doesn't appear any error... what I think it's doing is to retrieve always the template for the actual user (the user who is logged into application)... And that's not correct at all.. because.. a user could create a Expense report for another person (chosen from the Employees picklist) ...
    I see in the AM certain logic to set the employee_id in a profile (OIE_EMPLOYEE_ID).. So.. I created that profile and add to the code what you see above but.. no way...
    Any ideas? I suppose it must be not very complicated.. It's only to add a new parameter to a query.. (with the peculiarity that the "where" clause is built through this method...) I don't know if bind variables would useful here.. (I don't know how to manage bind variables)
    Thanks !!

    Hi again,
    Ok, I was a bit lost in my last post, but... regarding the others, I have to say that the line
    setWhereClause(null);
    is standard.
    I put here the entire code of ExpenseTemplatesVOImpl. This is what I want to extend... The problem I see with youre code is that you're passing as parameter 0 a number (1?) and there already exists params 0,1 and 2. I don't understand very well too the sentence : setWhereClause("emp_id = :1"); ... Here what is +:1+ my main problem is how to get the employee_id from the picklist existing in this screen.. I've tried to get it from oatransaction and pass the to the query as parameter... but it seems to "reset" the expenses picklist query once we have made an employee change on employee's picklist.
    Suggestions?
    [btw: how do you enclose (which kind of format) code lines in these posts?
    +package oracle.apps.ap.oie.server;+
    +import oracle.apps.fnd.common.VersionInfo;+
    +import oracle.apps.fnd.framework.server.*;+
    +import oracle.jbo.Row;+
    +import oracle.jbo.RowSetIterator;+
    +import oracle.jbo.domain.Number;+
    +public class ExpenseTemplatesVOImpl extends OAViewObjectImpl+
    +{+
    +    public ExpenseTemplatesVOImpl()+
    +    {+
    +    }+
    + public void executeQuery()+
    + {+
    + setWhereParams();+
    + super.executeQuery();+
    setWhereClause("emp_id = :1");
    setWhereClauseParams(null);
    setWhereClauseParam(0,new Number(1));
    super.executeQuery();
    + }+
    + public void executeQueryForCollection(Object obj, Object aobj[], int i)+
    + {+
    + setWhereParams();+
    + super.executeQueryForCollection(obj, aobj, i);+
    + }+
    + public void setWhereParams()+
    + {+
    + OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getRootApplicationModule();+
    + OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)oaapplicationmoduleimpl.getOADBTransaction();+
    + String s = (String)oadbtransactionimpl.getValue("ApWebGracePeriod");+
    + setWhereClause(null);+
    + setWhereClauseParam(0, s);+
    + setWhereClauseParam(1, s);+
    + setWhereClauseParam(2, s);+
    + }+
    + public Number getFirstExpenseTemplate()+
    + {+
    + OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getRootApplicationModule();+
    + OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)oaapplicationmoduleimpl.getOADBTransaction();+
    + if(oadbtransactionimpl.isLoggingEnabled(2))+
    + oadbtransactionimpl.writeDiagnostics(this, "start getFirstExpenseTemplate ", 2);+
    + Row row = first();+
    + if(row != null)+
    + return (Number)row.getAttribute("ExpenseReportId");+
    + else+
    + return null;+
    + }+
    + public String getTemplateName(String s)+
    + {+
    + OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getRootApplicationModule();+
    + OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)oaapplicationmoduleimpl.getOADBTransaction();+
    + if(oadbtransactionimpl.isLoggingEnabled(2))+
    + oadbtransactionimpl.writeDiagnostics(this, (new StringBuilder()).append("start getTemplateName ").append(s).toString(), 2);+
    + RowSetIterator rowsetiterator = findRowSetIterator("noValidationIterator");+
    + if(rowsetiterator == null)+
    + rowsetiterator = createRowSetIterator("noValidationIterator");+
    + rowsetiterator.setRangeSize(-1);+
    + rowsetiterator.setRowValidation(false);+
    + rowsetiterator.reset();+
    + while(rowsetiterator.hasNext())+
    + {+
    + Row row = rowsetiterator.next();+
    + if(row.getAttribute("ExpenseReportId").toString().equals(s))+
    + return (String)row.getAttribute("ReportType");+
    + }+
    + return "";+
    + }+
    + public boolean isTemplateWebEnabled(String s)+
    + {+
    + OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getRootApplicationModule();+
    + OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)oaapplicationmoduleimpl.getOADBTransaction();+
    + if(oadbtransactionimpl.isLoggingEnabled(2))+
    + oadbtransactionimpl.writeDiagnostics(this, (new StringBuilder()).append("start isTemplateWebEnabled ").append(s).toString(), 2);+
    + RowSetIterator rowsetiterator = findRowSetIterator("noValidationIterator");+
    + if(rowsetiterator == null)+
    + rowsetiterator = createRowSetIterator("noValidationIterator");+
    + rowsetiterator.setRangeSize(-1);+
    + rowsetiterator.setRowValidation(false);+
    + rowsetiterator.reset();+
    + while(rowsetiterator.hasNext())+
    + {+
    + Row row = rowsetiterator.next();+
    + if(row.getAttribute("ExpenseReportId").toString().equals(s))+
    + return true;+
    + }+
    + if(oadbtransactionimpl.isLoggingEnabled(2))+
    + oadbtransactionimpl.writeDiagnostics(this, "couldn't find matched template id in all rows ", 2);+
    + return false;+
    + }+
    + public String[] getCacheEventNames()+
    + {+
    + String as[] = {+
    + "oracle.apps.ap.oie.expenseReport.ExpenseTemplateChangeEvent"+
    + };+
    + return as;+
    + }+
    + public String getCacheKey()+
    + {+
    + OAApplicationModuleImpl oaapplicationmoduleimpl = (OAApplicationModuleImpl)getRootApplicationModule();+
    + OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)oaapplicationmoduleimpl.getOADBTransaction();+
    + String s = Integer.toString(oadbtransactionimpl.getOrgId());+
    + return s;+
    + }+
    + public static final String RCS_ID = "$Header: ExpenseTemplatesVOImpl.java 120.2.12000000.2 2007/10/08 08:27:27 sodash ship $";+
    + public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: ExpenseTemplatesVOImpl.java 120.2.12000000.2 2007/10/08 08:27:27 sodash ship $", "oracle.apps.ap.oie.server");+

  • Too many problems-what's wrong with my machine or OS?

    Lately I have had many problems with my computer and am not sure what is the cause. The list is
    - apps crash (primarily pro apps - Final Cut Pro Studio apps)
    - grey crash screen frequently
    - black lines across the screen (video card issue?)
    - sometimes broken looking icons (video card issue?)
    - weird color problems with display (Great condition apple 23" Cinema display)
    - odd asian characters mixed iwth english characters in the restart dialogue box
    - screen will sometimes go black
    - Motion 2.1 makes entire machine slow down (such as moving over dock icons)
    - apps hang for a long time
    - G5 fans spin more
    Incidentally, S.M.A.R.T status is verified on both internal drives, ran disk utility and fixed permissions yielded no problems found, I installed a new Tiger OS (archive and install, saving users and network prefs) and still had the problems, and ran Disk Warrior and still have the problems.
    Any suggestions folks? At my witts end. I want to say the video card could be at fault but how do you know if a video card has problems? is there a card utility like DISK UTILITY?
    My config:
    G5 Dual 2 GHZ/ 4 GB RAM/ two 250 GB SATAs/ Apple 23" Cinema display (last model, not aluminum)/ Apple 17" LCD Studio Display/ WACOM Intuos2/ Blackmagic Decklink Extreme Card/ ATI Radeon 9600 XT (in AGP slot)/ ATI Radeon 9200 (in PCI slot)

    Hi, T. C.
    If you are seeing the following message
    that indicates a kernel panic.
    If so, see my "Resolving Kernel Panics" FAQ. This FAQ includes step-by-step instructions for identifying and resolving some of the most common causes of kernel panics. The FAQ is a roadmap: start at the beginning and work systematically through the end, i.e. the "If all else fails..." section.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X
    Note: The information provided in the link(s) above is freely available. However, because I own The X Lab™, a commercial Web site to which some of these links point, the Apple Discussions Terms of Use require I include the following disclosure statement with this post:
    I may receive some form of compensation, financial or otherwise, from my recommendation or link.

  • Verbatim pic dvd full of pics from canon and nikon cameras reads as empty. What is wrong?

    I have a bunch of pictures burned on a cd in Germany. When i put the cd into my macbook pro that i bought in denmark, it says the cd is empty. How can i make my macbook read the pictures?

    soundman1024 wrote:
    Let's go back a few steps here.  As you're using DVDSP I'm going to assume you edited in Final Cut.  What were your sequence settings?
    If you open your exported Quicktime movie does it have black bars on the top/bottom?
    In DVDSP which display mode are you picking for the track the movie is on?
    ok, i completely forgot about this post or i would ahve come in and eliminated it.  i found the solution.  was supposed to click the menu, then select "16:9 Letterbox" from the menu and that fixed it wholeheartedly.  sorry i forgot to post the resply to myself.  i am REALLY liking DVD SP unlike my avid friends all told me, it is a full functional authoring suite.  i just have to "learn" where everything is and how to get some of the things to function, like music playing while the menu is running, sub menus, etc.
    thanks "soundman1024" however for your response

  • My MacBook Pro isn't turning on, at first it would only turn on when being plugged in by its charger and continued to stay on 0% and now it won't even turn on even when plugged into charger. What's wrong with it?

    Please help

    Is this an early 2008 MacBook Pro?
    I observed two of these machines work perfectly for several months (different users and workflows) with no issues and with normal shutdown. The next press of the power button is greeted by about 3 - 5 seconds of DVD click, hard disk seek, and then nothing. Different batteries, chargers, and memory chips were used with no machine revival.
    As these two machines were fully depreciated employer hardware, they were scrapped, rather than provided to Apple for hardware diagnostic and likely expensive repair.

  • What's wrong with the XML output?

    I got an XML page in IE browser with XSQL Servlet&XSL. But its format is often disordered, for instance there are blank lines between two sequential tags, or the tags at the same level display from different start point. So the whole file seems fall into disorder!
    What's wrong with it?
    Are there some bugs in XSQL Servlet?
    null

    Would you send your XSL file and XSQL file?

  • I am having problems managing my subscriptions.  I want to cancel auto-renew.  When I sign into iTune to "Manage Subscriptions" my subscriptions are not listed.  The page is blank.  What is wrong?

    I am having problems managing my subscriptions.  I want to cancel auto-renew.  When I sign into iTune to "Manage Subscriptions" my subscriptions are not listed.  The page is blank.  What is wrong?

    I am having problems managing my subscriptions.  I want to cancel auto-renew.  When I sign into iTune to "Manage Subscriptions" my subscriptions are not listed.  The page is blank.  What is wrong?

  • I would like to use my work exchange email on my macbook pro.  But I cannot insult it.  I have not problem as on my iPhone or iPad.  My work IT person does not know what is wrong.

    I would like to use my work exchange email on my macbook pro.  But I cannot install it.  I have no problem my work email on my iPhone or iPad.  My work IT person does not know what is wrong.  Why I try to set up the email I get the message that it cannot connect to this server. 

    Try going into System Prefereces then Mail, Cintacts & Calendars then click on the Microsoft Exchange link on the right. Type in your email address and password and allow it to set it up automatically.
    Make sure your Mac is updated to the newest version of Mail.
    If that still fails then I suggest you switch email clients. I don't care for the built in mail program. IMHO it is very buggy.

  • Hi my iph4s wont turn on or off and seems to be zoomed into a particular part of the screen, loads normally when rebooted the phone. what is wrong with it? and how would i go abouts fixing it?thanks

    hi my
    iph4s wont turn on or off and seems to be zoomed into a particular part of the screen, loads normally when rebooted the phone. what is wrong with it? and how would i go abouts fixing it?
    also recovery mode shows up as a red icon instead of a blue one, not jail broken or had any third party alterations
    thanks

    Reset the PRAM
    Reinstall the operating system from the dvd (you will not loose your data)

  • My macbook pro has been shutting off on its own. The power cord "shuts off" (does not work) simultaneously. Does anyone know what is wrong? or what could be the problem?

    My macbook pro has been shutting off on its own. The power cord "shuts off" (does not work) simultaneously. Does anyone know what is wrong? or what could be the problem?
    When my mac finally turns on the date/time is reset a windows pops up saying, "Your computer's clock is set to a date before January 1, 2008. This may cause some applications to behave erractically."

    Resetting your Mac's PRAM and NVRAM
    If you have Apple Care you should give them a call.

  • Some of my songs in iPad Mini with RD disappeared all the sudden and I need to redownload it again. Same thing happen to my iPod touch 5 too. What's wrong with it? Is it the iOS problem?

    Some of my songs in iPad Mini with RD disappeared all the sudden and I need to redownload it again. Same thing happen to my iPod touch 5 too. What's wrong with it? Is it the iOS problem?

    Delete the music in your iTunes library, then go to iTunes store, Quick Link, 'Purchased' to redownload again.

  • My battery reads that it is 100% charged. However, as soon as I unplug it, it dies instantly. The battery lights are still functional, and everything else is working fine! What's wrong with my battery?

    My battery reads that it is 100% charged. However, as soon as I unplug it, it dies instantly. The battery lights are still functional, and everything else is working fine! What's wrong with my battery?

    Sounds like it may need to be replaced. Contact Apple.
    Basic troubleshooting steps  
    17" 2.2GHz i7 Quad-Core MacBook Pro  8G RAM  750G HD + OCZ Vertex 3 SSD Boot HD 
    Got problems with your Apple iDevice-like iPhone, iPad or iPod touch? Try Troubleshooting 101

  • HT1688 My iphone 5 won't charge and it's in perfect condition, I dont drop it and it's not cracked. I tried multiple chargers, none of them are damaged and my outlets work with other things so the problem is my phone. What's wrong with it and what should

    My iphone 5 won't charge and it's in perfect condition, I dont drop it and it's not cracked. I tried multiple chargers, none of them are damaged and my outlets work with other things so the problem is my phone. What's wrong with it and what should I do? Please help me I need my phone for work.

    Make sure there's nothing blocking a contact in the charging port of the phone.

  • My iPod will not charge at all it will when it's off it will power on and charge to a certain pint then will stop and no longer charge what is its problem I've tried 3 cords and three different outlets and also in my computer! What is wrong with it?

    My iPod will not charge at all it will when it's off it will power on and charge to a certain pint then will stop and no longer charge what is its problem I've tried 3 cords and three different outlets and also in my computer! What is wrong with it?it won't charge when it's powered on only when it s off then it turns on and stops charging?? What's wrong with it ad how much is a Genius Bar appt at apple stores??

    Not Charge
    - See:      
    iPod touch: Hardware troubleshooting
    - Try another cable. Some 5G iPods were shipped with Lightning cable that were either initially defective or failed after short use.
    - Try another charging source
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Make an appointment at the Genius Bar of an Apple store.
      Apple Retail Store - Genius Bar 

Maybe you are looking for