This is a bug #122429 of eclipse
Answer from swimmingfisher on Stack OverflowThis is a bug #122429 of eclipse
This code snippet should do the trick:
private String readLine(String format, Object... args) throws IOException {
if (System.console() != null) {
return System.console().readLine(format, args);
}
System.out.print(String.format(format, args));
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
return reader.readLine();
}
private char[] readPassword(String format, Object... args)
throws IOException {
if (System.console() != null)
return System.console().readPassword(format, args);
return this.readLine(format, args).toCharArray();
}
While testing in Eclipse, your password input will be shown in clear. At least, you will be able to test. Just don't type in your real password while testing. Keep that for production use ;).
command line - Try to disable console output, console=null doesn't work - Unix & Linux Stack Exchange
When will be Console.Readline() == null?
html - Why am I getting null in the console in JavaScript? - Stack Overflow
java - System.console() is null - Stack Overflow
1. Using dmesg
One method would be to do so using dmesg:
-n, --console-level level
Set the level at which logging of messages is done to the console.
The level is a level number or abbreviation of the level name.
For all supported levels see dmesg --help output.
For example:
$ sudo dmesg -n0
2. Using rsyslog
Another method would be through rsyslog. The config file /etc/rsyslog.conf:
#kern.* /dev/console
Changing this line to this:
kern.* /dev/null
NOTE: A restart of rsyslog is necessary, sudo service rsyslog restart.
3. Using sysctl
Lastly you can control this at the kernel level via sysctl.
I suggest you alter your /etc/sysctl.conf. Specifically, you want to tweak the kernel.printk line.
# Uncomment the following to stop low-level messages on console
kernel.printk = 3 4 1 3
You can see your current settings:
$ sudo sysctl -a|grep "kernel.printk\b"
kernel.printk = 4 4 1 7
4. Using silent
If you truly want to disable all logging, even during boot then change the string quiet to silent in the boot arguments to the kernel in GRUB, in /boot/grub2/grub.cfg.
linux /vmlinuz-3.12.11-201.fc19.x86_64 ... rhgb silent ....
After hours of searching:
Comment out the *.emerg line or change it to *.emerg /var/log/messages etc
I'm learning C# (.NET 8.0) and doing exercises on Microsoft Learn platform.
The following code won't work as intended, because if I hit enter, without any prompt the readResult will be an empty string instead of null.
Description from the exercise:
When using a
Console.ReadLine()statement to obtain user input, it's common practice to use a nullable type string (designatedstring?) for the input variable and then evaluate the value entered by the user. The following code sample uses a nullable type string to capture user input. The iteration continues while the user-supplied value is null:
Code:
string? readResult;
Console.WriteLine("Enter a string:");
do
{
readResult = Console.ReadLine();
} while (readResult == null);
In this case the program stops in every case, because it won't be null and won't trigger Console.ReadLine() again.
string input = Console.ReadLine(); // just hit enter withount any input Console.WriteLine(input == null); // False Console.WriteLine(input == ""); // True
When will it be null?
Am I right? Is it a bug or something changed in the new version of .NET?
The object isn't rendered immediately. Your img property has a null value at logging time but when you open the object in the console, later, it's filled.
You can check that by logging console.log(JSON.stringify(this.article)).
The most probable reason of your problem is some asynchronous code whose achievement you're not correctly waiting for. As the object is taken from a database as you said, I guess you forget to use the object in the callback (which might be promise based).
Instead of logging:
console.log("Product:", this.article);
var url = this.article.img;
console.log("Image" , url);
try debugging, so that you can inspect the value in real time:
console.log("Product:", this.article);
debugger;
...
In your HTML, you are using popup2 as a class name, not an id!
Therefore, you should replace var modal = document.getElementById('popup2'); by
var modal = document.getElementsByClassName('popup2')[0];
Another thing: make sure this code runs after the HTML has loaded, otherwise it will return undefined. To do so, wrap your code inside:
document.onload = function() {
var modal = document.getElementsByClassName('popup2')[0];
//your code here
}
you can do that with Jquery
$("#popup").hide(); //hidden in start
$("#openPopup").on("click",function(){
$("#popup").show();
});
$("#closePopup").on("click",function(){
$("#popup").hide();
});
see CodePen Demo
You could add a nested loop and only break out when double.TryParse has parsed the input into the array element:
Console.Write("Enter required count marks: ");
int count = Convert.ToInt32(Console.ReadLine());
double[] mark = new double[count];
for (int i = 0; i < count; i++) {
while (true) {
Console.Write("enter mark{0}: ", i + 1);
if (double.TryParse(Console.ReadLine(), out mark[i])) {
break;
}
}
}
Unless the is a good reason to avoid using TryParse, I agree with @P a u l
Here is an alternate for working with int values only.
The following language extension keep code clean although you can take the code in the extension body and use directly in a loop.
internal static class StringExtensions
{
public static bool IsInteger(this string sender)
=> !string.IsNullOrEmpty(sender) && sender.All(char.IsDigit);
}
Test the extension
while (true)
{
Console.Write("Enter value ");
string userInput = Console.ReadLine();
if (userInput.IsInteger())
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(Convert.ToInt32(userInput));
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"'{userInput}' is not valid");
}
Console.ResetColor();
ConsoleKeyInfo ch;
Console.Write("Press the Escape (Esc) key to quit");
ch = Console.ReadKey();
if (ch.Key == ConsoleKey.Escape)
{
Environment.Exit(0);
}
Console.Clear();
}