Note that there are some explanatory texts on larger screens.

plurals
  1. PONull pointer exception when changing int in another class
    primarykey
    data
    text
    <p>Ive looked and looked and cant find the answer. But here is my issue. I am wanting to change a int in another class based on ticks in the main Game class. Here is the code:</p> <p>Trace:</p> <pre><code> 02-16 02:10:58.605: W/dalvikvm(1578): threadid=13: thread exiting with uncaught exception (group=0x40c5ca68) 02-16 02:10:58.615: E/AndroidRuntime(1578): FATAL EXCEPTION: Thread-16720 02-16 02:10:58.615: E/AndroidRuntime(1578): java.lang.NullPointerException 02-16 02:10:58.615: E/AndroidRuntime(1578): at com.mojang.ld22.Game.tick(Game.java:374) 02-16 02:10:58.615: E/AndroidRuntime(1578): at com.mojang.ld22.Game.iterate(Game.java:300) 02-16 02:10:58.615: E/AndroidRuntime(1578): at com.mojang.ld22.GameActivity$4.run(GameActivity.java:136) 02-16 02:10:58.615: E/AndroidRuntime(1578): at java.lang.Thread.run(Thread.java:856) </code></pre> <p>Game.java Snippet</p> <pre><code> public void tick() { tickCount++; ... ... ... if (tickCount % 1000 == 0) { if (rising) { lightlvl++; Would error here too clock.time++; &lt;----------- if (lightlvl &gt;= 8) { rising = false; } } else { lightlvl--; LINE 374 ----------&gt; clock.time--; &lt;------------ if (lightlvl &lt;= -2) rising = true; } } } } </code></pre> <p>And Clock.java</p> <pre><code> package com.mojang.ld22.entity; import com.mojang.ld22.crafting.Crafting; import com.mojang.ld22.entity.particle.TextParticle; import com.mojang.ld22.entity.particle.TimeClock; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Screen; import com.mojang.ld22.screen.CraftingMenu; import com.mojang.ld22.item.FurnitureItem; public class Clock extends Furniture { /** * */ private static final long serialVersionUID = 3146189783597003582L; Player player; public int time = 0; public int clock = 1; public boolean rising = false; public Clock() { super("Clock"); col = Color.get(-1, 100, 321, 431); sprite = 10; xr = 3; yr = 2; } @Override public void tick(){ if (time &lt;= 0) clock = 1; if (time == 1) clock = 1; if (time == 2) clock = 2; if (time == 3) clock = 3; if (time == 4) clock = 4; if (time == 5) clock = 5; if (time == 6) clock = 6; if (time == 7) clock = 7; if (time == 8); clock = 8; } @Override public void render(Screen screen){ int col = Color.get(-1, 531, 000, 534); //incorrect times TODO if (clock == 8) screen.render(x - 8, y - 8, 7 + 11 * 32, col, 0); if (clock == 6) screen.render(x - 8, y - 8, 8 + 11 * 32, col, 0); //noon midnight if (clock == 5) screen.render(x - 8, y - 8, 9 + 11 * 32, col, 0); if (clock == 4) screen.render(x - 8, y - 8, 10 + 11 * 32, col, 0); //Before noon after noon if (clock == 3) screen.render(x - 8, y - 8, 11 + 11 * 32, col, 0); if (clock == 2) screen.render(x - 8, y - 8, 12 + 11 * 32, col, 0); //730pm 530pm if (clock == 1) screen.render(x - 8, y - 8, 13 + 11 * 32, col, 0); if (clock == -1) screen.render(x - 8, y - 8, 14 + 11 * 32, col, 0); } } </code></pre> <p>And yes this isn't pretty. This is basically what I tried when I couldn't pull any int from game.java to clock.java So this was to test sending it. I cant use separate ticks because clock.java isn't created until the player pulls it from his/her inventory.</p> <p>I hope this makes since. I can supply more code if you need it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload