Ich lese aus einer Datenbank meine Zitate und möchte diese in ein Array der Form
schreiben. Leider bekomme ich das überhaupt nicht auf die Reihe...hier erstmal die Klasse, wie sie bisher ist (schreibt nur index und zitat):
das programm schmiert aufgrund einer NullPointerException aber ab, doch leider sagt mir das nichts,wenn nicht sogar weniger... kann mir jemand verraten wie man einfach etwas in ein Array schreibt?!?!
vielen Dank / viele Grüße
Sebastian
Code:
quotes[0]["id"]=1
quotes[0]["quote"]="I have come here to chew bubblegum and kick arse. And I'm all out of bubblegum."
quotes[1]["id"]=2
quotes[1]["quote"]="..."
schreiben. Leider bekomme ich das überhaupt nicht auf die Reihe...hier erstmal die Klasse, wie sie bisher ist (schreibt nur index und zitat):
Code:
package quoteindex;
import java.sql.*;
import java.util.*;
public class RandomQuote {
String Quote;
ArrayList Quotes;
DbConnection DBC;
Statement st;
int QuoteId;
RandomQuote(){
DBC = new DbConnection();
st=DBC.makeSt();
int i=0;
try{
String stmt = "SELECT * FROM quotes";
ResultSet result = st.executeQuery(stmt);
while (result.next()){
Quotes.add(i,result.getString("quote"));
i++;
}
}
catch(SQLException e){
System.out.println(
"SQL Query erroneous.\n" +
"Error: " + e.getMessage());
}
}
public String recite(){
return Quote;
}
}
vielen Dank / viele Grüße
Sebastian