Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4942 > unrolled thread

Strange JTable issue in Sun's Java code

Started byNovice <novice@example..com>
First post2012-01-16 18:34 +0000
Last post2012-01-19 21:00 +0100
Articles 18 — 3 participants

Back to article view | Back to comp.lang.java.gui


Contents

  Strange JTable issue in Sun's Java code Novice <novice@example..com> - 2012-01-16 18:34 +0000
    Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-16 14:48 -0500
      Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-16 14:55 -0500
      Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-16 15:19 -0500
        Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-16 15:31 -0500
          Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-16 17:57 -0500
      Re: Strange JTable issue in Sun's Java code Novice <novice@example..com> - 2012-01-17 01:48 +0000
        Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-17 03:22 -0500
          Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-17 03:29 -0500
          Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-17 03:49 -0500
          Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-17 03:55 -0500
          Re: Strange JTable issue in Sun's Java code Novice <novice@example..com> - 2012-01-17 22:21 +0000
            Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-17 18:18 -0500
              Re: Strange JTable issue in Sun's Java code Jeff Higgins <jeff@invalid.invalid> - 2012-01-17 20:56 -0500
                Re: Strange JTable issue in Sun's Java code Novice <novice@example..com> - 2012-01-18 05:24 +0000
                  Re: Strange JTable issue in Sun's Java code Novice <novice@example..com> - 2012-01-18 17:40 +0000
              Re: Strange JTable issue in Sun's Java code Novice <novice@example..com> - 2012-01-18 05:37 +0000
    Re: Strange JTable issue in Sun's Java code Christian Kaufhold <chka@ucuri.chka.de> - 2012-01-19 21:00 +0100

#4942 — Strange JTable issue in Sun's Java code

FromNovice <novice@example..com>
Date2012-01-16 18:34 +0000
SubjectStrange JTable issue in Sun's Java code
Message-ID<Xns9FDC8ADEB9988jpnasty@94.75.214.39>
I'm getting an exception I don't understand when I attempt to delete all 
the data in a small Jtable (46 rows, 3 columns). 

Here's the stacktrace; the "rowCount = 45" is a diagnostic I'm writing:
========================================================================
rowCount = 45
Exception in thread "AWT-EventQueue-0" 
java.lang.ArrayIndexOutOfBoundsException: 0
	at javax.swing.SizeSequence.removeEntries(SizeSequence.java:383)
	at javax.swing.JTable.tableRowsDeleted(JTable.java:4500)
	at javax.swing.JTable.tableChanged(JTable.java:4399)
	at javax.swing.table.AbstractTableModel.fireTableChanged
(AbstractTableModel.java:280)
	at javax.swing.table.AbstractTableModel.fireTableRowsDeleted
(AbstractTableModel.java:245)
	at hang.PhraseListTableModel.deleteAllRows
(PhraseListTableModel.java:634)
	at hang.PhraseListEditor.actionPerformed(PhraseListEditor.java:625)
	at javax.swing.AbstractButton.fireActionPerformed
