ArrayList e iText - erro ao escrever parágrafo

2 respostas
A

Olá pessoal, estou com um problema aqui na hora de escrever um parágrafo em um PDF com o iText.
O código é esse:

ArrayList ListaDeQuestoes = new ArrayList(); String pronto = "olá"; ListaDeQuestoes.add(pronto); String cder = (String) ListaDeQuestoes.get(0); // TEM PROBLEMA documento.add(new Paragraph(cder));

Fiz alguns testes e concluí que na linha onde diz // TEM PROBLEMA da o erro:

Gostaria de saber qual é o problema que está acontecendo, alguém me ajuda?

Obrigado comunidade

2 Respostas

Fox_McCloud

Aqui isso não deu erro...

E realmente não poderia dar erro, você adicionou a variável do tipo String à lista, portanto ela está lá!
ArrayList ListaDeQuestoes = new ArrayList();     
String pronto = "olá";   
ListaDeQuestoes.add(pronto);   
System.out.println((String) ListaDeQuestoes.get(0));
Vai depender do contexto onde isso se encontra, veja um trecho do JavaDoc do ArrayList...
/**
 * <p><strong>Note that this implementation is not synchronized.</strong>
 * If multiple threads access an <tt>ArrayList</tt> instance concurrently,
 * and at least one of the threads modifies the list structurally, it
 * <i>must</i> be synchronized externally.  (A structural modification is
 * any operation that adds or deletes one or more elements, or explicitly
 * resizes the backing array; merely setting the value of an element is not
 * a structural modification.)  This is typically accomplished by
 * synchronizing on some object that naturally encapsulates the list.*/
alexcostars:
Olá pessoal, estou com um problema aqui na hora de escrever um parágrafo em um PDF com o iText. O código é esse:
ArrayList ListaDeQuestoes = new ArrayList();  
String pronto = "olá";
ListaDeQuestoes.add(pronto);
String cder = (String) ListaDeQuestoes.get(0);          // TEM PROBLEMA
documento.add(new Paragraph(cder));

Fiz alguns testes e concluí que na linha onde diz // TEM PROBLEMA da o erro:

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

Gostaria de saber qual é o problema que está acontecendo, alguém me ajuda?

Obrigado comunidade

A

vlw pela ajuda, vou tentar mudar a lógica, quem sabe é isso.

Criado 19 de julho de 2009
Ultima resposta 19 de jul. de 2009
Respostas 2
Participantes 2