How Do You Troubleshoot the Java Compilation Error “cannot find symbol”?

Problem scenario
You try to compile a Java program with a javac command. You get this error:

special.java:39: error: cannot find symbol
symbol: class foo
location: class bar

What should you do?

Possible solution
In some cases you need a keyword “new”, but in other cases you need to not have the keyword “new”.

Why Would Boto3 Not Show a Peering Connection That the AWS CLI Shows?

Problem scenario
You have found an AWS CLI command that shows you output consistent with the console. You run this:

aws ec2 describe-vpc-peering-connection –region us-west-2 | grep pcx-abcd1234

The results show you a peering connection called pcx-abcd1234

You run this from a Python3 interpreter prompt:

import boto3
foo = boto3.resource(‘ec2’)
foo.describe_vpc_peering.connections()
print(foo)

You then search the output for pcx-abcd1234. You do not see it.

How Do You Troubleshoot the Java Compilation Problem “error expected … illegal start of type”?

Problem scenario
When trying to compile a Java program, you get this output:

ContInt.java:15: error: expected
System.out.println(“test”);
^
ContInt.java:15: error: illegal start of type
System.out.println(“test”);
^

What do you do?

Solution
Create a class for the System.out.println statement to be in.

Here is code that would cause the error:

import java.util.Scanner; …

How Do You Troubleshoot “error: no suitable method found for toString(String)”?

Problem scenario
You are trying to print out a multi-dimensional array in Java. When you try to compile your program, you get this:

error: no suitable method found for toString(String)
System.out.println(Arrays.toString(Arrays.toString(var1)));
^
method Arrays.toString(long[]) is not applicable
(argument mismatch; String cannot be converted to long[])

What should you do?

Solution
You need to pass a one-dimensional array to Arrays.toString in the System.out.println statement.

How Do You Create a Callable Function in Java outside of the “main” Section?

Problem scenario
You have a public static void main (String[] args) portion of your Java program. You want to have a subroutine such as a function outside of this section. How do you code this?

Solution
In Java methods are components of an object that perform an action on the object themselves. We therefore use the term “method” here and not “function”.

How Do You Troubleshoot the Error “Could not find suitable distribution for Requirement.parse(‘botocore==2.0.0dev11’)”?

Problem scenario
You try to install the AWS CLI version 2.x

You run this command:

$ sudo python3 setup.py install

You get a message like this:

Processing dependencies for awscli==2.0.7
Searching for botocore==2.0.0dev11
Reading https://pypi.org/simple/botocore/
No local packages or working download links found for botocore==2.0.0dev11
error: Could not find suitable distribution for Requirement.parse(‘botocore==2.0.0dev11’)

What should you do?

How Do You Install Django on a CentOS/RHEL/Fedora server?

Problem scenario
You want to install Django and have it working for browsing from a desktop workstation. You do not want to leverage Django’s API functionality. How do you install and configure Django from scratch?

Prerequisite
pip3 is probably installed. If you are not sure, you could run this: sudo find / -name pip3

You must have pip or pip3 installed.

How Do You Troubleshoot the Python Error “json.decoder.JSONDecode..”Expecting property name enclosed in double quotes…”?

Problem scenario
You are running a Python program that uses “import json”. You get this error: “json.decoder.JSONDecode..”Expecting property name enclosed in double quotes…” You are not allowed to use bson, but you can use other Python packages. What should you do?

Solution
This solution only works if you can eliminate single quotes in the content to be serialized (or translated into JSON).

How Do You Troubleshoot the Python Program Problem “FileNotFoundError: [Errno 2] No such file or directory”?

Problem scenario
Your Python program is trying to invoke a Bash command. But you get an error like this: “FileNotFoundError: [Errno 2] No such file or directory”. What should you do?

Possible Solution #1 Use the shell=True command if your environment is secure. This is not a recommended practice from a security perspective. We have found that this with shell=True syntax can make the error go away:

subprocess.Popen(variableofcommand,