Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 29

Thread: cell size excel and java

  1. #1
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default cell size excel and java

    Since the size () method exists with Arrraylist, to know the size of the elements.

    Instead using apache then how can I know the cell size in excel, to know how many records there are?

    public void fillDispositivoVeicoloIDVEICOLO() {
      for (int rowIndex = 1; rowIndex < 281 ; rowIndex++) {
           currentRow = dataTypeSheet.getRow(rowIndex);
           cell_id_veicolo = currentRow.getCell(8); // Cella I
           id_veicolo.add(cell_id_veicolo.getStringCellValue());
       }
           System.out.println(id_veicolo);
    }

    instead of 281 what should I put in it? given that in Excel there are 281 records?

    --- Update ---

    public void fillDispositivoVeicoloIDVEICOLO() {
      for (int rowIndex = 1; rowIndex < dataTypeSheet.getLastRowNum() ; rowIndex++) {
           currentRow = dataTypeSheet.getRow(rowIndex);
           cell_id_veicolo = currentRow.getCell(8); // Cella I
           id_veicolo.add(cell_id_veicolo.getStringCellValue());
       }
           System.out.println(id_veicolo);
    }

    Error:
    Exception in thread "main" java.lang.NullPointerException
    at it.cliente.Cliente.fillVeicoloId(Cliente.java:112)
    at it.cliente.Test.main(Test.java:15)

    dataTypeSheet.getLastRowNum() -->
    returns me 1000

    the error is here:
    id_veicolo.add(cell_id_veicolo.getStringCellValue( ));


    now it works but the problem is always the index

    public void fillTarga() {
    		for (int rowIndex = 1; rowIndex < dataTypeSheet.getPhysicalNumberOfRows(); rowIndex++) {
    			currentRow = dataTypeSheet.getRow(rowIndex);
    			cell_targa = currentRow.getCell(21); // Cella V
    			if( cell_targa != null)
    			targa.add(cell_targa.getStringCellValue());
    		}
     
    		System.out.println(targa);
    	}
     
    Error:
    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 12, Size: 12
    at java.util.ArrayList.rangeCheck(ArrayList.java:657)
    at java.util.ArrayList.get(ArrayList.java:433)
    at it.cliente.Confrontare.confrontaTargheVeicolo(Confrontare.java:97)
    at it.cliente.Test.main(Test.java:10)
    Last edited by glprobot; July 18th, 2019 at 04:38 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    What class is dataTypeSheet? Is there API doc for that class that describes what you need to use it?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    I used this bee, because I don't know how to do it. Are there other alternatives?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    Are there other alternatives?
    I do not know.

    What class is dataTypeSheet? Is there API doc for that class that describes what you need to use it?
    Please post a link to the API doc for the class.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    XSSFSheet dataTypeSheet

    The indices are driving me crazy

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    Please post a link to the API doc for the class
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 12, Size: 12
    at java.util.ArrayList.rangeCheck(ArrayList.java:657)
    at java.util.ArrayList.get(ArrayList.java:433)
    at it.cliente.Confrontare.confrontaTargheVeicolo(Conf rontare.java:97)
    What statement is at line 97?
    Why does that statement use an index past the end? If the list has 12 elements, then 11 is the maximum index allowed.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    for (clienteIndex = 0; clienteIndex < cliente.getVeicoloId().size(); clienteIndex++) {
    			boolean match = false;
    			for (veicoloIndex = 0; veicoloIndex < veicolo.getVeicoloId().size(); veicoloIndex++) {
     
                            Error:
                            at it.cliente.Confrontare.confrontaTargheVeicolo(Conf rontare.java:97)
     97: 				if (cliente.getTarga().get(clienteIndex).equals(veicolo.getTarga().get(veicoloIndex))) {
    					match = true;


    Here I always get the error


    I have tried in all ways I always error indexes



    cliente.getTarga()
    // VEICOLO TARGA
    	public void fillTarga() {
    		for (int rowIndex = 0; rowIndex < dataTypeSheet.getPhysicalNumberOfRows(); rowIndex++) {
    			currentRow = dataTypeSheet.getRow(rowIndex);
    			cell_targa = currentRow.getCell(21); // Cella V
    			if( cell_targa != null)
    			targa.add(cell_targa.getStringCellValue());
    		}
     
    		System.out.println(targa);
    	}


    veicolo.getTarga()
    public void fillTarga() {
    		for (int rowIndex = 0; rowIndex < dataTypeSheet.getPhysicalNumberOfRows(); rowIndex++) {
    			currentRow = dataTypeSheet.getRow(rowIndex);
    			cell_targa = currentRow.getCell(11); // Cella L
     
    			if (cell_targa != null)
    				targa.add(cell_targa.getStringCellValue());
    		}
     
    		System.out.println(targa);
    	}

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    always error indexes
    I see 2 indexes. Which one has the invalid value in it?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    cliente.getTarga()

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    cliente.getTarga()
    Does that mean the index variable: clienteIndex has the wrong value?

    Why does the code get the index value control value from cliente.getVeicoloId().size()
    but uses the index in cliente.getTarga()?
    It seems those two lists should be the same one.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    yes, as you can see in the code they use the index, I don't know how I can solve, they are days that pass
    (cliente.getTarga().get(clienteIndex)


    When I compare in the first sheet it appears that there are 13 records and instead in the second sheet it is 16 records, when I make plaque .equals (plaque) it must return me based on the index of values.
    Last edited by glprobot; July 18th, 2019 at 10:25 AM.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    I don't know how I can solve
    Use the same reference to the list to get its size and to get an element from the list. For example:
      for (clienteIndex = 0; clienteIndex < cliente.getTarga().size(); clienteIndex++) {
    ...
         if (cliente.getTarga().get(clienteIndex).equals(veicolo.getTarga().get(veicoloIndex)))
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    as i could understand i have to use only 1 index, which makes me equality. In this way I don't want to go wrong, I have to try.

    Quite right?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    i have to use only 1 index
    One index for each list because it is possible for the lists to have different sizes.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    if I understand correctly, since they are two lists. Just 1 index is enough

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    since they are two lists. Just 1 index is enough
    I think you have misunderstood me. If there are three lists and the lists are not guaranteed to all be the same size, then there must be 3 indexes, one for each list.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    ok, but in my case since I have problems with indexes, how can I do to solve, given that they have different sizes?

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    they have different sizes?
    Use one index for each list. 2 lists requires 2 indexes.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    As I understand the error gives me when I change the license plates in the Excel file.
    When the plates have changed and they go into the else, they have to insert and here they go wrong because the indexes are not respectedv

    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 12, Size: 12
    at java.util.ArrayList.rangeCheck(ArrayList.java:657)
    at java.util.ArrayList.get(ArrayList.java:433)
    at it.cliente.Confrontare.confrontaTargheVeicolo(Conf rontare.java:97)
    at it.cliente.Test.main(Test.java:10)


    error always in the for loop of idici, I'll show you the excel file
    Last edited by glprobot; July 18th, 2019 at 01:15 PM.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 12, Size: 12
    The maximum index in a list with 12 elements is 11. Check the code to see why it is using an index past the end of the list.
    What statement gives that exception?
    What is the name of the list?
    What is the name of the index variable with the value that is past the end of the list?
    How does that index variable get a value past the end of the list?

    If it is in a loop, the loop control expression should keep the index from going past the end. For example:
    for(int theIndex = 0; theIndex < theList.size(); theIndex++)
    The expression in red keeps theIndex from going past the end of theList
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    I checked the indexes and return both 12 values. But I still don't understand why size () behaves this way.

    I removed the size () and I put 12 in this way it works. But with the size () even if it returns the value 12 it doesn't work as it should

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: cell size excel and java

    I checked the indexes and return both 12 values.
    That does not make sense to me.
    Do you mean that the code called the size() method for each list and they both returned 12?
    That is what the exception message says: the size of the list is 12.
    The problem is that the index to the list has a value of 12 which is too big. The maximum value for an index is 11 when the size is 12.

    Can you answer these 3 questions?
    1-What statement gives that exception?
    2-What is the name of the list?
    3-What is the name of the index variable with the value that is past the end of the list?
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cell size excel and java

    1-What statement gives that exception?
    System.out.println("Indice Cliente: " + cliente.getVeicoloId().size()); --> Indice Cliente: 12
    System.out.println("Indice Veicolo:" + veicolo.getVeicoloId().size()); --> Indice Veicolo: 12

    As I could understand the excitement is due to the change of indexes in excel, from 12 onwards if you add values ​​in the cells the index in size () is calculated differently
    cliente.getVeicoloId() in Error

    2-What is the name of the list?
    cliente.getVeicoloId()
    public void fillVeicoloId() {
    for (int rowIndex = 1; rowIndex < dataTypeSheet.getPhysicalNumberOfRows(); rowIndex++) {
    currentRow = dataTypeSheet.getRow(rowIndex);
    cell_id = currentRow.getCell(0); // Cella A

    if(cell_id != null)
    veicoloId.add(cell_id.getStringCellValue());
    }

    System.out.println(veicoloId);
    }

    3-Qual è il nome della variabile indice con il valore che è passato alla fine della lista?
    clienteIndex

Page 1 of 2 12 LastLast

Similar Threads

  1. Get Cell value in Excel to TextField
    By mdhs in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2014, 08:18 AM
  2. Issue while set formula for Excel cell
    By vinothparthasarathy in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 15th, 2013, 09:02 AM
  3. getting java code to cell phone
    By crtravel in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 10th, 2013, 03:43 PM
  4. Excel Text Box to string in a cell
    By ecornes in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 12th, 2012, 01:34 PM
  5. set Background Excel cell color using POI API
    By ngamal in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 26th, 2011, 11:20 AM