Sign in to follow this  

Help with java NullPointerException Needed!

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm having trouble with the java.lang.NullPointerException runtime error. I'm new to java programming and hope someone may be able to help. I get the error when i attempt to delete a element from a list. Here are two portions of the code that i believe are contributing to the error:
// Here i delete element 0 off the list if conditions are met.

if (command == word1Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord1.getLayout() ==(Item.LAYOUT_CENTER))
{
stringWord1.setLayout(Item.LAYOUT_LEFT);
wordList.delete(0); // <---- This is when i get the error
tPlayer1++;
oPlayer1++;
}
}

// Here's the code for the list which comes after the previous code segment


public List getWordList() {
if (wordList == null) {
// write pre-init user code here
wordList = new List("Ataddin", Choice.IMPLICIT);
wordList.append(Word1, null);
wordList.append(Word2, null);
wordList.append(Word3, null);
wordList.append(Word4, null);
wordList.append(Word5, null);
wordList.append(Word6, null);
wordList.append(Word7, null);
wordList.append(Word8, null);
wordList.append(Word9, null);
wordList.append(Word10, null);
wordList.setCommandListener(this);
wordList.setSelectedFlags(new boolean[] { false, false, false, false, false, false, false, false, false, false });
// write post-init user code here
}
return wordList;
}

Thanks in advance and any questions just ask as i'm getting so frustrated at the mo. I'm using Netbeans IDE 6 and J2ME. Thank you.

Share this post


Link to post
Share on other sites
So, what does netbeans tell you is null? If you debug it, setting a breakpoint at the exception you should be able to highlight bits of code or look at the locals to see if wordList is null or wordList is empty, which is the cause of your problems. If you need to, you can set the breakpoint earlier and step through the code to see where things aren't going according to plan.

Or, if that makes no sense how far do you get before you're confused about debugging?

Share this post


Link to post
Share on other sites
Well sort of. It means your initial diagnosis about what line it is on is correct; otherwise I'd just have to take your word for it. It doesn't let me/us know how far you got into using the debugger so we can help you learn that valuable skill.

Share this post


Link to post
Share on other sites
I have just set a breakpoint at the point in the code where it throws the error (wordList.delete(0);).

I then hovered over wordList and it says it equals null.

I presume this is the problem, how would i go about fixing this.

Again thanks for your help, i appreciate it.

Share this post


Link to post
Share on other sites
Make it not delete while null. How to do that is largely dependent on the circumstances of your code at that point. In some cases, you should just not delete; in some cases it's a bug elsewhere (since it should never be null there by design, you just made a mistake somewhere) and needs to be fixed; in some cases it's a runtime error and the exception should be thrown (and perhaps a handler added to deal with it gracefully).

I don't know without more info about the context. And you're welcome :]

Share this post


Link to post
Share on other sites
i will try to put it into context for you as i'm struggling to understand the error.

On screen i have 10 words these are stringItems, i then have a command for each of these being:


if (command == word1Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord1.getLayout() ==(Item.LAYOUT_CENTER))
{
stringWord1.setLayout(Item.LAYOUT_LEFT);
wordList.delete(0);
tPlayer1++;
oPlayer1++;
}
}



I have one of these commands for each stringItem. I also have a list which is on a screen the the user cannot access, it is not lined to anything. This list contains the 10 words. So when the user selects the word (stringItem) the command should delete the word from the of screen list as well as do other irrelevant things.

Does this help in any way and can you see a possible reason for the error?

I hope i haven't overcomplicated things, if so please say as i would love to sort this out.

Thank You.

Share this post


Link to post
Share on other sites
You haven't overcomplicated things, but the snippet you're supplying is incomplete, and thus leaves much of the context out such as how wordList is being (and supposed to be) populated. I suspect that it is a problem populating the list, but the snippet you provided in the original post that should be creating it looks kosher at first glance, guessing on a lot of the stuff. So how's it being populated/created?

Share this post


Link to post
Share on other sites
Due to the fact i have been using J2ME and the pallette to drag items onto the screen for design alot of the code is generated in this way. i think this is where the list is created and poputlated:


public List getWordList() {
if (wordList == null) {
// write pre-init user code here
wordList = new List("Ataddin", Choice.IMPLICIT);
wordList.append(Word1, null);
wordList.append(Word2, null);
wordList.append(Word3, null);
wordList.append(Word4, null);
wordList.append(Word5, null);
wordList.append(Word6, null);
wordList.append(Word7, null);
wordList.append(Word8, null);
wordList.append(Word9, null);
wordList.append(Word10, null);
wordList.setCommandListener(this);
wordList.setSelectedFlags(new boolean[] { false, false, false, false, false, false, false, false, false, false });
// write post-init user code here
}
return wordList;
}



Word1, Word2 .....etc being variable declared at the top of my program like so:


String Word1 = "to";
String Word2 = "tip";
String Word3 = "pods";
String Word4 = "on";
String Word5 = "pan";
String Word6 = "is";
String Word7 = "as";
String Word8 = "a";
String Word9 = "tad";
String Word10 = "din";



I would upload the entire code for the program but it i quite large, but if that would help i'm more than happy to do so.

Thanks again.

Share this post


Link to post
Share on other sites
And wordList is a member of the class containing getWordList or is wordList being assigned the result of getWordList? I imagine the former? And where is that getWordList called in relation to your exception throwing delete?

Share this post


Link to post
Share on other sites
First off, we need to see more.

[nerdzombie]More code![/nerdzombie]

:D

Secondly, I looked through the Java Documentation for the List class and it doesn't list a delete method. So even if we do fix your problem there is a chance you're trying to call a method that does not exist. Unless you've written your own List class, then we're going to need to see that too.

Share this post


Link to post
Share on other sites
I'm getting quite confused at the minute i think i've only imported 4 classes?

I also don't think that i have coded anywhere for wordList to be the result of getwordList();

I don't fully understand your last question either not because of the why it is written but because i am not used to some of the terminology.

Because alot of the code is generated through me dragging and dropping buttons etc i can sometimes get confused as to what has gone were.

Below is the entire code ( sorry for dumping it on you ), i know there is alot of unused stuff in there and i plan to tidy it all up. i hope this can help you understand a bit better as my explanations arn't great due to my lack of knowledge.


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


package ataddin;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.netbeans.microedition.lcdui.SplashScreen;
import java.util.Random;

/**
* @author Paul Jarratt
*/

