我写的一个程序在1.4下运行没任何问题,但5.0下提示:arrayindexoutofboundsexception,是不是因为1.4的arraylist和5.0的不一样啊?
  程序中有如下代码:   CrawlerList.add(crawler);//很有可能是这里出了问题   crawler是我写的一个Observable接口。

解决方案 »

  1.   

    我的程序是一个多线程的下载工具,原型是书上的。我从网上下载的代码也出错。出要输入URL按回车就错
      

  2.   

    我遇到过类似的问题,主要是因为两个版本对多线程的实现稍有不同,造成了代码运行中先后顺序的差异,本来应该先有对象的再访问arraylist的,现在反了过来,建议你在访问arraylist前先做检查
      

  3.   

    好象是下面最后几段有问题,大家看怎么解决:
    class CrawlersTableModel extends AbstractTableModel
      implements Observer
    {
      // These are the names for the table's columns.
      private static final String[] columnNames = {"URL", "Crawled"
        ,"ToCrawl","Progress", "Status"};  // These are the classes for each column's values.
      private static final Class[] columnClasses = {String.class,
        String.class,String.class, JProgressBar.class, String.class,};  // The table's list of crawlers.
      private ArrayList CrawlerList = new ArrayList();  // Add a new crawler to the table.
      public void addCrawler(Crawler crawler) {
        // Register to be notified when the crawler changes.    crawler.addObserver(this);    CrawlerList.add(crawler);//尤其是这里
        ........
      

  4.   

    感觉没有什么问题啊!new ArrayList(10),CrawlerList,看看运行时长度.
      

  5.   

    经过在JBUILDER下的调试才发现了问题。
    为了监视对TABLE中行的选择,我向表中添加了一个ListSelectionListener(),在1.4下ListSelectionListener()中的valueChanged方法如果是手动选择而发生的当前行的变化时该方法才被调用,但5.0下只要程序往表里添加了行,它也调用valueChanged方法,所以导致程序发生错误。以后希望大家小心。多谢大家参与这个话题的讨论,向大家学习。