The code below is action taken when a button is clicked on a simple form. The problem comes with the one if/else block. The If line is not terminated. The Else line is not terminated. But I have a consistent error that my Else exists without an If. I can't see why. I need someone smarter than me to identify what is going on here.
Thank you in advance!
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
FileFilter filter;
filter = new FileNameExtensionFilter("Comma Separated Value files","csv","txt");
JFileChooser chooser;
chooser = new JFileChooser();
chooser.addChoosableFileFilter(filter);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int showDialog = chooser.showDialog(this, null);
File selectedFile = chooser.getSelectedFile();
String filename;
filename = selectedFile.getAbsolutePath();
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
else
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
}
You are missing the bracket '}' after "jTextField2.setBackground(Color.white);" and else.code is here
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
}
else
{
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The SYNTAX for if-else Block looks like this:-
if {
// statements
} else {
//statements
}
Now if you are having only ONE statement inside the if Or else part then you can afford to skip the curly braces{ } otherwise you surely need to put those curly braces as compiler looks for it can terminate the execution of if statement.
However, it is always recommended to use the braces even if u have only ONE statement inside the if or else part as it improves the readability of the code.
You need to close your "if" and "else" blocks.
Example: if {} else {}.
if (filter.accept(selectedFile)) {
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
} else {
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The if's closing bracket is missing just before the else.
Related
When I try to evaluate an expression I get this error: net.sourceforge.jeval.EvaluationException: Invalid use of quotes.
To be clearer. I read my rules from a .txt files where after I put them in a hasmap.
I have tried:
#{mentor} = Chung
#{mentor} = "Chung"
#{mentor} == "Chung"
#{mentor} == 'Chung'
but still gives another error or same error.
What am I doing wrong?
List<String> approvalMentors = new ArrayList<>();
Evaluator evaluator = new Evaluator();
evaluator.putVariable("mentor", String.valueOf(graduationApprovalRequest.getMentor()));
for (HashMap.Entry<String, String> entry : this.schoolRules.entrySet()) {
try {
if(evaluator.evaluate(entry.getValue()).equals("1.0")){
approvalMentors.add(entry.getKey());
}
} catch (EvaluationException ex) {
Logger.getLogger(SchoolRules.class.getName()).log(Level.SEVERE, null, ex);
}
}
return approvalMentors;
.txt File I read my rules from
#{mentor} = 'Chung'
JEval internal validation logic assumes each "operand" (a part of the conditional expression) should be either a built-in function, a number, a special symbol, OR a quoted string. If there is even a single SPACE between the == and double-quote symbols, the check for correctness of quoted string fails. Each such operand should either begin AND end with a quote(s), or do not have the quote(s) at all. The latter is the case with numbers, for example.
I use this code to filter database records
if (!string.IsNullOrEmpty(_searchCriteria.MessageType))
{
var messageType = (AutotransferMessageType)Enum.Parse(typeof(AutotransferMessageType), _searchCriteria.MessageType, true);
if (Enum.IsDefined(typeof(AutotransferMessageType), messageType))
{
criteriaQuery.CreateAlias("AutotransferInputRecord", "AutotransferInputRecord")
.Add(
Restrictions.Eq(
"AutotransferInputRecord." + AutotransferLogSearchCriteria.MessageTypePropertyName,
messageType));
}
else
{
criteriaQuery.Add(Restrictions.IsNull("AutotransferInputRecord"));
}
}
AutotransferMessageType is enumerable type
public enum AutotransferMessageType
{
[DisplayName("MT202")]
[DatabaseName("MT202")]
MT202,
[DisplayName("MT210")]
[DatabaseName("MT210")]
MT210,
//...
}
My filter outputs the results when I enter MT202, for example. (It's the right behavior).
When I input just number, for example, 202, I get no results (It's the right behavior too).
But when I try to input some line, "mt", for example, I get error
Unexpected application error has been occured:
'Requested value 'mt' was not found.'
How to make the filter do not show any results when I input a line?
Your error is coming from the line that parses the enum. Use Enum.TryParse instead:
AutotransferMessageType msgEnum;
var enumPrasedOk = Enum.TryParse(_searchCriteria.MessageType, true, out msgEnum);
if(enumPrasedOk){
//Do something
}else{
//Handle case where enum was not found for some reason (if need be)
}
Also please note that you can not look up the enum this way using it's description (in your case they are the same so it is ok).
I want to create level codes, like in sea of fire (http://armorgames.com/play/351/sea-of-fire)
I have a text input box with the instance name "code" and a button that has this code:
on (release) {
if (code = 96925) {
gotoAndStop(4);
}
if (code = 34468) {
gotoAndStop(5);
}
if (code = 57575) {
gotoAndStop(6);
}
if (code = 86242) {
gotoAndStop(7);
}
if (code = 99457) {
gotoAndStop(8);
}
if (code = 66988) {
gotoAndStop(10);
}
if (code = !96925 && !34468 && !57575 && !86242 && !99457 && !66988) {
gotoAndStop(3);
}
}
I've tried to use code.text instead of just code, I've also tried quotes around the numbers, also I tried both together but it always sends you to frame 10 even if the code is invalid.
You need to use conditional operator (==), not equality operator (=) in 'if' condition
Also if 'code' is a text field then you need to use code.text
You can put trace to check for the value of code.
I do not understand your last if condition
Instead you can use if - else if - else here.
I'm new to PHP so this will sound basic to most people but I need to write the code for when a variable returns nothing (blank).
My variable is $winner, but sometimes there is no winner, in this case it just leaves the page blank, I would like it so if there is no winner then it will display "no winner".
This is my attempt:
if empty($winner) {
echo "no winner";
}
You can make a function to check the variable's valaue with null or empty...
function IsEmptyString($Season){
return (!isset($Season) || trim($Season)==='');
}
This function can be used to check the same.
Just use:
if (!$winner) { // will catch "", null
echo "no winner"
}
I changed this login script to PDO. Now it passes the username but get's stuck fetchAll line. I need help please. thanks
<?php
session_start();
include_once"includes/config.php";
if (isset($_POST['admin_login'])) {
$admin_user = trim($_POST['admin_user']);
$admin_pw = trim($_POST['admin_pw']);
if ($admin_user == NULL OR $admin_pw == NULL) {
$final_report.="Please complete all the fields below..";
} else {
$check_user_data = $db->prepare("SELECT * FROM `admin`
WHERE `admin_user`='$admin_user'");
$check_user_data->execute();
if ($check_user_data->fetchColumn() == 0) {
$final_report.="This admin username does not exist..";
} else {
$get_user_data = $check_user_data->fetchAll($check_user_data);
if ($get_user_data['admin_pw'] == $admin_pw) {
$start_idsess = $_SESSION['admin_user'] = "".$get_user_data['admin_user']."";
$start_passsess = $_SESSION['admin_pw'] = "".$get_user_data['admin_pw']."";
$final_report.="You are about to be logged in, please wait a few moments...";
header('Location: admin.php');
}
}
}
}
?>
Not checking return value prepare() or execute() for false. You need to check for SQL errors and handle them, stopping the code instead of continuing on blithely.
Not using query parameters in the prepared statement, still interpolating $_POST content into the query unsafely. You're missing the benefit of switching to PDO, and leaving yourself vulnerable to SQL injection attack.
You're storing passwords in plaintext, which is unsafe. See You're Probably Storing Passwords Incorrectly.
Do you really need to SELECT * if you only use the admin_pw column? Hint: no.
PDOStatement::fetchAll() returns an array of arrays, not just one array for a row. Read the examples in the documentation for fetchAll().