(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed
(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed
(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed
(DefaultButtonModel.java:242)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick
(BasicMenuItemUI.java:1223)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased
(BasicMenuItemUI.java:1264)
	at java.awt.Component.processMouseEvent(Component.java:6263)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
	at java.awt.Component.processEvent(Component.java:6028)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4630)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.LightweightDispatcher.retargetMouseEvent
(Container.java:4574)
	at java.awt.LightweightDispatcher.processMouseEvent
(Container.java:4238)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Window.dispatchEventImpl(Window.java:2478)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters
(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter
(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
========================================================================

The crash is happening in the Java code but here's my deleteAllRows() so 
that you can see nothing very exotic is happening:

========================================================================
	public int deleteAllRows() {

		String METHOD_NAME = "deleteAllRows()"; //$NON-NLS-1$
		if (DEBUG) this.logger.entering(this.CLASS_NAME, METHOD_NAME);
		
		int rowCount = getRowCount();
		//FIXME: remove the next line
		System.err.println("rowCount = " + rowCount); //temporary 

		this.phraseList.removeAllElements();
		fireTableRowsDeleted(1, rowCount);

		return rowCount;
	}
========================================================================

When I debug the code and follow it into the Java code, some odd things 
are happening. First, the actual fireTableRowsDeleted() method shows a 
valid value for the "this" parameter but displays the following for each 
of the other parameters when I inspect them via the Eclipse debugger: 
"firstRow [or whatever] cannot be resolved to a variable". I don't recall 
ever seeing that before in debugging a program. Then, when I proceed 
beyond that to the removeEntries(int, int) method, things continue to be 
strange. When I get to line 383 of that method, I get the same "cannot be 
resolved to a variable" notation on EVERY variable in that line, even 
variable i, which has just been explicitly set to 0. 

Here's the complete code for this method:

========================================================================
    /**
     * Removes a contiguous group of entries
     * from this <code>SizeSequence</code>.
     * Note that the values of <code>start</code> and
     * <code>length</code> must satisfy the following
     * conditions:  <code>(0 <= start < getSizes().length)
     * AND (length >= 0)</code>.  If these conditions are
     * not met, the behavior is unspecified and an exception
     * may be thrown.
     * 
     * @param start   the index of the first entry to be removed
     * @param length  the number of entries to be removed
     */
   public void removeEntries(int start, int length) { 
        int sizes[] = getSizes(); 
        int end = start + length; 
        int n = a.length - length; 
        a = new int[n]; 
        for (int i = 0; i < start; i++) { 
            a[i] = sizes[i] ;
        }
        for (int i = start; i < n; i++) { 
            a[i] = sizes[i+length] ;
        }
        setSizes(a); 
    } 
========================================================================

I've never encountered a situation like this before. It feels like the 
problem is in the Java code - or Eclipse - and I'm not sure what to do 
about that. Is this nature's way of telling me that I need a newer Java 
JDK? I'm using Java 1.6.18. If not, what should I be doing?

-- 
Novice

[toc] | [next] | [standalone]


#4943

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-16 14:48 -0500
Message-ID<jf1ufa$kt$1@dont-email.me>
In reply to#4942
On 01/16/2012 01:34 PM, Novice wrote:
> I'm getting an exception I don't understand when I attempt to delete all
> the data in a small Jtable (46 rows, 3 columns).
>
> Here's the stacktrace; the "rowCount = 45" is a diagnostic I'm writing:
> ========================================================================
> rowCount = 45
> Exception in thread "AWT-EventQueue-0"
> java.lang.ArrayIndexOutOfBoundsException: 0
> 	at javax.swing.SizeSequence.removeEntries(SizeSequence.java:383)

> ... When I get to line 383 of that method, I get the same "cannot be
> resolved to a variable" notation on EVERY variable in that line, even
> variable i, which has just been explicitly set to 0.

I don't see any line numbers in the code you have provided.
I don't see a variable i in the code you have provided.
>
> Here's the complete code for this method:
>
> ========================================================================
>      /**
>       * Removes a contiguous group of entries
>       * from this<code>SizeSequence</code>.
>       * Note that the values of<code>start</code>  and
>       *<code>length</code>  must satisfy the following
>       * conditions:<code>(0<= start<  getSizes().length)
>       * AND (length>= 0)</code>.  If these conditions are
>       * not met, the behavior is unspecified and an exception
>       * may be thrown.

Where are you checking these?

>       *
>       * @param start   the index of the first entry to be removed
>       * @param length  the number of entries to be removed
>       */
>     public void removeEntries(int start, int length) {
>          int sizes[] = getSizes();

I would set a break point just above.

>          int end = start + length;
>          int n = a.length - length;
>          a = new int[n];

What is a?

>          for (int i = 0; i<  start; i++) {
>              a[i] = sizes[i] ;
>          }
>          for (int i = start; i<  n; i++) {
>              a[i] = sizes[i+length] ;
>          }
>          setSizes(a);
>      }
> ========================================================================

[toc] | [prev] | [next] | [standalone]


#4944

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-16 14:55 -0500
Message-ID<jf1usq$39u$1@dont-email.me>
In reply to#4943
On 01/16/2012 02:48 PM, Jeff Higgins wrote:
> On 01/16/2012 01:34 PM, Novice wrote:
>> I'm getting an exception I don't understand when I attempt to delete all
>> the data in a small Jtable (46 rows, 3 columns).
>>
>> Here's the stacktrace; the "rowCount = 45" is a diagnostic I'm writing:
>> ========================================================================
>> rowCount = 45
>> Exception in thread "AWT-EventQueue-0"
>> java.lang.ArrayIndexOutOfBoundsException: 0
>> at javax.swing.SizeSequence.removeEntries(SizeSequence.java:383)
>
>> ... When I get to line 383 of that method, I get the same "cannot be
>> resolved to a variable" notation on EVERY variable in that line, even
>> variable i, which has just been explicitly set to 0.
>
> I don't see any line numbers in the code you have provided.
> I don't see a variable i in the code you have provided.

Oops! yea I do, the loop counter.
>>
>> Here's the complete code for this method:
>>
>> ========================================================================
>> /**
>> * Removes a contiguous group of entries
>> * from this<code>SizeSequence</code>.
>> * Note that the values of<code>start</code> and
>> *<code>length</code> must satisfy the following
>> * conditions:<code>(0<= start< getSizes().length)
>> * AND (length>= 0)</code>. If these conditions are
>> * not met, the behavior is unspecified and an exception
>> * may be thrown.
>
> Where are you checking these?
>
>> *
>> * @param start the index of the first entry to be removed
>> * @param length the number of entries to be removed
>> */
>> public void removeEntries(int start, int length) {
>> int sizes[] = getSizes();
>
> I would set a break point just above.
>
>> int end = start + length;
>> int n = a.length - length;
>> a = new int[n];
>
> What is a?
>
>> for (int i = 0; i< start; i++) {
>> a[i] = sizes[i] ;
>> }
>> for (int i = start; i< n; i++) {
>> a[i] = sizes[i+length] ;
>> }
>> setSizes(a);
>> }
>> ========================================================================
>

[toc] | [prev] | [next] | [standalone]


#4945

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-16 15:19 -0500
Message-ID<jf20am$cuv$1@dont-email.me>
In reply to#4943
On 01/16/2012 02:48 PM, Jeff Higgins wrote:
> On 01/16/2012 01:34 PM, Novice wrote:
>> I'm getting an exception I don't understand when I attempt to delete all
>> the data in a small Jtable (46 rows, 3 columns).
>>
>> Here's the stacktrace; the "rowCount = 45" is a diagnostic I'm writing:
>> ========================================================================
>> rowCount = 45
>> Exception in thread "AWT-EventQueue-0"
>> java.lang.ArrayIndexOutOfBoundsException: 0
>> at javax.swing.SizeSequence.removeEntries(SizeSequence.java:383)
>
>> ... When I get to line 383 of that method, I get the same "cannot be
>> resolved to a variable" notation on EVERY variable in that line, even
>> variable i, which has just been explicitly set to 0.
>
The java.lang.ArrayIndexOutOfBoundsException: 0
would seem to indicate a null reference to the array in question.
I cannot say which one it might be because:
> I don't see any line numbers in the code you have provided.
getSizes() might have initialized sizes to null, or a may be null.
> I don't see a variable i in the code you have provided.
>>
>> Here's the complete code for this method:
>>
>> ========================================================================
>> /**
>> * Removes a contiguous group of entries
>> * from this<code>SizeSequence</code>.
>> * Note that the values of<code>start</code> and
>> *<code>length</code> must satisfy the following
>> * conditions:<code>(0<= start< getSizes().length)
>> * AND (length>= 0)</code>. If these conditions are
>> * not met, the behavior is unspecified and an exception
>> * may be thrown.
>
> Where are you checking these?
>
>> *
>> * @param start the index of the first entry to be removed
>> * @param length the number of entries to be removed
>> */
>> public void removeEntries(int start, int length) {
>> int sizes[] = getSizes();
>
> I would set a break point just above.
>
>> int end = start + length;
>> int n = a.length - length;
>> a = new int[n];
>
> What is a?
>
>> for (int i = 0; i< start; i++) {
>> a[i] = sizes[i] ;
>> }
>> for (int i = start; i< n; i++) {
>> a[i] = sizes[i+length] ;
>> }
>> setSizes(a);
>> }
>> ========================================================================
>

[toc] | [prev] | [next] | [standalone]


#4946

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-16 15:31 -0500
Message-ID<jf211c$gg2$1@dont-email.me>
In reply to#4945
On 01/16/2012 03:19 PM, Jeff Higgins wrote:
> On 01/16/2012 02:48 PM, Jeff Higgins wrote:
>> On 01/16/2012 01:34 PM, Novice wrote:
>>> I'm getting an exception I don't understand when I attempt to delete all
>>> the data in a small Jtable (46 rows, 3 columns).
>>>
>>> Here's the stacktrace; the "rowCount = 45" is a diagnostic I'm writing:
>>> ========================================================================
>>> rowCount = 45
>>> Exception in thread "AWT-EventQueue-0"
>>> java.lang.ArrayIndexOutOfBoundsException: 0
>>> at javax.swing.SizeSequence.removeEntries(SizeSequence.java:383)
>>
>>> ... When I get to line 383 of that method, I get the same "cannot be
>>> resolved to a variable" notation on EVERY variable in that line, even
>>> variable i, which has just been explicitly set to 0.
>>
> The java.lang.ArrayIndexOutOfBoundsException: 0
> would seem to indicate a null reference to the array in question.
Oops! wrong again. Should be an empty array.
> I cannot say which one it might be because:
>> I don't see any line numbers in the code you have provided.
> getSizes() might have initialized sizes to null, or a may be null.
getSizes() might have returned an empty array or a might be empty.
>> I don't see a variable i in the code you have provided.
>>>
>>> Here's the complete code for this method:
>>>
>>> ========================================================================
>>> /**
>>> * Removes a contiguous group of entries
>>> * from this<code>SizeSequence</code>.
>>> * Note that the values of<code>start</code> and
>>> *<code>length</code> must satisfy the following
>>> * conditions:<code>(0<= start< getSizes().length)
>>> * AND (length>= 0)</code>. If these conditions are
>>> * not met, the behavior is unspecified and an exception
>>> * may be thrown.
>>
>> Where are you checking these?
>>
>>> *
>>> * @param start the index of the first entry to be removed
>>> * @param length the number of entries to be removed
>>> */
>>> public void removeEntries(int start, int length) {
>>> int sizes[] = getSizes();
>>
>> I would set a break point just above.
>>
>>> int end = start + length;
>>> int n = a.length - length;
>>> a = new int[n];
>>
>> What is a?
>>
>>> for (int i = 0; i< start; i++) {
>>> a[i] = sizes[i] ;
>>> }
>>> for (int i = start; i< n; i++) {
>>> a[i] = sizes[i+length] ;
>>> }
>>> setSizes(a);
>>> }
>>> ========================================================================
>>
>

[toc] | [prev] | [next] | [standalone]


#4947

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-16 17:57 -0500
Message-ID<jf29j4$8fn$1@dont-email.me>
In reply to#4946
I get:
java.lang.NegativeArraySizeException
	at NullTest.removeEntries(NullTest.java:43)
when I run this.
Maybe another precondition needs checking.


public class Test {

   private static int[] a = {};


   public static void main(String[] args) {

     try {
       removeEntries(0,3);
     } catch (Exception e) {
       e.printStackTrace();
     }

   }

   private static int[] getSizes() {
     return new int[]{1,2,3,4,5};
   }

   /**
    * Removes a contiguous group of entries
    * from this <code>SizeSequence</code>.
    * Note that the values of <code>start</code> and
    * <code>length</code> must satisfy the following
    * conditions:  <code>(0 <= start < getSizes().length)
    * AND (length >= 0)</code>.  If these conditions are
    * not met, the behavior is unspecified and an exception
    * may be thrown.
    *
    * @param start   the index of the first entry to be removed
    * @param length  the number of entries to be removed
    */
   public static void removeEntries(int start, int length) {
     assert getSizes() != null;
     assert 0 <= start;
     assert start < getSizes().length;
     assert length >= 0;
     assert a != null;
     int sizes[] = getSizes();
     //int end = start + length;
     int n = a.length - length;
     a = new int[n];
     for (int i = 0; i < start; i++) {
         a[i] = sizes[i] ;
     }
     for (int i = start; i < n; i++) {
         a[i] = sizes[i+length] ;
     }
     //setSizes(a);
}

[toc] | [prev] | [next] | [standalone]


#4949

FromNovice <novice@example..com>
Date2012-01-17 01:48 +0000
Message-ID<Xns9FDCD472333ABjpnasty@94.75.214.39>
In reply to#4943
Jeff Higgins <jeff@invalid.invalid> wrote in news:jf1ufa$kt$1@dont-
email.me:

> On 01/16/2012 01:34 PM, Novice wrote:
>> I'm getting an exception I don't understand when I attempt to delete all
>> the data in a small Jtable (46 rows, 3 columns).
>>
>> Here's the stacktrace; the "rowCount = 45" is a diagnostic I'm writing:
>> ========================================================================
>> rowCount = 45
>> Exception in thread "AWT-EventQueue-0"
>> java.lang.ArrayIndexOutOfBoundsException: 0
>>      at javax.swing.SizeSequence.removeEntries(SizeSequence.java:383)
> 
>> ... When I get to line 383 of that method, I get the same "cannot be
>> resolved to a variable" notation on EVERY variable in that line, even
>> variable i, which has just been explicitly set to 0.
> 
> I don't see any line numbers in the code you have provided.
> I don't see a variable i in the code you have provided.
>>
>> Here's the complete code for this method:
>>
>> ========================================================================
>>      /**
>>       * Removes a contiguous group of entries
>>       * from this<code>SizeSequence</code>.
>>       * Note that the values of<code>start</code>  and
>>       *<code>length</code>  must satisfy the following
>>       * conditions:<code>(0<= start<  getSizes().length)
>>       * AND (length>= 0)</code>.  If these conditions are
>>       * not met, the behavior is unspecified and an exception
>>       * may be thrown.
> 
> Where are you checking these?
> 
>>       *
>>       * @param start   the index of the first entry to be removed
>>       * @param length  the number of entries to be removed
>>       */
>>     public void removeEntries(int start, int length) {
>>          int sizes[] = getSizes();
> 
> I would set a break point just above.
> 
>>          int end = start + length;
>>          int n = a.length - length;
>>          a = new int[n];
> 
> What is a?
> 
>>          for (int i = 0; i<  start; i++) {
>>              a[i] = sizes[i] ;
>>          }
>>          for (int i = start; i<  n; i++) {
>>              a[i] = sizes[i+length] ;
>>          }
>>          setSizes(a);
>>      }
>> ========================================================================
> 

Sorry for the delay!

I've just stepped through the whole removeEntries() method until it 
crashed. I should mention that I downloaded a Java 1.7 JDK and JRE and I'm 
using _that_ version now. The code for this method looks the same but I 
might be missing a subtle difference. Here's the code, along with what I 
saw as I stepped through it:

    public void removeEntries(int start, int length) {
//Before executing the following line, start and length both show "cannot 
//be resolved to a variable". When I tried setting them as expressions in 
//the expressions monitor, I got "<error(s)_during_the_evaluation>" for 
//both variables
        int sizes[] = getSizes();
//getSizes() returns an int array of 45 items; each item has a value of 
//21
//when I inspect or inspect 'sizes' (without the brackets), I get "sizes 
//cannot be resolved to a variable. It's not clear if the assignment has 
//worked!
//Before this next line, 'start' and 'length' are still "cannot be 
//resolved to a variable."
        int end = start + length;
//After the assignment, 'end' "cannot be resolved to a variable"
//Before this next line, 'a' is an int array of 45 diverse integers and 
//'a.length is 45. 'length' "cannot be resolved to a variable"
        int n = a.length - length;
//After the preceding statement is executed, 'n' "cannot be resolved to a 
//variable" 
        a = new int[n];
//After the preceding statement is executed, 'a' has a value of "[]" (!!)
        for (int i = 0; i < start; i++) {
//Before the following line is executed the first time, 'i' should be zero 
//but Eclipse says "i cannot be resolved to a variable". 'sizes[i] cannot 
//be resolved to a variable". 
            a[i] = sizes[i] ;
//Upon executing the preceding line the first time through the loop, we get 
//the ArrayIndexOutOfBoundsException for an index value of 0
        }
        for (int i = start; i < n; i++) {
            a[i] = sizes[i+length] ;
        }
        setSizes(a);
    }


This seems REALLY messed up to me. I don't understand why all these 
variables "cannot be resolved to a variable". If they really don't have 
values, why doesn't it crash long before we get to the line where we get 
the exception? But if the variables do have values, why can't Eclipse show 
them to me? 

Since a newer JDK/JRE didn't resolve the problem and it happens 
consistently, I'm leaning toward Eclipse as being the problem here. I can't 
think of anything inappropriate that I'm doing in my code and I have to 
believe that the Java team tests these methods pretty thoroughly before 
putting them in a JDK.

Am I thinking along the right lines here? If so, what do I do next? I'd 
like my program to work without getting this apparently inappropriate 
exception but I'm not sure how to accomplish that....

-- 
Novice

[toc] | [prev] | [next] | [standalone]


#4950

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-17 03:22 -0500
Message-ID<jf3amd$1rr$1@dont-email.me>
In reply to#4949
On 01/16/2012 08:48 PM, Novice wrote:

>
> I've just stepped through the whole removeEntries() method until it
> crashed.

OK, your program crashes inside the removeEntries method - just as the 
stack trace indicated.

I should mention that I downloaded a Java 1.7 JDK and JRE and I'm
> using _that_ version now. The code for this method looks the same but I
> might be missing a subtle difference. Here's the code, along with what I
> saw as I stepped through it:

One way to decide on an update - I'm using Java 6.

>
>      public void removeEntries(int start, int length) {
> //Before executing the following line, start and length both show "cannot
> //be resolved to a variable". When I tried setting them as expressions in
> //the expressions monitor, I got "<error(s)_during_the_evaluation>" for
> //both variables

Have you disabled debug information in your project build settings?

>          int sizes[] = getSizes();
> //getSizes() returns an int array of 45 items; each item has a value of
> //21
> //when I inspect or inspect 'sizes' (without the brackets), I get "sizes
> //cannot be resolved to a variable. It's not clear if the assignment has
> //worked!
> //Before this next line, 'start' and 'length' are still "cannot be
> //resolved to a variable."
>          int end = start + length;
> //After the assignment, 'end' "cannot be resolved to a variable"
> //Before this next line, 'a' is an int array of 45 diverse integers and
> //'a.length is 45. 'length' "cannot be resolved to a variable"
>          int n = a.length - length;
> //After the preceding statement is executed, 'n' "cannot be resolved to a
> //variable"
>          a = new int[n];
> //After the preceding statement is executed, 'a' has a value of "[]" (!!)
>          for (int i = 0; i<  start; i++) {
> //Before the following line is executed the first time, 'i' should be zero
> //but Eclipse says "i cannot be resolved to a variable". 'sizes[i] cannot
> //be resolved to a variable".
>              a[i] = sizes[i] ;
> //Upon executing the preceding line the first time through the loop, we get
> //the ArrayIndexOutOfBoundsException for an index value of 0

Using the SSCCE that I provided elsethread, I can get your method to 
crash at the above line also. I cannot remember with what combinations 
of values.

>          }
>          for (int i = start; i<  n; i++) {
>              a[i] = sizes[i+length] ;
>          }
>          setSizes(a);
>      }
>
>
> This seems REALLY messed up to me. I don't understand why all these
> variables "cannot be resolved to a variable". If they really don't have
> values, why doesn't it crash long before we get to the line where we get
> the exception? But if the variables do have values, why can't Eclipse show
> them to me?
>
> Since a newer JDK/JRE didn't resolve the problem and it happens
> consistently, I'm leaning toward Eclipse as being the problem here. I can't
> think of anything inappropriate that I'm doing in my code and I have to
> believe that the Java team tests these methods pretty thoroughly before
> putting them in a JDK.

You could try another IDE, but that seems drastic.
Another option, you could employ javac and jdb outside the IDE.

>
> Am I thinking along the right lines here? If so, what do I do next? I'd
> like my program to work without getting this apparently inappropriate
> exception but I'm not sure how to accomplish that....

I'd take a deep breath, relax, become intimate with my debugger, and enjoy.
Really, try compiling and running the SSCCE I provided - do you get the 
variable not resolved?
One question. Why arrays here, instead of ArrayLists? The answer would 
probably be obvious knowing the rest of your code.


[toc] | [prev] | [next] | [standalone]


#4951

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-17 03:29 -0500
Message-ID<jf3b2g$2s1$1@dont-email.me>
In reply to#4950
On 01/17/2012 03:22 AM, Jeff Higgins wrote:

>
> You could try another IDE, but that seems drastic.
> Another option, you could employ javac and jdb outside the IDE.
You might also try inserting some logging statements at key points.

[toc] | [prev] | [next] | [standalone]


#4952

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-17 03:49 -0500
Message-ID<jf3c87$8k3$1@dont-email.me>
In reply to#4950
On 01/17/2012 03:22 AM, Jeff Higgins wrote:

> I'd take a deep breath, relax, become intimate with my tools, and enjoy.

[toc] | [prev] | [next] | [standalone]


#4953

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-17 03:55 -0500
Message-ID<jf3cjt$a4r$1@dont-email.me>
In reply to#4950
On 01/17/2012 03:22 AM, Jeff Higgins wrote:

> Using the SSCCE that I provided elsethread, I can get your method to
> crash at the above line also. I cannot remember with what combinations
> of values.
But not with assertions enabled I think, cannot remember.

[toc] | [prev] | [next] | [standalone]


#4954

FromNovice <novice@example..com>
Date2012-01-17 22:21 +0000
Message-ID<Xns9FDDB0B11D330jpnasty@94.75.214.39>
In reply to#4950
Jeff Higgins <jeff@invalid.invalid> wrote in
news:jf3amd$1rr$1@dont-email.me: 

> On 01/16/2012 08:48 PM, Novice wrote:
> 
>>
>> I've just stepped through the whole removeEntries() method until it
>> crashed.
> 
> OK, your program crashes inside the removeEntries method - just as the
> stack trace indicated.
> 
> I should mention that I downloaded a Java 1.7 JDK and JRE and I'm
>> using _that_ version now. The code for this method looks the same but
>> I might be missing a subtle difference. Here's the code, along with
>> what I saw as I stepped through it:
> 
> One way to decide on an update - I'm using Java 6.
> 
Since Java 7 didn't change anything except the line number (the failing 
line number is 400 in Java 7), I've reverted to running Java 6.18.
>>
>>      public void removeEntries(int start, int length) {
>> //Before executing the following line, start and length both show
>> "cannot //be resolved to a variable". When I tried setting them as
>> expressions in //the expressions monitor, I got
>> "<error(s)_during_the_evaluation>" for //both variables
> 
> Have you disabled debug information in your project build settings?
> 
I've looked around and I'm not finding any such settings. Can you please 
be specific on which menu I should check and which specific settings I'd 
have had to mess with? (I don't think I've EVER messed with the debug 
settings but I might as well look, just in case I did at some point and 
forgot. Or a new version of Eclipse had unexpected values for some 
settings.)

>>          int sizes[] = getSizes();
>> //getSizes() returns an int array of 45 items; each item has a value
>> of //21
>> //when I inspect or inspect 'sizes' (without the brackets), I get
>> "sizes //cannot be resolved to a variable. It's not clear if the
>> assignment has //worked!
>> //Before this next line, 'start' and 'length' are still "cannot be
>> //resolved to a variable."
>>          int end = start + length;
>> //After the assignment, 'end' "cannot be resolved to a variable"
>> //Before this next line, 'a' is an int array of 45 diverse integers
>> and //'a.length is 45. 'length' "cannot be resolved to a variable"
>>          int n = a.length - length;
>> //After the preceding statement is executed, 'n' "cannot be resolved
>> to a //variable"
>>          a = new int[n];
>> //After the preceding statement is executed, 'a' has a value of "[]"
>> (!!) 
>>          for (int i = 0; i<  start; i++) {
>> //Before the following line is executed the first time, 'i' should be
>> zero //but Eclipse says "i cannot be resolved to a variable".
>> 'sizes[i] cannot //be resolved to a variable".
>>              a[i] = sizes[i] ;
>> //Upon executing the preceding line the first time through the loop,
>> we get //the ArrayIndexOutOfBoundsException for an index value of 0
> 
> Using the SSCCE that I provided elsethread, I can get your method to 
> crash at the above line also. I cannot remember with what combinations
> of values.
> 
>>          }
>>          for (int i = start; i<  n; i++) {
>>              a[i] = sizes[i+length] ;
>>          }
>>          setSizes(a);
>>      }
>>
When I used your SSCCE, it crashed at line 44 (a = new int[n];) which is 
just above that point. I'm not sure what the significance of that is 
though. I'm really not quite sure what your SSCCE is trying to do.

For what it's worth, I created my own SSCCE which is somewhat longer than 
yours but more closely parallels what my problem code is doing. It works 
fine though. It doesn't crash and I'm not getting any of the "cannot be 
resolved to a variable" nonsense when I try to debug. I put my SSCCE (and 
yours) in the same project as the one that is blowing up so they must be 
using the same settings/compiler/etc. 

>>
>> This seems REALLY messed up to me. I don't understand why all these
>> variables "cannot be resolved to a variable". If they really don't
>> have values, why doesn't it crash long before we get to the line
>> where we get the exception? But if the variables do have values, why
>> can't Eclipse show them to me?
>>
>> Since a newer JDK/JRE didn't resolve the problem and it happens
>> consistently, I'm leaning toward Eclipse as being the problem here. I
>> can't think of anything inappropriate that I'm doing in my code and I
>> have to believe that the Java team tests these methods pretty
>> thoroughly before putting them in a JDK.
> 
> You could try another IDE, but that seems drastic.
> Another option, you could employ javac and jdb outside the IDE.
> 
Can you flesh that out a bit. I have used raw javac a long time ago 
before I got my first proper editor but I'm not sure what that and jdb 
will prove here. Are we just trying to establish whether Eclipse and it's 
compiler are the culprits?
 
>>
>> Am I thinking along the right lines here? If so, what do I do next?
>> I'd like my program to work without getting this apparently
>> inappropriate exception but I'm not sure how to accomplish that....
> 
> I'd take a deep breath, relax, become intimate with my debugger, and
> enjoy. Really, try compiling and running the SSCCE I provided - do you
> get the variable not resolved?

Your SSCCE has VERY different behavior than mine.

Yours actually has values for all of the variables until well into the 
method. 'start' and 'length' begin as 0 and 3 respectively. getSizes() 
initially contains [1, 2, 3, 4, 5]. 'getSizes.length' is 5. 'a' is empty. 
After "int[] sizes = getSize();", 'sizes' contains [1,2,3,4,5]. 
'a.length' is 0. 'length' remains 3. 'n' is -3. (0-3). Not surprisingly, 
Java doesn't like the line "a = int[n]" when n is -3 and this causes the 
exception just before we get to the first loop. 

I've just tried my code again but it's still doing the same nonsense as 
before. 'getSizes()' actually returns a very reasonable array but after 
assigning it to 'sizes', I get the "cannot be resolved to a variable" 
message again. 'start' and 'length' have the same issues on entry to the 
method. And so it goes until the first iteration of the first loop when 
it crashes again on the ArrayIndexOutOfBoundsException because the index 
is 0. 

I can't figure out if "cannot be resolved to a variable" proves that the 
debugger is messed up or if it is only masking the underlying error. 
Maybe something that should be in scope isn't for some reason??

> One question. Why arrays here, instead of ArrayLists? The answer would
> probably be obvious knowing the rest of your code.

I don't honestly know. My table model actually consists of a Vector of 
rows, not an array or a Vector of Vectors. The rows being stored in the 
Vector have their own custom class that consists of three String fields, 
one for each of the columns of the JTable. The list of column names to be 
used in the header is an array but that's just about the only one in the 
entire program, aside from some local ones used to determine the widest 
values in each column. 

getSizes() is getting an array of 45 entries and that surely corresponds 
to the number of rows in the table. From looking at getSizes(), it seems 
as if it might be keeping track of sizes of cells or something like that. 

--
One strange thing jumped out at me when I was debugging my code just now. 
A System.out.println() that I'd put into another method for a couple of 
minutes and then deleted is still being executed when I do that method 
(which sets the column widths of the table). That is REALLY bizarre and 
suggests that I'm executing a slightly older version of the program. I 
don't see how that bears on exception I'm getting but it may point to the 
solution anyway: if I actually executed the code I want to execute, maybe 
the exception wouldn't be happening. Why would the debugger execute a 
different version of the code than it is displaying??

--
Rhino

















-- 
Novice

[toc] | [prev] | [next] | [standalone]


#4955

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-17 18:18 -0500
Message-ID<jf4v54$hd0$1@dont-email.me>
In reply to#4954
On 01/17/2012 05:21 PM, Novice wrote:
> Jeff Higgins<jeff@invalid.invalid>  wrote in
> news:jf3amd$1rr$1@dont-email.me:
>
>> On 01/16/2012 08:48 PM, Novice wrote:
>>
>>>
>>> I've just stepped through the whole removeEntries() method until it
>>> crashed.
>>
>> OK, your program crashes inside the removeEntries method - just as the
>> stack trace indicated.
>>
>> I should mention that I downloaded a Java 1.7 JDK and JRE and I'm
>>> using _that_ version now. The code for this method looks the same but
>>> I might be missing a subtle difference. Here's the code, along with
>>> what I saw as I stepped through it:
>>
>> One way to decide on an update - I'm using Java 6.
>>
> Since Java 7 didn't change anything except the line number (the failing
> line number is 400 in Java 7), I've reverted to running Java 6.18.
>>>
>>>       public void removeEntries(int start, int length) {
>>> //Before executing the following line, start and length both show
>>> "cannot //be resolved to a variable". When I tried setting them as
>>> expressions in //the expressions monitor, I got
>>> "<error(s)_during_the_evaluation>" for //both variables
>>
>> Have you disabled debug information in your project build settings?
>>
> I've looked around and I'm not finding any such settings. Can you please
> be specific on which menu I should check and which specific settings I'd
> have had to mess with? (I don't think I've EVER messed with the debug
> settings but I might as well look, just in case I did at some point and
> forgot. Or a new version of Eclipse had unexpected values for some
> settings.)

 From the main menu:
Project>Properties>Java Compiler>Classfile Generation

>
>>>           int sizes[] = getSizes();
>>> //getSizes() returns an int array of 45 items; each item has a value
>>> of //21
>>> //when I inspect or inspect 'sizes' (without the brackets), I get
>>> "sizes //cannot be resolved to a variable. It's not clear if the
>>> assignment has //worked!
>>> //Before this next line, 'start' and 'length' are still "cannot be
>>> //resolved to a variable."
>>>           int end = start + length;
>>> //After the assignment, 'end' "cannot be resolved to a variable"
>>> //Before this next line, 'a' is an int array of 45 diverse integers
>>> and //'a.length is 45. 'length' "cannot be resolved to a variable"
>>>           int n = a.length - length;
>>> //After the preceding statement is executed, 'n' "cannot be resolved
>>> to a //variable"
>>>           a = new int[n];
>>> //After the preceding statement is executed, 'a' has a value of "[]"
>>> (!!)
>>>           for (int i = 0; i<   start; i++) {
>>> //Before the following line is executed the first time, 'i' should be
>>> zero //but Eclipse says "i cannot be resolved to a variable".
>>> 'sizes[i] cannot //be resolved to a variable".
>>>               a[i] = sizes[i] ;
>>> //Upon executing the preceding line the first time through the loop,
>>> we get //the ArrayIndexOutOfBoundsException for an index value of 0
>>
>> Using the SSCCE that I provided elsethread, I can get your method to
>> crash at the above line also. I cannot remember with what combinations
>> of values.
>>
>>>           }
>>>           for (int i = start; i<   n; i++) {
>>>               a[i] = sizes[i+length] ;
>>>           }
>>>           setSizes(a);
>>>       }
>>>
> When I used your SSCCE, it crashed at line 44 (a = new int[n];) which is
> just above that point. I'm not sure what the significance of that is
> though.

Then you must spend some more time pondering it.

I'm really not quite sure what your SSCCE is trying to do.

I wrapped your method removeEntries() verbatim into a test class and 
provided a int[]getSizes() and an int[]a at class scope - because that 
where they looked to be in relation to your removeEntries method. I 
placed a call to your removeEntries method inside a try block inside an 
executable main method.

The intent was to provide you a free playground to experiment with the 
values of the variables - only you know what these values should be.

My SSCCE is currently trying desperately to break out of my scratch project.

>
> For what it's worth, I created my own SSCCE which is somewhat longer than
> yours but more closely parallels what my problem code is doing.It works
> fine though. It doesn't crash and I'm not getting any of the "cannot be
> resolved to a variable" nonsense when I try to debug. I put my SSCCE (and
> yours) in the same project as the one that is blowing up so they must be
> using the same settings/compiler/etc.
>
>>>
>>> This seems REALLY messed up to me. I don't understand why all these
>>> variables "cannot be resolved to a variable". If they really don't
>>> have values, why doesn't it crash long before we get to the line
>>> where we get the exception? But if the variables do have values, why
>>> can't Eclipse show them to me?
>>>
>>> Since a newer JDK/JRE didn't resolve the problem and it happens
>>> consistently, I'm leaning toward Eclipse as being the problem here. I
>>> can't think of anything inappropriate that I'm doing in my code and I
>>> have to believe that the Java team tests these methods pretty
>>> thoroughly before putting them in a JDK.
>>
>> You could try another IDE, but that seems drastic.
>> Another option, you could employ javac and jdb outside the IDE.
>>
> Can you flesh that out a bit. I have used raw javac a long time ago
> before I got my first proper editor but I'm not sure what that and jdb
> will prove here. Are we just trying to establish whether Eclipse and it's
> compiler are the culprits?

Yep.

>
>>>
>>> Am I thinking along the right lines here? If so, what do I do next?
>>> I'd like my program to work without getting this apparently
>>> inappropriate exception but I'm not sure how to accomplish that....
>>
>> I'd take a deep breath, relax, become intimate with my debugger, and
>> enjoy. Really, try compiling and running the SSCCE I provided - do you
>> get the variable not resolved?
>
> Your SSCCE has VERY different behavior than mine.

I am not VERY surprised.

>
> Yours actually has values for all of the variables until well into the
> method. 'start' and 'length' begin as 0 and 3 respectively. getSizes()
> initially contains [1, 2, 3, 4, 5]. 'getSizes.length' is 5. 'a' is empty.
> After "int[] sizes = getSize();", 'sizes' contains [1,2,3,4,5].
> 'a.length' is 0. 'length' remains 3. 'n' is -3. (0-3). Not surprisingly,
> Java doesn't like the line "a = int[n]" when n is -3 and this causes the
> exception just before we get to the first loop.
>
> I've just tried my code again but it's still doing the same nonsense as
> before. 'getSizes()' actually returns a very reasonable array but after
> assigning it to 'sizes', I get the "cannot be resolved to a variable"
> message again. 'start' and 'length' have the same issues on entry to the
> method. And so it goes until the first iteration of the first loop when
> it crashes again on the ArrayIndexOutOfBoundsException because the index
> is 0.
>
> I can't figure out if "cannot be resolved to a variable" proves that the
> debugger is messed up or if it is only masking the underlying error.
> Maybe something that should be in scope isn't for some reason??
>
>> One question. Why arrays here, instead of ArrayLists? The answer would
>> probably be obvious knowing the rest of your code.
>
> I don't honestly know. My table model actually consists of a Vector of
> rows, not an array or a Vector of Vectors. The rows being stored in the
> Vector have their own custom class that consists of three String fields,
> one for each of the columns of the JTable. The list of column names to be
> used in the header is an array but that's just about the only one in the
> entire program, aside from some local ones used to determine the widest
> values in each column.

You are trolling now.

>
> getSizes() is getting an array of 45 entries and that surely corresponds
> to the number of rows in the table. From looking at getSizes(), it seems
> as if it might be keeping track of sizes of cells or something like that.
>
>
> One strange thing jumped out at me when I was debugging my code just now.
> A System.out.println() that I'd put into another method for a couple of
> minutes and then deleted is still being executed when I do that method
> (which sets the column widths of the table). That is REALLY bizarre and
> suggests that I'm executing a slightly older version of the program. I
> don't see how that bears on exception I'm getting but it may point to the
> solution anyway: if I actually executed the code I want to execute, maybe
> the exception wouldn't be happening. Why would the debugger execute a
> different version of the code than it is displaying??
>
No rest for the weary.

[toc] | [prev] | [next] | [standalone]


#4957

FromJeff Higgins <jeff@invalid.invalid>
Date2012-01-17 20:56 -0500
Message-ID<jf58dl$1tf$1@dont-email.me>
In reply to#4955
On 01/17/2012 06:18 PM, Jeff Higgins wrote:

> No rest for the weary.
It seems that your difficulties are so far outside my experience that 
I'm not sure how to proceed. I would interested in hearing how you 
finally sort it all out.


[toc] | [prev] | [next] | [standalone]


#4958

FromNovice <novice@example..com>
Date2012-01-18 05:24 +0000
Message-ID<Xns9FDE41905AF7jpnasty@94.75.214.39>
In reply to#4957
Jeff Higgins <jeff@invalid.invalid> wrote in news:jf58dl$1tf$1@dont-
email.me:

> On 01/17/2012 06:18 PM, Jeff Higgins wrote:
> 
>> No rest for the weary.
> It seems that your difficulties are so far outside my experience that 
> I'm not sure how to proceed. I would interested in hearing how you 
> finally sort it all out.
> 

Yikes! I'm completely baffled. You seemed like you had a plan and were 
heading in the right direction so I was hoping you'd figure this enough 
that I could do what had to be done after that....

Well, I don't blame you for wanting to get back to your own work. It's not 
really your problem and I've got no right to drag you into this. Maybe I 
should file a bug report with Bugzilla and let Oracle figure it out ;-) 
Then again, I really don't want to give them my entire program and coming 
up with an SSCCE for it is something of a problem....