public class VisualMIDlet extends MIDlet implements CommandListener, ItemCommandListener {

private boolean midletPaused = false;
Random randomNumGen = new Random();
protected int randomNum;

String player2Choice;
String Word1 = "to";
String Word2 = "tip";
String Word3 = "pods";
String Word4 = "on";
String Word5 = "pan";
String Word6 = "is";
String Word7 = "as";
String Word8 = "a";
String Word9 = "tad";
String Word10 = "din";

int tPlayer1 = 0;
int oPlayer1 = 0;
int iPlayer1 = 0;
int pPlayer1 = 0;
int dPlayer1 = 0;
int sPlayer1 = 0;
int nPlayer1 = 0;
int aPlayer1 = 0;

int tPlayer2 = 0;
int oPlayer2 = 0;
int iPlayer2 = 0;
int pPlayer2 = 0;
int dPlayer2 = 0;
int sPlayer2 = 0;
int nPlayer2 = 0;
int aPlayer2 = 0;

String wordArray[] = new String[10];


//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">
private SplashScreen splashScreen;
private Form gameScreen;
private StringItem stringDivider1;
private StringItem stringDivider2;
private StringItem stringEndTurn;
private StringItem stringWord3;
private StringItem stringWord2;
private StringItem stringWord1;
private StringItem stringWord8;
private StringItem stringWord9;
private StringItem stringWord10;
private StringItem stringWord4;
private StringItem stringWord5;
private StringItem stringWord6;
private StringItem stringWord7;
private StringItem stringItem;
private Form menuScreen;
private StringItem stringStartGame;
private StringItem stringQuitGame;
private List wordList;
private Command endTurnCommand;
private Command returnMenuCommand;
private Command exitGameCommand;
private Command quitGameCommand;
private Command startGameCommand;
private Command word6Command;
private Command word7Command;
private Command word4Command;
private Command word5Command;
private Command word10Command;
private Command word8Command;
private Command word9Command;
private Command word1Command;
private Command word2Command;
private Command word3Command;
private Image image1;
//</editor-fold>

/**
* The VisualMIDlet constructor.
*/

public VisualMIDlet() {
}

//<editor-fold defaultstate="collapsed" desc=" Generated Methods ">
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">
/**
* Initilizes the application.
* It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
*/

private void initialize() {
// write pre-initialize user code here

// write post-initialize user code here
wordArray[0] = Word1;
wordArray[1] = Word2;
wordArray[2] = Word3;
wordArray[3] = Word4;
wordArray[4] = Word5;
wordArray[5] = Word6;
wordArray[6] = Word7;
wordArray[7] = Word8;
wordArray[8] = Word9;
wordArray[9] = Word10;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">
/**
* Performs an action assigned to the Mobile Device - MIDlet Started point.
*/

public void startMIDlet() {
// write pre-action user code here
switchDisplayable(null, getSplashScreen());
// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">
/**
* Performs an action assigned to the Mobile Device - MIDlet Resumed point.
*/

public void resumeMIDlet() {
// write pre-action user code here

// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">
/**
* Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
* @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
* @param nextDisplayable the Displayable to be set
*/

public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
// write pre-switch user code here
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
// write post-switch user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">
/**
* Called by a system to indicated that a command has been invoked on a particular displayable.
* @param command the Command that was invoked
* @param displayable the Displayable where the command was invoked
*/

public void commandAction(Command command, Displayable displayable) {
// write pre-action user code here
if (displayable == gameScreen) {
if (command == returnMenuCommand) {
// write pre-action user code here
switchDisplayable(null, getMenuScreen());
// write post-action user code here
stringWord1.setLayout(Item.LAYOUT_CENTER);
stringWord2.setLayout(Item.LAYOUT_CENTER);
stringWord3.setLayout(Item.LAYOUT_CENTER);
stringWord4.setLayout(Item.LAYOUT_CENTER);
stringWord5.setLayout(Item.LAYOUT_CENTER);
stringWord6.setLayout(Item.LAYOUT_CENTER);
stringWord7.setLayout(Item.LAYOUT_CENTER);
stringWord8.setLayout(Item.LAYOUT_CENTER);
stringWord9.setLayout(Item.LAYOUT_CENTER);
stringWord10.setLayout(Item.LAYOUT_CENTER);
}
} else if (displayable == menuScreen) {
if (command == exitGameCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
}
} else if (displayable == splashScreen) {
if (command == SplashScreen.DISMISS_COMMAND) {
// write pre-action user code here
switchDisplayable(null, getMenuScreen());
// write post-action user code here
}
} else if (displayable == wordList) {
if (command == List.SELECT_COMMAND) {
// write pre-action user code here
wordListAction();
// write post-action user code here
}
}
// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: splashScreen ">
/**
* Returns an initiliazed instance of splashScreen component.
* @return the initialized component instance
*/

public SplashScreen getSplashScreen() {
if (splashScreen == null) {
// write pre-init user code here
splashScreen = new SplashScreen(getDisplay());
splashScreen.setCommandListener(this);
splashScreen.setImage(getImage1());
// write post-init user code here
}
return splashScreen;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: image1 ">
/**
* Returns an initiliazed instance of image1 component.
* @return the initialized component instance
*/

public Image getImage1() {
if (image1 == null) {
// write pre-init user code here
try {
image1 = Image.createImage("/AtaddinMELogo.png");
} catch (java.io.IOException e) {
e.printStackTrace();
}
// write post-init user code here
}
return image1;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Items ">
/**
* Called by a system to indicated that a command has been invoked on a particular item.
* @param command the Command that was invoked
* @param displayable the Item where the command was invoked
*/

public void commandAction(Command command, Item item) {
// write pre-action user code here
if (item == stringEndTurn) {
if (command == endTurnCommand) {
// write pre-action user code here

// write post-action user code here
randomNum = randomNumGen.nextInt(wordList.size());
player2Choice = wordList.getString(randomNum);
if (player2Choice == Word1)
{
stringWord1.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word2)
{
stringWord2.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord3.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord4.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord5.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord6.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord7.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord8.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord9.setLayout(Item.LAYOUT_RIGHT);
}
if (player2Choice == Word1)
{
stringWord10.setLayout(Item.LAYOUT_RIGHT);
}
wordList.delete(randomNum);
}
} else if (item == stringQuitGame) {
if (command == quitGameCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
}
} else if (item == stringStartGame) {
if (command == startGameCommand) {
// write pre-action user code here
switchDisplayable(null, getGameScreen());
// write post-action user code here
}
} else if (item == stringWord1) {
if (command == word1Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord1.getLayout() ==(Item.LAYOUT_CENTER))
{
stringWord1.setLayout(Item.LAYOUT_LEFT);
wordList.delete(0);
tPlayer1++;
oPlayer1++;
}
}
} else if (item == stringWord10) {
if (command == word10Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord10.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord10.setLayout(Item.LAYOUT_LEFT);
wordList.delete(9);
dPlayer1++;
iPlayer1++;
nPlayer1++;
}
}
} else if (item == stringWord2) {
if (command == word2Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord2.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord2.setLayout(Item.LAYOUT_LEFT);
wordList.delete(1);
tPlayer1++;
iPlayer1++;
pPlayer1++;
}
}
} else if (item == stringWord3) {
if (command == word3Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord3.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord3.setLayout(Item.LAYOUT_LEFT);
wordList.delete(2);
pPlayer1++;
oPlayer1++;
dPlayer1++;
sPlayer1++;
}
}
} else if (item == stringWord4) {
if (command == word4Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord4.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord4.setLayout(Item.LAYOUT_LEFT);
wordList.delete(3);
oPlayer1++;
nPlayer1++;
}
}
} else if (item == stringWord5) {
if (command == word5Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord5.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord5.setLayout(Item.LAYOUT_LEFT);
wordList.delete(4);
pPlayer1++;
aPlayer1++;
nPlayer1++;
}
}
} else if (item == stringWord6) {
if (command == word6Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord6.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord6.setLayout(Item.LAYOUT_LEFT);
wordList.delete(5);
iPlayer1++;
sPlayer1++;
}
}
} else if (item == stringWord7) {
if (command == word7Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord7.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord7.setLayout(Item.LAYOUT_LEFT);
wordList.delete(6);
aPlayer1++;
sPlayer1++;
}
}
} else if (item == stringWord8) {
if (command == word8Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord8.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord8.setLayout(Item.LAYOUT_LEFT);
wordList.delete(7);
aPlayer1++;
}
}
} else if (item == stringWord9) {
if (command == word9Command) {
// write pre-action user code here

// write post-action user code here
if (stringWord9.getLayout() == (Item.LAYOUT_CENTER))
{
stringWord9.setLayout(Item.LAYOUT_LEFT);
wordList.delete(8);
tPlayer1++;
aPlayer1++;
dPlayer1++;
}
}
}
// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: menuScreen ">
/**
* Returns an initiliazed instance of menuScreen component.
* @return the initialized component instance
*/

