I got my inv finally working! :D But, you know... now... it's dumb. I want it to say "Use Item 1" or whatever when I Right-click so I do this:
if (actItemx == "Item 1") {
popup.add(dropMenuItem + " " + actItemx); // should print "Use Item 1"
popup.add(cancelMenuItem);
}
Looks fine to me... but... when I compile, it's fine. When I run it, it's fine... but when I DO IT:
I would have sworn that because it's displayed correctly in CMD that it would display correctly on JMenu... weird.
popup.add(dropMenuItem + " " + actItemx);
That command is adding the toString() representaion of the dropMenuItem Swing component, plus a space, the the String value of actItemx.
I would guess you want:
popup.add(dropMenuItem.getText() + " " + actItemx);
Related
Ok, I am very, very new to Java and am self taught, so no making fun of my bad coding ;)
I am messing around with Java fx and am trying to insert an image into a borderpane layout.
this is the method that is in the controller I am using to make an image appear but I cant get the filepath to work. It currently has "/images/brownBear.jpg" as the filepath, but I've tried the relative path-
com/jaimependlebury/mammal/images/brownBear.jpg
and the full path and everything in between and i either get a
FileNotFoundException
or
NullPointerErrorException
I'm not even sure I set it up correctly, I've found different things on different websites and have tried to piece information together, so any help would be appreciated.
FXML file
<ImageView fx:id="picture">
</ImageView>
Controller file-
I have the ImageView picture variable declared at the top of the class, I just didn't include it in the code block.
#FXML
public void handleMammalListView()throws FileNotFoundException {
Species species= mammalList.getSelectionModel().getSelectedItem();
picture=new ImageView();
Image img =new Image(new FileInputStream("/images/brownBear.jpg"));
picture.setImage(img);
speciesName.setText(species.getSpeciesName());
details.setText(
"Scientific name: " + species.getScientificName() +"\n"+
"Staus: " + species.getStatus() + "\n" +
"Distribution: " + species.getHabitat() +"\n" +
"Food: " + species.getFood() + "\n" +
"Birth: " + species.getBirth() + "\n" +
"Distinguishing Characteristics: " + species.getBodyType() + "\n"+
"Nursing: " + species.getNurse() + "\n" +
"Type of hair: " + species.getTypeOfHair());
The following line of code:
picture=new ImageView();
Is resetting the reference you set in your FXML - you can just remove it.
I've commented code like below :
/*System.out.println("Parsed in main : " + parsed);
System.out.println("Parsed sum " + (parsed.getHour() + parsed.getMinute()));
System.out.println(isSessionSelected("10:00:00 am"));*/
However, after organize import it disturb the import and look like this :
/*
* System.out.println("Parsed in main : " + parsed);
* System.out.println("Parsed sum " + (parsed.getHour() + parsed.getMinute()));
* System.out.println(isSessionSelected("10:00:00 am"));
*/
This eats my time as every time I uncomment code I have to remove extra *.
How to not let eclipse do this?
If you want to remove those extra *.
in eclipse go to
Window->Preferences->Java->Code Style->Formatter.
Create a new profile by clicking on new button.
after that a new dialog appears,
Select Comments tab
uncheck Enable block comment formatting.
I have a tool what uses Perforce. When it merge a branch back to the parent, mark the project branch with checkout a text file, and submit it unchanged. This tool also use that text file, for read the actual build number. My problem is, a "/n" appeared in the text, and because it have to contain just numbers, it's a big problem.
Have anyone met this problem, or this can't caused by P4C?
Maybe important, I don't use P4JAVA here.
Please note that I'm debugging right now, and I'm not sure the problem is here, but at the moment this seems the most probable.
//<path> is a legit path, I just shortened the code here
commandSync = "p4 -d " + getPerforceRoot() + " sync " + selectedDataBean.getP4Path() + "<path>/BuildNum.txt";
CommandResultBean syncCommandResult = commandExecuter.runAndGetResults(commandSync);
//command executer that runs the command string in cmd
commandMark = "p4 -d " + getPerforceRoot() + " edit -c " + changelistNumber + " " + selectedDataBean.getP4Path() + "<path>/BuildNum.txt";
CommandResultBean markCommandResult = commandExecuter.runAndGetResults(commandMark);
commandSubmit = "p4 -d " + getPerforceRoot() + " submit -f submitunchanged -c " + changelistNumber;
CommandResultBean submitCommandResult = commandExecuter.runAndGetResults(commandSubmit);
I believe that most of you would be thinking that this is the same question you have heard multiple times (and answered ) about string concatenation in Java. But trust me, it is different. In fact, so different that I am even hesitant in posting it here. But anyways, here it is. I have some piece of code which goes like:
public void handleSuccess(String result)
{
result = result.trim();
MessageBox.alert("Information","Result after trimming: '" + result + "'");
result = result.substring(result.indexOf('\n') + 1);
MessageBox.alert("Information","Result after substring: '" + result + "'");
String returns = getReturns();
MessageBox.alert("Information","Returns: '" + returns + "'");
String action = getAction();
MessageBox.alert("Information","Action: '" + action + "'");
String finalResult = result + returns + action;
MessageBox.alert("Information","Final result: '" + finalResult + "'");
}
Now the situation here is that, all of these : getReturns(), result and getAction() return non blank values, and in fact the string finalResult contains the concatenated value after the last line is executed.
So, at Line 1, "result" contains "12/03/2013|04-AERTY|". The value of result remains same at end of line 1,2. getReturns() returns value 12.4724. So at end of line 3, finalResult contains "12/03/2013|04-AERTY|12.4724". getAction() returns "expt". So, at end of line 5, finalResult contains "12/03/2013|04-AERTY|12.4724|expt"
This is , when I debug or run the application in eclipse. As soon as build the same application on a UNIX system to generate a "war" file, and deploy the war on a tomcat server, the problem rears it's ugly head. When I run the application on the deployed war, the last line does not contain the concatenated value. So at the end of line 5, finalResult contains just "12/03/2013|04-AERTY|12.4724". I expected it to contain "12/03/2013|04-AERTY|12.4724|expt" as it does while running in eclipse.
I have tried stringbuffer, stringbuilder and the "+" operator as well, but nothing seems to work. I am not even getting an exception.
Can somebody help me in fixing this or at least enlightening me in what I might be doing wrong here?
Just to stress again, the code on eclipse(which is on a windows machine) and UNIX machine are exactly same. I have done a diff on them.
Here is what I get after putting the message-boxes:
Message-box 1: "Result after trimming: '12/03/2013|04-AERTY|'"
Message-box 2: "Result after substring: '12/03/2013|04-AERTY|'"
Message-box 3:"Returns: '12.4724'"
Message-box 4:"Action: '|expt'"
Message-box 5:"Final result: '12/03/2013|04-AERTY|12.4724|expt'"
Message-box 5 output is the one I receive when I execute code using eclipse
When running on deployed war, Message-box 1-4 have the same output as above, but Message-box 5 says: "Final result: '12/03/2013|04-AERTY|12.4724"
It's not clear where the extra "|" is meant to come from - if getAction() just returns expt, the result would be 12/03/2013|04-AERTY|12.4724|expt.
Anyway, I think it's safe to say that string concatenation will be working fine, and something else is wrong. You should add more diagnostics, logging everything:
public void handleSuccess(String result) {
result = result.trim();
log.info("Result after trimming: '" + result + "'");
result = result.substring(result.indexOf('\n') + 1);
log.info("Result after substring: '" + result + "'");
String returns = getReturns();
log.info("Returns: '" + returns + "'");
String action = getAction();
log.info("Action: '" + action + "'");
// It's not clear what this is meant to do. I suggest you remove it and
// use logging instead.
MessageBox.alert("Information", "The selected action is " + action, null);
String finalResult = result + returns + action;
log.info("Final result: '" + finalResult + "'");
I suspect you'll find that action is an empty string in the broken case.
Note that I've added quotes round each of the logged values, very deliberately. That means that if there's some unprintable character at the end of a string which causes problems, you should be able to detect that in the logging.
EDIT: As per the comment thread, when these were turned into message boxes (as it turns out this is running in GWT) it looks like there's something wrong with the early strings, as the closing ' isn't seen in diagnostics, in the broken case. The OP is going to investigate further.
I have the below code and on my computer via Eclipse virtual device it works fine. But when installed on a real life phone it always reverts to the else statement.
This activity does not always get passed a value and if it is not I want a random record to appear. Thank you for any help or advice and time taken to read.
searchId = getIntent().getIntExtra("EMPLOYEE_ID", 0);
if(searchId > 0){
Query="SELECT * FROM " + DB_TABLE +" ORDER BY RANDOM() LIMIT 1";
Log.v("STANDARD RANDOM", "Was run");
}
else{
Query ="SELECT * FROM " + DB_TABLE +" WHERE _id=" + searchId + "";
Log.v("FROM SEARCH PAGE", "Was run");
}
Not sure if this fixes your problem. But according to the documentation, your code is not correct:
The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".
Taken from Intent.putExtra.
You are using "EMPLOYEE_ID", without a package prefix, but you must include one!