Maybe I'll have to destroy the entire table and/or table model rather than 
just deleting the rows to bypass this problem. It's a bit ugly but might be 
less painful in the long run. 

I'll post a new thread back here if I figure out the current problem. If 
you don't hear from me, I've probably gone a different way, like nulling 
out the whole table and model, to avoid the problem. 





-- 
Novice

[toc] | [prev] | [next] | [standalone]


#4964

FromNovice <novice@example..com>
Date2012-01-18 17:40 +0000
Message-ID<Xns9FDE8122BF4A6jpnasty@94.75.214.39>
In reply to#4958
Novice <novice@example..com> wrote in
news:Xns9FDE41905AF7jpnasty@94.75.214.39: 

> Jeff Higgins <jeff@invalid.invalid> wrote in news:jf58dl$1tf$1@dont-
> email.me:
> 
>> On 01/17/2012 06:18 PM, Jeff Higgins wrote:
>> 
>>> No rest for the weary.
>> It seems that your difficulties are so far outside my experience that
>> I'm not sure how to proceed. I would interested in hearing how you 
>> finally sort it all out.
>> 
> 
> Yikes! I'm completely baffled. You seemed like you had a plan and were
> heading in the right direction so I was hoping you'd figure this
> enough that I could do what had to be done after that....
> 
> Well, I don't blame you for wanting to get back to your own work. It's
> not really your problem and I've got no right to drag you into this.
> Maybe I should file a bug report with Bugzilla and let Oracle figure
> it out ;-) Then again, I really don't want to give them my entire
> program and coming up with an SSCCE for it is something of a
> problem.... 
> 
> Maybe I'll have to destroy the entire table and/or table model rather
> than just deleting the rows to bypass this problem. It's a bit ugly
> but might be less painful in the long run. 
> 
> I'll post a new thread back here if I figure out the current problem.
> If you don't hear from me, I've probably gone a different way, like
> nulling out the whole table and model, to avoid the problem. 
> 

