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.

Results 1 to 11 of 11

Thread: help me!!

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Location
    Honduras
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Error!!

    C:\Users\Administrator\Desktop\ProyectoII>javac PaginaPrincipal.java

    C:\Users\Administrator\Desktop\ProyectoII>java PaginaPrincipal
    <<BIENVENIDOS>>
    ADMINISTRACION MI DINERO

    MENU PRINCIPAL
    1.CONFIGURACION
    2.INGRESOS
    3.GASTOS
    4.TRANSFERENCIA
    5.REPORTES
    6.SALIR
    INGRESE SU ELECCION1
    ||CONFIGURACION||
    1.CUENTAS
    2.CATEGORIA DE GASTOS
    3.CATEGORIA DE INGRESOS
    INGRESE SU ELECCION2
    **CATEGORIA DE GASTOS**
    <<BIENVENIDO>> CUANTAS CATEGORIAS INGRESAREMOS
    1
    Categoria1
    Nombre de la categoria: transporte
    Desea continuar: S/N s
    <<BIENVENIDOS>>
    ADMINISTRACION MI DINERO

    MENU PRINCIPAL
    1.CONFIGURACION
    2.INGRESOS
    3.GASTOS
    4.TRANSFERENCIA
    5.REPORTES
    6.SALIR
    INGRESE SU ELECCION3
    ||GASTOS||
    Nombre de la Categoria:
    transporte
    No existeException in thread "main" java.lang.NullPointerException
    at Administrar.buscargastos(Administrar.java:34)
    at PaginaPrincipal.main(PaginaPrincipal.java:84)


    It's my classes
    I have 3 classes 2, where have all the control procedures and where to call nesecito find the name of a category

    class Administrar{
    	MiDinero admin[] = new MiDinero[20];
    	//cuentas
    	public void administrarcuentas(int efectivo,int banco ,int pos){
    	this.admin[pos] = new MiDinero(efectivo,banco);
    	}
    	/*
    	public void administrargastos(int pos){
    	this.admin[pos] = new MiDinero();
    	}
    	*/
    	//gastos
    	public void administrargastos(int categorias, String nombrec ,int pos){
    	this.admin[pos] = new MiDinero(categorias,nombrec);
    	}
    	//ingresos
    	public void administraringresos(float categorias,String nombrec, int pos){
    	this.admin[pos] = new MiDinero(categorias,nombrec);
    	}
     
    	//Calculos
    	public String buscaringresos(String nombrebuscar){
    		for(int i=0; i<admin.length;i++){
    		if(admin[i].cingresos==nombrebuscar){
    		System.out.print("si existe");
    		}else{
    		System.out.print("No existe");
    		}
    		}
    		return nombrebuscar;
    	}
    	public String buscargastos(String nombrebuscar){
    		for(int i=0; i<admin.length;i++){
    		if(admin[i].cgastos==nombrebuscar){
    		System.out.print("si existe");
    		}else{
    		System.out.print("No existe");
    		}
    		}
    		return nombrebuscar;
    	}
    }
    Attached Images Attached Images
    Last edited by JosselynMedina; March 22nd, 2014 at 12:28 PM.

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

    Default Re: Error!!

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Location
    Honduras
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Error!!

    Sorry I'm new and did not know

  4. #4
    Junior Member
    Join Date
    Mar 2014
    Location
    Honduras
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post help me!!

    Sorry I'm new need help these are the 3 classes and I want to search the name of a category I'm doing wrong?

    class Administrar{
    	MiDinero admin[] = new MiDinero[20];
    	//cuentas
    	public void administrarcuentas(int efectivo,int banco ,int pos){
    	this.admin[pos] = new MiDinero(efectivo,banco);
    	}
    	/*
    	public void administrargastos(int pos){
    	this.admin[pos] = new MiDinero();
    	}
    	*/
    	//gastos
    	public void administrargastos(int categorias, String nombrec ,int pos){
    	this.admin[pos] = new MiDinero(categorias,nombrec);
    	}
    	//ingresos
    	public void administraringresos(float categorias,String nombrec, int pos){
    	this.admin[pos] = new MiDinero(categorias,nombrec);
    	}
     
    	//Calculos
    	public String buscaringresos(String nombrebuscar){
    		for(int i=0; i<admin.length;i++){
    		if(admin[i].cingresos==nombrebuscar){
    		System.out.print("si existe");
    		}else{
    		System.out.print("No existe");
    		}
    		}
    		return nombrebuscar;
    	}
    	public String buscargastos(String nombrebuscar){
    		for(int i=0; i<admin.length;i++){
    		if(admin[i].cgastos==nombrebuscar){
    		System.out.print("si existe");
    		}else{
    		System.out.print("No existe");
    		}
    		}
    		return nombrebuscar;
    	}
    }

    import java.util.Scanner;
    public class PaginaPrincipal{
    public static void main(String arg[]){
    	Scanner lea = new Scanner(System.in);
    	int opcion;
    	int c=1,efectivo,banco,cuentas,cuenta;
    	String bancos, busqueda;
    	char respuesta;
    	int categorias;
    	float categoria;
    	String nombrecategoria;
    	Administrar admin = new Administrar();
    	do{
    		System.out.print("           <<BIENVENIDOS>>		"+ "\n");
    		System.out.print("	ADMINISTRACION MI DINERO	" + "\n"+ "\n");
    		System.out.print("	  MENU PRINCIPAL		"+ "\n");
    		System.out.print("	1.CONFIGURACION "+ "\n");
    		System.out.print("	2.INGRESOS "+ "\n");
    		System.out.print("	3.GASTOS "+ "\n");
    		System.out.print("	4.TRANSFERENCIA "+ "\n");
    		System.out.print("	5.REPORTES "+ "\n");
    		System.out.print("	6.SALIR "+ "\n");
    		System.out.print("INGRESE SU ELECCION");
    		opcion = lea.nextInt();
    			switch(opcion){
    				case 1: System.out.print("	||CONFIGURACION||	"+ "\n");
    						System.out.print(" 1.CUENTAS"+ "\n");
    						System.out.print(" 2.CATEGORIA DE GASTOS"+ "\n");
    						System.out.print(" 3.CATEGORIA DE INGRESOS"+ "\n");
    						System.out.print("INGRESE SU ELECCION" );
    						opcion = lea.nextInt();
    							switch(opcion){
    								case 1: System.out.print("**CUENTAS**"+ "\n");
    										System.out.println("<<BIENVENIDO>>	MIS CUENTAS SERAN EFECTIVO/BANCO");
    										System.out.print("Efectivo Inicial");
    										efectivo = lea.nextInt();
    											do{
    												System.out.print("Contaremos con cuenta de bancos?? S/N? ");
    												respuesta = lea.next().charAt(0);
    												System.out.print("Cuantas cuentas tendremos?? ");
    												cuentas = lea.nextInt();
    												for(int i=0;i<cuentas;i++){
    												System.out.println("Cuenta" + c++);
    												System.out.print("Numero de Cuenta: ");
    												cuenta = lea.nextInt();
    												System.out.print("Banco :");
    												bancos = lea.next();
    												System.out.print("Dinero:");
    												banco = lea.nextInt();
    												admin.administrarcuentas(efectivo,banco,i);
    												}
    											}while(respuesta=='S' && respuesta=='s');
    										break;
    								case 2: System.out.print("**CATEGORIA DE GASTOS**"+ "\n");
    												System.out.println("<<BIENVENIDO>>	CUANTAS CATEGORIAS INGRESAREMOS");
    												categorias = lea.nextInt();
    												for(int i=0;i<categorias;i++){
    												System.out.println("Categoria" + c++);
    												System.out.print("Nombre de la categoria: ");
    												nombrecategoria = lea.next();
    												admin.administrargastos(categorias,nombrecategoria,i);
    												}	
    										break;
    								case 3: System.out.print("**CATEGORIA DE INGRESOS**"+ "\n");
    												System.out.println("<<BIENVENIDO>>	CUANTAS CATEGORIAS INGRESAREMOS");
    												categoria = lea.nextInt();
    												for(int i=0;i<categoria;i++){
    												System.out.println("Categoria" + c++);
    												System.out.print("Nombre de la categoria: ");
    												nombrecategoria = lea.next();
    												admin.administraringresos(categoria,nombrecategoria,i);
    												}
    										break;
    							}
    						break;
    				case 2:	System.out.print("	||INGRESOS||	"+ "\n");
    						System.out.print("Nombre de la Categoria: "+ "\n");
    						nombrecategoria = lea.next();
    						busqueda = admin.buscaringresos(nombrecategoria);
    						break;
    				case 3:	System.out.print("	||GASTOS||	"+ "\n");
    						System.out.print("Nombre de la Categoria: "+ "\n");
    						nombrecategoria = lea.next();
    						busqueda = admin.buscargastos(nombrecategoria);
    						break;
    				case 4:	System.out.print("	||TRANSFERENCIAS||	"+ "\n");
    						break;
    				case 5:	System.out.print("	||REPORTES||	"+ "\n");
    						System.out.print(" 1.GASTO POR CATEGORIA"+ "\n");
    						System.out.print(" 2.GASTOS TOTALES POR CATEGORIA"+ "\n");
    						System.out.print(" 3.INGRESOS POR CUENTA"+ "\n");
    						System.out.print(" 4.INGRESOS POR CATEGORIA"+ "\n");
    						System.out.print(" 5.GENERAL"+ "\n");
    						System.out.print("INGRESE SU ELECCION: ");
    						opcion = lea.nextInt();
    							switch(opcion){
    								case 1: System.out.print("**GASTOS POR CATEGORIA**"+ "\n");
    										break;
    								case 2: System.out.print("**GASTOS TOTALES POR CATEGORIA**"+ "\n");
    										break;
    								case 3: System.out.print("**INGRESOS POR CUENTA**"+ "\n");
    										break;
    								case 4: System.out.print("**INGRESOS POR CATEGORIA**"+ "\n");
    										break;
    								case 5: System.out.print("**GENERAL**"+ "\n");
    										break;
    							}
    						break;
    				case 6: break;
    			}
    	System.out.print("Desea continuar: S/N ");
    	respuesta = lea.next().charAt(0);
    	}while(respuesta =='S' || respuesta =='s');
     
     
     
    }
    }

    import java.util.Scanner;
    public class MiDinero{
    	Scanner lea = new Scanner(System.in);
    	//Atributos configuracion
    	public int Efectivo;
    	public int Banco;
    	public float Cingresos;
    	public int Cgastos;
    	String cgastos;
    	String cingresos;
    	public int Salario;
    	public int Mesada;
    	//Cuenta
    	public MiDinero(int efectivo,int banco){
    	this.Efectivo = (efectivo> 0 ? efectivo : 0);
    	this.Banco = (banco> 0 ? banco : 0);
    	}
    	/*
    	public MiDinero(){
    	this.cgastos = "";
    	this.cingresos ="";
    	}
    	*/
    	//categoria gastos
    	public MiDinero(int cantidad,String nombrec){
    	this.Cingresos = cantidad;
    	this.cgastos = nombrec;
    	}
    	public String obtenernombreingresos(String nombrec){
    	return cgastos;
    	}
     
    	//categoria ingresos
    	public MiDinero(float cant,String nombrec){
    	this.Cingresos = cant;
    	this.cingresos = "salrio";
    	}
     
    }


    He throws the following error

    C:\Users\Administrator\Desktop\ProyectoII>javac PaginaPrincipal.java

    C:\Users\Administrator\Desktop\ProyectoII>java PaginaPrincipal
    <<BIENVENIDOS>>
    ADMINISTRACION MI DINERO

    MENU PRINCIPAL
    1.CONFIGURACION
    2.INGRESOS
    3.GASTOS
    4.TRANSFERENCIA
    5.REPORTES
    6.SALIR
    INGRESE SU ELECCION2
    ||INGRESOS||
    Nombre de la Categoria:
    salario
    Exception in thread "main" java.lang.NullPointerException
    at Administrar.buscaringresos(Administrar.java:24)
    at PaginaPrincipal.main(PaginaPrincipal.java:79)

    C:\Users\Administrator\Desktop\ProyectoII>

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

    Default Re: Error!!

    Exception in thread "main" java.lang.NullPointerException
    at Administrar.buscargastos(Administrar.java:34)
    At line 34 the code uses a variable with a null value. Look at line 34, find the variable with the null value and then backtrack in the code to see why that variable does not have a valid value.

    --- Update ---

    Also the formatting of the code need work. The contents of a method should be indented so the method header lines are easier to see.
      public void aMethod() {
          // the code is indented
      } // end aMethod
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    JosselynMedina (March 22nd, 2014)

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

    Default Re: help me!!

    Exception in thread "main" java.lang.NullPointerException
    at Administrar.buscaringresos(Administrar.java:24)
    Look at line 24 for the variable with a null value, then find out why it is null.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: help me!!

    Please don't start duplicate threads.

    Threads merged.

  9. #8
    Junior Member
    Join Date
    Mar 2014
    Location
    Honduras
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: help me!!

    Thanks and I saw what my mistake, now the problem is that I do not exist to strip all but the category does not exist as if nothing would store

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

    Default Re: help me!!

    Can you say it again? I don't understand what you said in the last post.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #10
    Junior Member
    Join Date
    Mar 2014
    Location
    Honduras
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: help me!!

    My problem now is that it say that doesn't exist even if exist

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

    Default Re: help me!!

    it say that doesn't exist
    If you are getting error messages, copy the full text and paste it here.

    Otherwise please explain what "it" is that is saying "doesn't exist".
    If you don't understand my answer, don't ignore it, ask a question.

Tags for this Thread