It appears to me that the source of the error is the fact that you're
trying to access an object that doesn't exist.  In your Main method,
although you declare that obj1 is of type Circulo, you set its value
to null rather than creating an instance of Circulo, then later try to
access obj1 by calling one of its methods.  This is the cause of the
error.  To fix this, all you have to do is replace the line...

Circulo obj1 = null;

...with the line...

Circulo obj1 = new Circulo();

Hope that helps.

BillyRay

On Mar 30, 1:36 pm, jose luis garcia <[email protected]> wrote:
> *Hello everybody... I have a problem. I wrote a code for a program that have
> 1 superclass and 1 class extends. the code it`s follow:*
>
> //Programa que realiza algunos calculos mediante las caracteristicas de un
> cilindro
>
> package cilindro;
>
> // @author louis
>
> import java.util.Scanner;
>
> public class Cilindro {
>      double pi = Math.PI;
>
>    public Cilindro(){
>       // super();
>
>     }
>
>     public double areaCilindro(double r, double h){
>         double area = (2*pi*r*h) + (2*pi*r*r);
>
>         return area;
>     }
>
>     public double perimetroCilindro(double r, double h){
>         double perimetro = (4*pi*r)+(2*h);
>
>         return perimetro;
>
>     }
>
>     public class Circulo extends Cilindro{
>
>         Circulo(){
>             super();
>         }
>
>         public double areaCirculo(double r){
>
>             double area = pi*r*r;
>             return area;
>         }
>
>         public double perimetroCirculo(double r){
>             double perimetro = 2*pi*r;
>
>             return r;
>         }
>
>     }
>
>         public static void main(String[] args) {
>
>            // Cilindro obj = null;
>             Circulo obj1 = null;
>             double radio = 0,altura = 0;
>             Scanner input = new Scanner(System.in);
>
>             System.out.println("Ingresa Radio: ");
>             radio = input.nextFloat();
>
>            /* System.out.println("Ingresa altura: ");
>             altura = input.nextFloat();
>             */
>             String resultado = "Area del circulo: " +
> obj1.areaCirculo(radio);
>
>             System.out.println(resultado);
>
>     }
>
> }
>
> *Netbeans not generate any error. But at the moment that run the program and
> insert a float, Netbeans generate me this message:*
>
> run:
> Ingresa Radio:
> Exception in thread "main" java.lang.NullPointerException
>         at cilindro.Cilindro.main(Cilindro.java:66)
> 2.23
> Java Result: 1
> GENERACIÓN CORRECTA (tiempo total: 3 segundos)
>
> *
> I`m sure that is a logic error... help me please. Thanks!
> *

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to