public Form getMenuScreen() {
if (menuScreen == null) {
// write pre-init user code here
menuScreen = new Form("Ataddin", new Item[] { getStringStartGame(), getStringQuitGame() });
menuScreen.addCommand(getExitGameCommand());
menuScreen.setCommandListener(this);
// write post-init user code here
}
return menuScreen;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringStartGame ">
/**
* Returns an initiliazed instance of stringStartGame component.
* @return the initialized component instance
*/

public StringItem getStringStartGame() {
if (stringStartGame == null) {
// write pre-init user code here
stringStartGame = new StringItem("Start Game", "");
stringStartGame.addCommand(getStartGameCommand());
stringStartGame.setItemCommandListener(this);
stringStartGame.setLayout(ImageItem.LAYOUT_DEFAULT | Item.LAYOUT_EXPAND);
// write post-init user code here
}
return stringStartGame;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringQuitGame ">
/**
* Returns an initiliazed instance of stringQuitGame component.
* @return the initialized component instance
*/

public StringItem getStringQuitGame() {
if (stringQuitGame == null) {
// write pre-init user code here
stringQuitGame = new StringItem("Quit Game", "");
stringQuitGame.addCommand(getQuitGameCommand());
stringQuitGame.setItemCommandListener(this);
stringQuitGame.setLayout(ImageItem.LAYOUT_DEFAULT | Item.LAYOUT_EXPAND);
// write post-init user code here
}
return stringQuitGame;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: startGameCommand ">
/**
* Returns an initiliazed instance of startGameCommand component.
* @return the initialized component instance
*/

public Command getStartGameCommand() {
if (startGameCommand == null) {
// write pre-init user code here
startGameCommand = new Command("Ok", Command.ITEM, 0);
// write post-init user code here
}
return startGameCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: quitGameCommand ">
/**
* Returns an initiliazed instance of quitGameCommand component.
* @return the initialized component instance
*/

public Command getQuitGameCommand() {
if (quitGameCommand == null) {
// write pre-init user code here
quitGameCommand = new Command("Ok", Command.ITEM, 0);
// write post-init user code here
}
return quitGameCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitGameCommand ">
/**
* Returns an initiliazed instance of exitGameCommand component.
* @return the initialized component instance
*/

public Command getExitGameCommand() {
if (exitGameCommand == null) {
// write pre-init user code here
exitGameCommand = new Command("Exit", Command.EXIT, 0);
// write post-init user code here
}
return exitGameCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: gameScreen ">
/**
* Returns an initiliazed instance of gameScreen component.
* @return the initialized component instance
*/

public Form getGameScreen() {
if (gameScreen == null) {
// write pre-init user code here
gameScreen = new Form("Ataddin", new Item[] { getStringItem(), getStringDivider1(), getStringWord1(), getStringWord2(), getStringWord3(), getStringWord4(), getStringWord5(), getStringWord6(), getStringWord7(), getStringWord8(), getStringWord9(), getStringWord10(), getStringDivider2(), getStringEndTurn() });
gameScreen.addCommand(getReturnMenuCommand());
gameScreen.setCommandListener(this);
// write post-init user code here
}
return gameScreen;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord1 ">
/**
* Returns an initiliazed instance of stringWord1 component.
* @return the initialized component instance
*/

public StringItem getStringWord1() {
if (stringWord1 == null) {
// write pre-init user code here
stringWord1 = new StringItem(Word1, "");
stringWord1.addCommand(getWord1Command());
stringWord1.setItemCommandListener(this);
stringWord1.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord1;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord2 ">
/**
* Returns an initiliazed instance of stringWord2 component.
* @return the initialized component instance
*/

public StringItem getStringWord2() {
if (stringWord2 == null) {
// write pre-init user code here
stringWord2 = new StringItem(Word2, "");
stringWord2.addCommand(getWord2Command());
stringWord2.setItemCommandListener(this);
stringWord2.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord2;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord3 ">
/**
* Returns an initiliazed instance of stringWord3 component.
* @return the initialized component instance
*/

public StringItem getStringWord3() {
if (stringWord3 == null) {
// write pre-init user code here
stringWord3 = new StringItem(Word3, "");
stringWord3.addCommand(getWord3Command());
stringWord3.setItemCommandListener(this);
stringWord3.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord3;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord4 ">
/**
* Returns an initiliazed instance of stringWord4 component.
* @return the initialized component instance
*/

public StringItem getStringWord4() {
if (stringWord4 == null) {
// write pre-init user code here
stringWord4 = new StringItem(Word4, "");
stringWord4.addCommand(getWord4Command());
stringWord4.setItemCommandListener(this);
stringWord4.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord4;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord5 ">
/**
* Returns an initiliazed instance of stringWord5 component.
* @return the initialized component instance
*/

public StringItem getStringWord5() {
if (stringWord5 == null) {
// write pre-init user code here
stringWord5 = new StringItem(Word5, "");
stringWord5.addCommand(getWord5Command());
stringWord5.setItemCommandListener(this);
stringWord5.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord5;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord6 ">
/**
* Returns an initiliazed instance of stringWord6 component.
* @return the initialized component instance
*/

public StringItem getStringWord6() {
if (stringWord6 == null) {
// write pre-init user code here
stringWord6 = new StringItem(Word6, "");
stringWord6.addCommand(getWord6Command());
stringWord6.setItemCommandListener(this);
stringWord6.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord6;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord7 ">
/**
* Returns an initiliazed instance of stringWord7 component.
* @return the initialized component instance
*/

public StringItem getStringWord7() {
if (stringWord7 == null) {
// write pre-init user code here
stringWord7 = new StringItem(Word7, "");
stringWord7.addCommand(getWord7Command());
stringWord7.setItemCommandListener(this);
stringWord7.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord7;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord8 ">
/**
* Returns an initiliazed instance of stringWord8 component.
* @return the initialized component instance
*/

public StringItem getStringWord8() {
if (stringWord8 == null) {
// write pre-init user code here
stringWord8 = new StringItem(Word8, "");
stringWord8.addCommand(getWord8Command());
stringWord8.setItemCommandListener(this);
stringWord8.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord8;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord9 ">
/**
* Returns an initiliazed instance of stringWord9 component.
* @return the initialized component instance
*/

public StringItem getStringWord9() {
if (stringWord9 == null) {
// write pre-init user code here
stringWord9 = new StringItem(Word9, "");
stringWord9.addCommand(getWord9Command());
stringWord9.setItemCommandListener(this);
stringWord9.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord9;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringWord10 ">
/**
* Returns an initiliazed instance of stringWord10 component.
* @return the initialized component instance
*/

public StringItem getStringWord10() {
if (stringWord10 == null) {
// write pre-init user code here
stringWord10 = new StringItem(Word10, "");
stringWord10.addCommand(getWord10Command());
stringWord10.setItemCommandListener(this);
stringWord10.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringWord10;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word1Command ">
/**
* Returns an initiliazed instance of word1Command component.
* @return the initialized component instance
*/

public Command getWord1Command() {
if (word1Command == null) {
// write pre-init user code here
word1Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word1Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">
/**
* Returns an initiliazed instance of stringItem component.
* @return the initialized component instance
*/

public StringItem getStringItem() {
if (stringItem == null) {
// write pre-init user code here
stringItem = new StringItem("Player 1 Words Player 2", "");
stringItem.setLayout(ImageItem.LAYOUT_DEFAULT);
// write post-init user code here
}
return stringItem;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word2Command ">
/**
* Returns an initiliazed instance of word2Command component.
* @return the initialized component instance
*/

public Command getWord2Command() {
if (word2Command == null) {
// write pre-init user code here
word2Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word2Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word3Command ">
/**
* Returns an initiliazed instance of word3Command component.
* @return the initialized component instance
*/

public Command getWord3Command() {
if (word3Command == null) {
// write pre-init user code here
word3Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word3Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word4Command ">
/**
* Returns an initiliazed instance of word4Command component.
* @return the initialized component instance
*/

public Command getWord4Command() {
if (word4Command == null) {
// write pre-init user code here
word4Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word4Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word5Command ">
/**
* Returns an initiliazed instance of word5Command component.
* @return the initialized component instance
*/

public Command getWord5Command() {
if (word5Command == null) {
// write pre-init user code here
word5Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word5Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word6Command ">
/**
* Returns an initiliazed instance of word6Command component.
* @return the initialized component instance
*/

public Command getWord6Command() {
if (word6Command == null) {
// write pre-init user code here
word6Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word6Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word7Command ">
/**
* Returns an initiliazed instance of word7Command component.
* @return the initialized component instance
*/

public Command getWord7Command() {
if (word7Command == null) {
// write pre-init user code here
word7Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word7Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word8Command ">
/**
* Returns an initiliazed instance of word8Command component.
* @return the initialized component instance
*/

public Command getWord8Command() {
if (word8Command == null) {
// write pre-init user code here
word8Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word8Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word9Command ">
/**
* Returns an initiliazed instance of word9Command component.
* @return the initialized component instance
*/

public Command getWord9Command() {
if (word9Command == null) {
// write pre-init user code here
word9Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word9Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: word10Command ">
/**
* Returns an initiliazed instance of word10Command component.
* @return the initialized component instance
*/

public Command getWord10Command() {
if (word10Command == null) {
// write pre-init user code here
word10Command = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return word10Command;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: returnMenuCommand ">
/**
* Returns an initiliazed instance of returnMenuCommand component.
* @return the initialized component instance
*/

public Command getReturnMenuCommand() {
if (returnMenuCommand == null) {
// write pre-init user code here
returnMenuCommand = new Command("Exit", Command.EXIT, 0);
// write post-init user code here
}
return returnMenuCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringEndTurn ">
/**
* Returns an initiliazed instance of stringEndTurn component.
* @return the initialized component instance
*/

public StringItem getStringEndTurn() {
if (stringEndTurn == null) {
// write pre-init user code here
stringEndTurn = new StringItem("End Turn", "");
stringEndTurn.addCommand(getEndTurnCommand());
stringEndTurn.setItemCommandListener(this);
stringEndTurn.setLayout(ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_BEFORE);
// write post-init user code here
}
return stringEndTurn;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringDivider2 ">
/**
* Returns an initiliazed instance of stringDivider2 component.
* @return the initialized component instance
*/

public StringItem getStringDivider2() {
if (stringDivider2 == null) {
// write pre-init user code here
stringDivider2 = new StringItem("__________________________________", "");
// write post-init user code here
}
return stringDivider2;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringDivider1 ">
/**
* Returns an initiliazed instance of stringDivider1 component.
* @return the initialized component instance
*/

public StringItem getStringDivider1() {
if (stringDivider1 == null) {
// write pre-init user code here
stringDivider1 = new StringItem("__________________________________", "");
stringDivider1.setLayout(ImageItem.LAYOUT_CENTER);
// write post-init user code here
}
return stringDivider1;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: endTurnCommand ">
/**
* Returns an initiliazed instance of endTurnCommand component.
* @return the initialized component instance
*/

public Command getEndTurnCommand() {
if (endTurnCommand == null) {
// write pre-init user code here
endTurnCommand = new Command("Select", Command.ITEM, 0);
// write post-init user code here
}
return endTurnCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: wordList ">
/**
* Returns an initiliazed instance of wordList component.
* @return the initialized component instance
*/

public List getWordList() {
if (wordList == null) {
// write pre-init user code here
wordList = new List("Ataddin", Choice.IMPLICIT);
wordList.append(Word1, null);
wordList.append(Word2, null);
wordList.append(Word3, null);
wordList.append(Word4, null);
wordList.append(Word5, null);
wordList.append(Word6, null);
wordList.append(Word7, null);
wordList.append(Word8, null);
wordList.append(Word9, null);
wordList.append(Word10, null);
wordList.setCommandListener(this);
wordList.setSelectedFlags(new boolean[] { false, false, false, false, false, false, false, false, false, false });
// write post-init user code here
}
return wordList;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: wordListAction ">
/**
* Performs an action assigned to the selected list element in the wordList component.
*/

public void wordListAction() {
// enter pre-action user code here
String __selectedString = getWordList().getString(getWordList().getSelectedIndex());
if (__selectedString != null) {
if (__selectedString.equals(Word1)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word2)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word3)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word4)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word5)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word6)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word7)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word8)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word9)) {
// write pre-action user code here

// write post-action user code here
} else if (__selectedString.equals(Word10)) {
// write pre-action user code here

// write post-action user code here
}
}
// enter post-action user code here
}
//</editor-fold>



/**
* Returns a display instance.
* @return the display instance.
*/

public Display getDisplay () {
return Display.getDisplay(this);
}

/**
* Exits MIDlet.
*/

public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}

/**
* Called when MIDlet is started.
* Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
*/

public void startApp() {
if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();
}
midletPaused = false;
}

/**
* Called when MIDlet is paused.
*/

public void pauseApp() {
midletPaused = true;
}

/**
* Called to signal the MIDlet to terminate.
* @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
*/

public void destroyApp(boolean unconditional) {
}

}



I very much appreciate your time.

Share this post


Link to post
Share on other sites
Yeah, it just looks like wordList isn't ever created. workList=getWordList(); or just getWordList(); probably belongs inside of or along side the getStartGameCommand.

Share this post


Link to post
Share on other sites
Sorry to be cheeky but in areas of my code where i compare strings like so:


if (player2Choice == Word1)



I get a warning saying ' comparing strings with == or != '

should i be comparing them in another way?

Thanks in advance.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ronnie TRFC
Sorry to be cheeky but in areas of my code where i compare strings like so:

*** Source Snippet Removed ***

I get a warning saying ' comparing strings with == or != '

should i be comparing them in another way?

Thanks in advance.


Yes, there's .equals() method.

What you're doing above is checking if both point to same instance. Equals compares their contents.

In general, when you want to compare logical equality of objects (is A same as B), always use equals. If you're interested into sameness (is A actually A, even if it's called B), then use equality.

In Java, comparing using == is rare, so equals should be preferred.

Share this post


Link to post
Share on other sites

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this