Join 150,102 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,846 people online right now. Registration is fast and FREE... Join Now!
[code] private JTable getTable_listaPeliculas() { if (table_listaPeliculas == null) { String[] columnas= {"Titulo", "Actor Principal","Genero","Descripcion","Duracion","codigo","Disponible"}; //String[][] data= {{"pepe", "1111"}, {"juan","222"}}; String[][] dataPelis = new String[Sistema.getSistema().getPelis().size()][7]; int i=0; for (Pelicula p : Sistema.getSistema().getPelis()){ String pelis[]={s.getNombre(),s.getActorPrincipal(),s.getGenero(), s.getDescripcion(), s.getDuracion(),s.getCodigo(),s.getAv()}; dataPelis[i]= p; i++; } /[code]
I already have the Sistema class where I started It with a singleton as "s", on eclipse it says, "Pelicula cannot be resolved to a type", neither s. Setters and getters are present in Pelicula, ArrayList definitions in Sistema (System), (the main method lives elsewhere). This is supposed to represent a list of movies (Peliculas) with their Title, Main Actor, etc (as Titulo, Actor Principal, etc). Thanks in advance!!!!
private JTable getTable_listaPeliculas() { if (table_listaPeliculas == null) { String[] columnas= {"Titulo", "Actor Principal","Genero","Descripcion","Duracion","codigo","Disponible"}; //String[][] data= {{"pepe", "1111"}, {"juan","222"}}; String[][] dataPelis = new String[Sistema.getSistema().getPelis().size()][7]; int i=0; for (Pelicula p : Sistema.getSistema().getPelis()){ String pelis[]={s.getNombre(),s.getActorPrincipal(),s.getGenero(), s.getDescripcion(), s.getDuracion(),s.getCodigo(),s.getAv()}; dataPelis[i]= p; i++; }
I already have the Sistema class where I started It with a singleton as "s", on eclipse it says, "Pelicula cannot be resolved to a type", neither s. Setters and getters are present in Pelicula, ArrayList definitions in Sistema (System), (the main method lives elsewhere). This is supposed to represent a list of movies (Peliculas) with their Title, Main Actor, etc (as Titulo, Actor Principal, etc). Thanks in advance!!!!
I guess you'll have to post more code... correctly
This post has been edited by pbl: 26 Jun, 2008 - 09:11 PM
despite that Strings and arrays are treated differently from most objects, you still must still use new Object[] when you declare an array, so it should look like this:
Thans you for such a quick replay!! yes, it helped me out! Here comes more code, I can't attach the .java files, here I paste the Sistema class (System) and the Movie class (Pelicula) also with the visual class mentioned.
CODE
package domain; import java.util.*; public class Sistema{ //tenemos que tener lista de socios //lista de peliculas private static Sistema s; private ArrayList<Socio> sociosVideo; private ArrayList<Pelicula> pelis; //metodo private Sistema(){ sociosVideo=new ArrayList<Socio>(); pelis= new ArrayList<Pelicula>(); cargarPelisDePrueba(); //carg pelis de prueba cargarSociosDePrueba();//cargo los socios de prueba
} public static Sistema getSistema(){ if(s==null){ s = new Sistema(); } return s; }
private void cargarPelisDePrueba(){ Pelicula p1= new Pelicula(); p1.setTitulo("El zorro "); p1.setCodigo(0001); p1.setActorPrincipal("Arnold Schazennegger"); p1.setClasificacion("R"); p1.setDuracion(160); p1.setGenero("policial"); p1.setAv(true); //p1.setDescripcion("bla bla bla bla");
private void cargarSociosDePrueba(){ Socio s1=new Socio(); s1.setNombre("Juan"); s1.setApellidoM("Gonzales"); s1.setApellidoP("Piriz"); s1.setDireccion("18 de Julio 1234"); s1.setTelefono(12345678); s1.setCedula("1345678"); s1.setEdad(99); Socio s2=new Socio(); s2.setNombre("Juana"); s2.setApellidoM("Arco"); s2.setApellidoP("De"); s2.setDireccion("Borgoņa, Francia 1234"); s2.setTelefono(22255566); s2.setCedula("0000001"); s2.setEdad(500); sociosVideo.add(s1); sociosVideo.add(s2); } public void creaSocio(String nombre, String apellidoP, String apellidoM, String direccion, int telefono, int edad, String cedula, boolean sexo ){ Socio s = new Socio(); sociosVideo.add(s); } public void creaPelicula(String titulo, String actorPrincipal, String genero, String clasificacion, int duracion, int codigo, boolean av ){ Pelicula p = new Pelicula(); pelis.add(p); } //aca llamo el metodo busqueda de socio, busco la cedula
public ArrayList<Pelicula> getPelis() { return pelis; } public void setPelis(ArrayList<Pelicula> pelis) { this.pelis = pelis; } public ArrayList<Socio> getSociosVideo() { return sociosVideo; } public void setSociosVideo(ArrayList<Socio> sociosVideo) { this.sociosVideo = sociosVideo; }
}
QUOTE
the Pelicula clas
CODE
package domain; import java.util.ArrayList; public class Pelicula{ String nombre, actorPrincipal,titulo, genero, clasificacion; int codigo,duracion; boolean av;
//--------------------------------------getters and Setters------------------------ public String getActorPrincipal() { return actorPrincipal; } public void setActorPrincipal(String actorPrincipal) { this.actorPrincipal = actorPrincipal; } public String getClasificacion() { return clasificacion; } public void setClasificacion(String clasificacion) { this.clasificacion = clasificacion; } public int getDuracion() { return duracion; } public void setDuracion(int duracion) { this.duracion = duracion; } public String getGenero() { return genero; } public void setGenero(String genero) { this.genero = genero; } public String getNombre() { return nombre; } public void setNombre(String nombre) { this.nombre = nombre; } public String getTitulo() { return titulo; } public void setTitulo(String titulo) { this.titulo = titulo; }
public boolean isAv() { return av; } public void setAv(boolean av) { this.av = av; } public String toString(){ //el famoso toString. return titulo + codigo; } //private ArrayList clasificacion; //arraylist de clasificacion, no veo para que //private ArrayList genero; // arraylist de genero, no veo para que public int getCodigo() { return codigo; } public void setCodigo(int codigo) { this.codigo = codigo; }
/** * This method initializes table_listaPeliculas * * @return javax.swing.JTable */ private JTable getTable_listaPeliculas() { if (table_listaPeliculas == null) { String[] columnas= {"Titulo", "Actor Principal","Genero","Descripcion","Duracion","codigo","Disponible"}; //String[][] data= {{"pepe", "1111"}, {"juan","222"}}; String[][] dataPelis = new String[Sistema.getSistema().getPelis().size()][7]; int i=0; for (Pelicula p : Sistema.getSistema().getPelis()){ String pelis[]=new String[]{s.getNombre(),s.getActorPrincipal(),s.getGenero(), s.getDescripcion(), s.getDuracion(),s.getCodigo(),s.getAv()};
dataPelis[i]= p; i++; } DefaultTableModel dtm= new DefaultTableModel(dataPelis, columnas); table_listaPeliculas = new JTable(dtm); table_listaPeliculas.setBounds(new Rectangle(31, 13, 239, 127)); ; }//tendria que poner la lista de pelis aca, como un for con el indice i return table_listaPeliculas; }
Alright, that helps, here's the code with a couple changes:
CODE
private JTable getTable_listaPeliculas() { if(table_listaPeliculas == null) { String[] columnas= {"Titulo", "Actor Principal", "Genero", "Descripcion", "Duracion", "codigo", "Disponible"}; // String[][] data= {{"pepe", "1111"}, {"juan","222"}}; String[][] dataPelis= new String[Sistema.getSistema().getPelis().size()][7]; int i= 0; for(Pelicula p : Sistema.getSistema().getPelis()) { dataPelis[i]= new String[] {p.getNombre(), p.getActorPrincipal(), p.getGenero(), p.getDescripcion(), p.getDuracion(), p.getCodigo(), p.getAv()}; i++; } DefaultTableModel dtm= new DefaultTableModel(dataPelis, columnas); table_listaPeliculas= new JTable(dtm); table_listaPeliculas.setBounds(new Rectangle(31, 13, 239, 127)); ; }// tendria que poner la lista de pelis aca, como un for con el // indice i return table_listaPeliculas; }
I made just a couple changes. First: there's no need to make a temperary copy of your String array, you can just save it straight to the dataPelis[] array. Second: your for-each loop refers to each Pelicula object with the name p, but in your code you used s. I switched them all to p.
There is still a problem though, your Pelicula class doesn't have the methods getDescritpion() getDuracion() getCodigo() getAv() so this part of that line of code still doesn't work p.getDescripcion(), p.getDuracion(),p.getCodigo(), p.getAv()};
[quote] Thanks again, And sorry that I posyed the entire code. Well, actually there were most of the setters ang getters, one was missing. Also, I mistyped s (thought to be s, coming from an instance of System). With that fixed, still the following line doesn't work [\quote] [code]
for(Pelicula p : Sistema.getSistema().getPelis()) [\code] [quote] "Pelicula cannot be resolved to a type" Thanks again! [\quote]