I figured out a really simple workaround to the problem. I simply 
executed fireTableDataChanged() instead of fireTableRowsDeleted() and my 
problem went away. All the rows in the JTable now disappear cleanly, just 
as they should. 

It doesn't explain the mystery of why fireTableRowsDeleted() chokes but 
I've invested several hours on trying to make sense of that without 
making much headway. I'll let my workaround ride for now and get on to 
other more urgent tasks for now. 

If I can find a bit of time down the road, I'll revisit the original 
issue and see if I can figure it out. But, honestly, I'm doubtful that 
I'll be back to it. This works fine and there are no bad consequences to 
it that would push me to solve the problem with fireTableRowsDeleted().

Thanks for your help with this, Jeff! Even if we didn't figure it out, I 
appreciate that you were willing to help and spent some time trying to 
figure it out!

-- 
Novice

[toc] | [prev] | [next] | [standalone]


#4959

FromNovice <novice@example..com>
Date2012-01-18 05:37 +0000
Message-ID<Xns9FDE65A1FBA7jpnasty@94.75.214.39>
In reply to#4955
Jeff Higgins <jeff@invalid.invalid> wrote in
news:jf4v54$hd0$1@dont-email.me: 

> On 01/17/2012 05:21 PM, Novice wrote:
>> Jeff Higgins<jeff@invalid.invalid>  wrote in
>> news:jf3amd$1rr$1@dont-email.me:
>>
>>> On 01/16/2012 08:48 PM, Novice wrote:
>>>
>>>>
>>>> I've just stepped through the whole removeEntries() method until it
>>>> crashed.
>>>
>>> OK, your program crashes inside the removeEntries method - just as
>>> the stack trace indicated.
>>>
>>> I should mention that I downloaded a Java 1.7 JDK and JRE and I'm
>>>> using _that_ version now. The code for this method looks the same
>>>> but I might be missing a subtle difference. Here's the code, along
>>>> with what I saw as I stepped through it:
>>>
>>> One way to decide on an update - I'm using Java 6.
>>>
>> Since Java 7 didn't change anything except the line number (the
>> failing line number is 400 in Java 7), I've reverted to running Java
>> 6.18. 
>>>>
>>>>       public void removeEntries(int start, int length) {
>>>> //Before executing the following line, start and length both show
>>>> "cannot //be resolved to a variable". When I tried setting them as
>>>> expressions in //the expressions monitor, I got
>>>> "<error(s)_during_the_evaluation>" for //both variables
>>>
>>> Have you disabled debug information in your project build settings?
>>>
>> I've looked around and I'm not finding any such settings. Can you
>> please be specific on which menu I should check and which specific
>> settings I'd have had to mess with? (I don't think I've EVER messed
>> with the debug settings but I might as well look, just in case I did
>> at some point and forgot. Or a new version of Eclipse had unexpected
>> values for some settings.)
> 
>  From the main menu:
> Project>Properties>Java Compiler>Classfile Generation
> 
When I go to the Java Compiler page, I see that everything below Enable 
Project Specific Settings is grayed out. "Use default compliance 
settings" is grayed out too but checked. "Generated classfile compliance 
is likewise grayed out but set to 1.6." I assume that is all as it should 
be; correct me if I'm wrong. 
>>
>>>>           int sizes[] = getSizes();
>>>> //getSizes() returns an int array of 45 items; each item has a
>>>> value of //21
>>>> //when I inspect or inspect 'sizes' (without the brackets), I get
>>>> "sizes //cannot be resolved to a variable. It's not clear if the
>>>> assignment has //worked!
>>>> //Before this next line, 'start' and 'length' are still "cannot be
>>>> //resolved to a variable."
>>>>           int end = start + length;
>>>> //After the assignment, 'end' "cannot be resolved to a variable"
>>>> //Before this next line, 'a' is an int array of 45 diverse integers
>>>> and //'a.length is 45. 'length' "cannot be resolved to a variable"
>>>>           int n = a.length - length;
>>>> //After the preceding statement is executed, 'n' "cannot be
>>>> resolved to a //variable"
>>>>           a = new int[n];
>>>> //After the preceding statement is executed, 'a' has a value of
>>>> "[]" (!!)
>>>>           for (int i = 0; i<   start; i++) {
>>>> //Before the following line is executed the first time, 'i' should
>>>> be zero //but Eclipse says "i cannot be resolved to a variable".
>>>> 'sizes[i] cannot //be resolved to a variable".
>>>>               a[i] = sizes[i] ;
>>>> //Upon executing the preceding line the first time through the
>>>> loop, we get //the ArrayIndexOutOfBoundsException for an index
>>>> value of 0 
>>>
>>> Using the SSCCE that I provided elsethread, I can get your method to
>>> crash at the above line also. I cannot remember with what
>>> combinations of values.
>>>
>>>>           }
>>>>           for (int i = start; i<   n; i++) {
>>>>               a[i] = sizes[i+length] ;
>>>>           }
>>>>           setSizes(a);
>>>>       }
>>>>
>> When I used your SSCCE, it crashed at line 44 (a = new int[n];) which
>> is just above that point. I'm not sure what the significance of that
>> is though.
> 
> Then you must spend some more time pondering it.
> 
> I'm really not quite sure what your SSCCE is trying to do.
> 
> I wrapped your method removeEntries() verbatim into a test class and 
> provided a int[]getSizes() and an int[]a at class scope - because that
> where they looked to be in relation to your removeEntries method. I 
> placed a call to your removeEntries method inside a try block inside
> an executable main method.
> 
> The intent was to provide you a free playground to experiment with the
> values of the variables - only you know what these values should be.
> 
> My SSCCE is currently trying desperately to break out of my scratch
> project. 
> 
>>
>> For what it's worth, I created my own SSCCE which is somewhat longer
>> than yours but more closely parallels what my problem code is
>> doing.It works fine though. It doesn't crash and I'm not getting any
>> of the "cannot be resolved to a variable" nonsense when I try to
>> debug. I put my SSCCE (and yours) in the same project as the one that
>> is blowing up so they must be using the same settings/compiler/etc.
>>
>>>>
>>>> This seems REALLY messed up to me. I don't understand why all these
>>>> variables "cannot be resolved to a variable". If they really don't
>>>> have values, why doesn't it crash long before we get to the line
>>>> where we get the exception? But if the variables do have values,
>>>> why can't Eclipse show them to me?
>>>>
>>>> Since a newer JDK/JRE didn't resolve the problem and it happens
>>>> consistently, I'm leaning toward Eclipse as being the problem here.
>>>> I can't think of anything inappropriate that I'm doing in my code
>>>> and I have to believe that the Java team tests these methods pretty
>>>> thoroughly before putting them in a JDK.
>>>
>>> You could try another IDE, but that seems drastic.
>>> Another option, you could employ javac and jdb outside the IDE.
>>>
>> Can you flesh that out a bit. I have used raw javac a long time ago
>> before I got my first proper editor but I'm not sure what that and
>> jdb will prove here. Are we just trying to establish whether Eclipse
>> and it's compiler are the culprits?
> 
> Yep.
> 
Another IDE would do that too. It might be easier to just download one of 
those, just to try this one program, then delete it again once we've 
figured out this problem.
>>
>>>>
>>>> Am I thinking along the right lines here? If so, what do I do next?
>>>> I'd like my program to work without getting this apparently
>>>> inappropriate exception but I'm not sure how to accomplish that....
>>>
>>> I'd take a deep breath, relax, become intimate with my debugger, and
>>> enjoy. Really, try compiling and running the SSCCE I provided - do
>>> you get the variable not resolved?
>>
>> Your SSCCE has VERY different behavior than mine.
> 
> I am not VERY surprised.
> 
>>
>> Yours actually has values for all of the variables until well into
>> the method. 'start' and 'length' begin as 0 and 3 respectively.
>> getSizes() initially contains [1, 2, 3, 4, 5]. 'getSizes.length' is
>> 5. 'a' is empty. After "int[] sizes = getSize();", 'sizes' contains
>> [1,2,3,4,5]. 'a.length' is 0. 'length' remains 3. 'n' is -3. (0-3).
>> Not surprisingly, Java doesn't like the line "a = int[n]" when n is
>> -3 and this causes the exception just before we get to the first
>> loop. 
>>
>> I've just tried my code again but it's still doing the same nonsense
>> as before. 'getSizes()' actually returns a very reasonable array but
>> after assigning it to 'sizes', I get the "cannot be resolved to a
>> variable" message again. 'start' and 'length' have the same issues on
>> entry to the method. And so it goes until the first iteration of the
>> first loop when it crashes again on the
>> ArrayIndexOutOfBoundsException because the index is 0.
>>
>> I can't figure out if "cannot be resolved to a variable" proves that
>> the debugger is messed up or if it is only masking the underlying
>> error. Maybe something that should be in scope isn't for some
>> reason?? 
>>
>>> One question. Why arrays here, instead of ArrayLists? The answer
>>> would probably be obvious knowing the rest of your code.
>>
>> I don't honestly know. My table model actually consists of a Vector
>> of rows, not an array or a Vector of Vectors. The rows being stored
>> in the Vector have their own custom class that consists of three
>> String fields, one for each of the columns of the JTable. The list of
>> column names to be used in the header is an array but that's just
>> about the only one in the entire program, aside from some local ones
>> used to determine the widest values in each column.
> 
> You are trolling now.
> 
Typically, trolling means saying stuff you don't believe just to get a 
rise out of someone. Maybe you have something different in mind? 
Seriously, I am not making anything up here. The things I'm describing 
ARE happening as I've described.
>>
>> getSizes() is getting an array of 45 entries and that surely
>> corresponds to the number of rows in the table. From looking at
>> getSizes(), it seems as if it might be keeping track of sizes of
>> cells or something like that. 
>>
>>
>> One strange thing jumped out at me when I was debugging my code just
>> now. A System.out.println() that I'd put into another method for a
>> couple of minutes and then deleted is still being executed when I do
>> that method (which sets the column widths of the table). That is
>> REALLY bizarre and suggests that I'm executing a slightly older
>> version of the program. I don't see how that bears on exception I'm
>> getting but it may point to the solution anyway: if I actually
>> executed the code I want to execute, maybe the exception wouldn't be
>> happening. Why would the debugger execute a different version of the
>> code than it is displaying?? 
>>
> No rest for the weary.

You've got that right ;-) 
> 
> 





-- 
Novice

[toc] | [prev] | [next] | [standalone]


#4970

FromChristian Kaufhold <chka@ucuri.chka.de>
Date2012-01-19 21:00 +0100
Message-ID<3b9mu8-5v.ln1@ucuri.chka.de>
In reply to#4942
Novice <novice@example..com> wrote:

>        public int deleteAllRows() {
> 
>                String METHOD_NAME = "deleteAllRows()"; //$NON-NLS-1$
>                if (DEBUG) this.logger.entering(this.CLASS_NAME, METHOD_NAME);
>                
>                int rowCount = getRowCount();
>                //FIXME: remove the next line
>                System.err.println("rowCount = " + rowCount); //temporary 
> 
>                this.phraseList.removeAllElements();
>                fireTableRowsDeleted(1, rowCount);


Rows indices are zero-based on inclusive on both sides. So this must be

                 if (rowCount > 0)
		      fireTableRowsDeleted(0, rowCount -1);

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web