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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: i need help with my code plz

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default i need help with my code plz

    }
    public void setStunned(boolean stun){
    stunning = stun;
    }
    public int getMaxMana() {
    return maximumMana;
    }
    public int getCurrentHealth() {
    return currentHealth1;
    }
    public int getCurrentMana() {
    return currentMana1;
    }
    public int getMagicResist() {
    return magResist;
    }
    public int
    public void setMaxHealth(int maxH) {
    maximumHealth = maxH;
    }
    public void setAttackPower(int attDamage) {
    k.put("AttackPower", attDamage);
    }
    publentHealth1 = curHealth;
    }
    public void setCurrentMana(int curMana) {
    currentMana1 = curMana;
    }
    public Skill[] getSkills() {
    return championSkills;
    }
    public boolean isStunned(){
    return stunning;
    }
    public Skill getBasicSkill() {
    for(int initial = 1; initial <= championSkills.length; initial++) { //for loop on the whole array champion skill to check if isBasic is true or not if it is not return null
    if(championSkills[initial].isBasic()== true){
    return championSkills[initial];
    }
    }
    return null;
    }
    pu

    }
    }
    public boolean isSilenced(){
    return silencing;
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    What is your question or problem?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    t
    }
    [/code]

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    i have errors
    Copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    all the errors in test class

    --- Update ---

    java.lang.NullPointerException
    at eg.edu.guc.lol.game.champions.Skill.setBasic(Skill .java:30)
    at PublicChampionTests.setup(PublicChampionTests.java :27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:27)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)

    --- Update ---

    what is wrong with method isBasic in skill class
    ?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    java.lang.NullPointerException
    at eg.edu.guc.lol.game.champions.Skill.setBasic(Skill .java:30)
    There is a variable with a null value on line 30. Look at line 30 in the your source and see what variable is null. Then backtrack in the code to see why that variable does not have a valid value.
    If you can not tell which variable it is, add a println just before line 30 and print out the values of all the variables on that line.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    There is no variable with a null value on line 30. check it plz

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    What statement is on line 30?
    If there is a NPE thrown on that line, that means there is a variable with a null value on that line. You need to find the variable and then fix the code so it does not have a null value.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    public void setBasic(boolean ba){
    		h.put("Basic", ba);
    	}
    you mean the variable basic

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    What value does the variable h have? Add a println to print its value.

    There is no variable named basic in that code.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    h is a hashmap with key(strings) and value(boolean)

    --- Update ---

    ?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    Is h null?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    i don't know

    --- Update ---

    please can you tell me what i have to do to fix it, sorry?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    Print out its value to see.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    in which class?

    --- Update ---

    ?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    Add the println just before line 30 where the NPE happens.

    Did you miss reading post#6?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    can u write it down to understand

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    Write what down?
    Do you know how to use the println() method to print out the values of variables?
    Use it to print out the value of h
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    [
    instance.setSkills(skills);
    Champion target = new Champion("Annie", attributes, 500, 400);
    instance.useSkill(target, 0, true);
    assertEquals("Target should lose health as expected", 383, target.getCurrentHealth());
    }
    }
    [/code]

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    What was the value of h when you printed it out?
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    the value null
    null
    null
    ......and so on 19 null value

    --- Update ---

    ?

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    Why is the value of h null? The code needs to assign a value to h. Where is the missing code that should be assigning a value to h? If there is code that assigns a value to h, why isn't that code being executed?
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    why?

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: i need help with my code plz

    why what? When you ask a question include enough details so it can be understood.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Mar 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i need help with my code plz

    how can i assign values to h?

Page 1 of 2 12 LastLast

Similar Threads

  1. plz give me java program for this code
    By rajesh6866 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 3rd, 2012, 12:59 PM
  2. Simple swing GUI code....Plz help
    By Arati2512 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 13th, 2012, 11:13 AM
  3. problem with my code (FOR LOOPS) neeed help plZ
    By jessy sonita in forum Loops & Control Statements
    Replies: 11
    Last Post: December 12th, 2011, 10:22 AM
  4. what is wrong with this code???plz help me :(
    By kanikapant in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 17th, 2011, 06:03 PM
  5. help me plz with my code
    By matt1405 in forum Object Oriented Programming
    Replies: 22
    Last Post: August 15th, 2011, 04:49 PM