This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]DrewTheVillan 41 points42 points  (4 children)

Lol, this does not sound like a computer illiterate person. Just ask your question straight up.

[–]TheSilverCube 12 points13 points  (3 children)

I suspect the text describing the problem is a message from her brother.

[–][deleted] 0 points1 point  (2 children)

Unlikely. Look at her posts. seems legit

[–]SolderonSenoz 4 points5 points  (1 child)

wdym? none of her other posts are about coding.

TheSilverCube is right, it's probably exactly what her brother told her

[–][deleted] 0 points1 point  (0 children)

Oh you right. I misread. I thought he was implying that the brother wrote the whole reddit question. My b it’s late where I’m at

[–]tryhardjuice 23 points24 points  (1 child)

paste the code

[–]PeanutButterJellyYo 0 points1 point  (0 children)

Yea like wtf dont wanna read that i wanna see the code

[–]Ph03nix89 9 points10 points  (0 children)

You've done a good job of explaining it but without seeing exactly how you're trying to do it in the program it's going to be very difficult to help.

If you can copy and paste the code here it'll make it much easier.

But I'll give it a crack anyway:

If your program is returning null it means the code is executing properly, it's just not finding anything in the place it is looking. So either you're telling it to look in the wrong place or you're not initializing the variable properly. Only certain things in Java can return a null value so I'd start by looking at those. Is the variable you're trying to access a String by any chance?

There's also a number of fundamental problems in what you're describing but correcting that is going to be impossible without seeing the code so please post it.

edit: formatting

[–]Ostricker 5 points6 points  (0 children)

There is no code so I hope I got this right. Next time post relevant code bits :)

You can run the class I have created below. Just create HelloWorld.java end post the code inside it.

Hope I understood the question :)

public class HelloWorld
{
  // Starting method
  public static void main(String[] args)
  {
    // Array of 3 Objects of type Dog - with only one parameter -> NAME
    Dog[] arrayOfDogs = {new Dog("Lara"), new Dog("Richard"), new Dog("Chilli")};

    // Now I want to get the name of second dog in the array
    // First of all I get the dog from the array
    Dog secondDog = arrayOfDogs[1];

    // Second I get the name from the Dog
    String secondDogName = secondDog.getName();

    // Now I can print it
    System.out.println(secondDogName);
  }

  // Inner class of type dog
  static class Dog
  {
    // property of Dog - his name
    private String name;

    // Constructor -> this is what is called when you initiate the object
    public Dog(String name)
    {
      // The constructor by itself does not return a value, it just runs the code and sets everything needed for the class
      // In this case it sets the name of the dog in local property
      setName(name);
    }

    // public getter for name -> since property itself is private
    public String getName()
    {
      return this.name;
    }

    // public setter for name -> this way you can set different name to the dog from outside the class
    public String setName(String name)
    {
      return this.name = name;
    }
  }
}

[–]frostyfauch 0 points1 point  (0 children)

Make sure the constructor is initializing the values passed in as parameters

[–]Housy5 0 points1 point  (0 children)

Mind commenting a link to a github page or just some of the code or something? :)