Java console is not showing

No Console found. How to get the console for my JVM?

This is a follow-up question to this. I asked this question yesterday, and although it is not resolved yet, I tried to make some silly changes to the code to just make it compile once (replacing console.format() statements by System.out.print statements, and adding null as the second argument to the readLine() methods). Luckily the code did run, but it prints No console. (obviously because the JVM does not have a console device. Reference) So how can I get the console device, supposed to be represented by an object of the Console class? For convenience, I am adding the code after I made the aforementioned silly changes to it to make it run:-

import java.io.Console; import java.util.regex.Pattern; import java.util.regex.Matcher; /* * Enter your regex: foo * Enter input string to search: foo * I found the text foo starting at index 0 and ending at index 3. * */ public class RegexTestHarness < public static void main(String[] args)< Console console = System.console(); if (console == null) < System.err.println("No console."); System.exit(1); >while (true) < Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: ", null)); Matcher matcher = pattern.matcher(console.readLine("Enter input string to search: ", null)); boolean found = false; while (matcher.find()) < /*console.format("I found the text" + " \"%s\" starting at " + "index %d and ending at index %d.%n", matcher.group(), matcher.start(), matcher.end());*/ System.out.println("I found the text " + matcher.group() + " starting at index " + matcher.start() + " and ending at index " + matcher.end() + "."); found = true; >if(!found) < //console.format("No match found.%n", null); System.out.println("No match found."); >> > > 

How do you run this code? I have a feeling that you are using some IDE like Eclipse, NetBeans or InteliiJ.

Источник

Eclipse Console not showing output

I have written a simple class having an SOP statement for «Hello World». But the Eclipse console is not showing output. I then wrote the same program in a previously created project and it worked fine. I am opening the Console as given below:

Читайте также:  What is escape character in html

But it is not working. I am using j2ee project in the same workspace. Any idea? Please help. I am stuck because of this problem.

share screenshot of your problem that you are facing. How some can know what issue you having if they don’t see it.

14 Answers 14

Go to «Window > Reset Perspective», that will reset the window settings to default. Next, you might need to stop any running Java processes. I suggest you then click «Remove all Terminated Launches» and if the red «Terminate All» is still available click that as well

Remove all Terminated Launches

I reset perspective and open console.it shows me console with red button on.i also click on terminate all button.still i will not work.

[working] I encountered the same problem, I tried with all the solutions provided above but it didn’t work then I came to a solution which worked. Follow the following process to overcome the problem.

Right click on workspace provided by Eclipse —> Select «Run As» —> Java Application.

enter image description here

This will work definitely.

I’ve lost the console only in the Java default perspective and I wasn’t able to show it again by using window > show view > console.

What I did is the following :

  1. window > Perspective > reset perspective
  2. window > show view > console

Make sure that the project structure should be as follows:

enter image description here

Make sure that your System.out.println(«Hello World») is in main method with proper signature.

public static void main(String[] args)

None of the above. What helped in my case:

Run > Run configurations > Common > uncheck Launch in background (last tab all the way at the bottom).

Then it showed the error why the thing wouldnt start.

In my case: a project dependency to a project which I had closed.

Читайте также:  Python exit script return

See (rightclick) Project > Build path > Configure build path.

Источник

Java: Console doesn’t show any output

enter image description here

Whenever I run my program, nothing shows up. In the console window, all that is visible is blank, white space. Screenshot: Here is a paste of my code:

import java.util.Scanner; public class Foothill < public static void main(String[] args) < // declare the references //warning for line below HeartRates heartrates; //warning for line above: the value of the local variable heartrates is not used // instantiate the object heartrates = new HeartRates(); >> class HeartRates < // member data public String firstName, lastName; public int birthMonth, birthDay, birthYear, personAge, maxRate, minRange, maxRange; // default constructor HeartRates() < >// 2-parameter constructor HeartRates (String userFirstname, String userLastname, int userBirthmonth, int userBirthday, int userBirthYear, int userAge, int heartMax, int userMin, int userMax) < firstName = userFirstname; lastName = userLastname; birthMonth = userBirthmonth; birthDay = userBirthday; birthYear = userBirthYear; personAge = userAge; maxRate = heartMax; minRange = userMin; maxRange = userMax; >// accessor "get" methods -------------------------------- public String getFirstname(String userFirstname, String firstName) < firstName = userFirstname; Scanner inputStream = new Scanner (System.in); userFirstname = inputStream.nextLine(); System.out.print("Your first name is: " + userFirstname); inputStream.close(); return firstName; >public String getLastName(String userLastname, String lastName) < lastName = userLastname; Scanner inputStream = new Scanner (System.in); userLastname = inputStream.nextLine(); System.out.print("Your last name is: " +userLastname); inputStream.close(); return lastName; >public int getBirthmonth(int userBirthmonth, int birthMonth) < birthMonth = userBirthmonth; Scanner inputStream = new Scanner (System.in); userBirthmonth = inputStream.nextInt(); int monthBirth = Integer.parseInt("userBirthmonth"); System.out.print(monthBirth); inputStream.close(); return birthMonth; >public int getBirthday(int userBirthday, int birthDay) < birthDay = userBirthday; Scanner inputStream = new Scanner (System.in); userBirthday = inputStream.nextInt(); int dayBirth = Integer.parseInt("userBirthday"); System.out.print(dayBirth); inputStream.close(); return birthDay; >public int getBirthyear(int userBirthyear, int birthYear) < birthYear = userBirthyear; Scanner inputStream = new Scanner (System.in); userBirthyear = inputStream.nextInt(); int yearBirth = Integer.parseInt("userBirthyear"); System.out.print(yearBirth); inputStream.close(); return birthYear; >public int getAge(int birthMonth, int birthDay, int birthYear, int userAge) < personAge = userAge; Scanner inputStream = new Scanner (System.in); System.out.print("Please enter the current month in numbers: "); int theMonth = inputStream.nextInt(); System.out.print("Please enter the current day in numbers: "); int theDay = inputStream.nextInt(); System.out.print("Please enter the current year in numbers: "); int theYear = inputStream.nextInt(); userAge = theYear - birthYear; if ((theMonth == birthMonth && theDay < birthDay) || theMonth < birthMonth)< userAge--; System.out.println("Your date of birth is: " + birthMonth + "/" + birthDay + "/" + birthYear); System.out.println("You are " + userAge + " years old."); >else < System.out.println("Your are " + userAge + " years old."); >inputStream.close(); return userAge; > public int getMaximumHeartRate(int heartMax, int userAge, int maxRate) < maxRate = heartMax; heartMax = 220 - userAge; return maxRate; >public double getMinTargetHeartRate(int heartMax, int userMin, int minRange) < minRange = userMin; userMin = (int)(heartMax*0.5); return minRange; >public int getMaxTargetHeartRate(int heartMax, int userMax, int maxRange) < maxRange = userMax; userMax = (int)(heartMax*0.85); return maxRange; >public void getTargetHeartRange(int heartMax, int userMin, int userMax) < System.out.println("Your maximum heart rate is " + heartMax + "beats per minute."); System.out.print("Your target-heart-rate range is from " + userMin + " to " + userMax + " beats per minute."); >// accessor "set" method ------------------------------- public void setFirstname(String userFirstname, String firstName) < firstName = userFirstname; >public void setLastname(String userLastname, String lastName) < lastName = userLastname; >public void setBirthmonth(int userBirthmonth, int birthMonth) < birthMonth = userBirthmonth; >public void setBirthday(int userBirthday, int birthDay) < birthDay = userBirthday; >public void setBirthyear(int userBirthyear, int birthYear) < birthYear = userBirthyear; >public void setAge(int userAge, int personAge) < personAge = userAge; >public void setMaximumHeartRate(int heartMax, int maxRate) < maxRate = heartMax; >public void setMinTargetHeartRate(int userMin, int minRange) < minRange = userMin; >public void setMaxTargetHeartRate(int userMax, int maxRange) < maxRange = userMax; >> 

I’m a beginner to Java, and from my code you can probably tell I’m struggling to grasp the concept of creating classes, methods, and instantiating objects. In fact, we’re supposed to print out all the information from the object, but I don’t quite understand what that means. Most of what I have are based from examples online or from my book. I know there have been similar questions asked, but I think mine is slightly different. Thank you so much.

Читайте также:  Тег IMG

Источник

Оцените статью