无法使用调试器(无法连接到VM)

时间:2014-11-21 17:46:42

标签: java eclipse window

Eclipse已经有一段时间了,但是我最近遇到了一个错误,现在真的很烦我,因为我无法使用调试器。我可以正常运行我的程序,但不能运行调试程序。这是我尝试使用调试器运行时得到的结果:

  

'启动CarLoanUser'遇到了问题   无法连接到VM   无法连接到VM   com.sun.jdi.connect.TransportTimeoutException

并在控制台中:

  本地方法中的

FATAL ERROR:JDWP没有初始化传输,   jvmtiError = AGENT_ERROR_TRANSPORT_INIT(197)错误:传输错误202:   连接失败:权限被拒绝错误:JDWP传输dt_socket   无法初始化,TRANSPORT_INIT(510)JDWP退出错误   AGENT_ERROR_TRANSPORT_INIT(197):未初始化传输   [debugInit.c:750]

我已经尝试了很多相关的事情:

  • 重启Eclipse
  • 重新启动计算机
  • 尝试我拥有的其他代码
  • 重新安装Eclipse(Luna)
  • 删除Eclipse(Luna)并将其替换为Eclipse Java EE(Kepler)
  • 回到Eclipse(Luna)
  • 卸载所有Java实例并安装Java 8
  • 卸载Java 8并安装Java 7(所有Java安装均使用64位安装程序)
  • 用ccleaner清理注册表

我目前在Windows 8.1 64位上运行

如果有帮助,我会提供我目前正在处理的代码

import java.util.Scanner;
import java.text.NumberFormat;

/**
 * Title:  CarLoanUser
 * Description: 
 * @author 
 * @version 1.0
 */

public class CarLoanUser {

/**
 * @param args
 */
public static void main(String[] args) {
    runWithConsole();
}//main(args)

public static void runWithConsole()
{
    NumberFormat money = NumberFormat.getCurrencyInstance();
    Scanner key = new Scanner(System.in);
    CarLoanMethods user;
    int numberOfPayments = 0;
    double remainingAmount, remainingAmountInCalculation; 
    user = new CarLoanMethods();

    System.out.print("What is the model? ");
    user.setModel(key.nextLine());

    System.out.print("What is the loan amount? ");
    user.setLoanAmount(key.nextInt());
    remainingAmountInCalculation = user.getLoanAmount(); 

    System.out.print("What is the interest rate? ");
    user.setInterestRate(key.nextInt());

    System.out.print("What is the monthly payment? ");
    user.setMonthlyPayment(key.nextInt());

    user.calculateEverything();

    System.out.printf("\n%10s%35s", "Car model: ", user.getModel());
    System.out.printf("\n%14s%31s", "Amount to pay: ", money.format(user.getTotalPrice()));
    System.out.printf("\n%33s%12s", "Total interest that will be paid: ", money.format(user.getTotalInterest()));
    System.out.printf("\n%19s%26s", "Number of payments: ", user.getNumberOfPayments());

}//runWithConsole()
}//CarLoanUser class

方法类:

/**
 * @author 
 *
 */
public class CarLoanMethods {

private String model;
private int loanAmount;
private int interestRate;
private int numberOfPayments = 0;
private double monthlyPayment;
private double interestTotal;
private double interest;
private double toBePaid;

public CarLoanMethods()
{
    model = "Unknown";
    loanAmount = 0;
    interestRate = 0;
    monthlyPayment = 0;
}//CarLoanMethods()

public CarLoanMethods(String userModel, int userLoan)
{
    model = userModel;
    loanAmount = userLoan;
    interestRate = 0;
    monthlyPayment = 0;
}//CarLoanMethods(String, int)

public CarLoanMethods(int userInternetRate, int userMonthlyPayment)
{
    model = "Unknown";
    loanAmount = 0;
    interestRate = userInternetRate;
    monthlyPayment = userMonthlyPayment;
}//CarLoanMethods(int, int)

public void setModel(String userModel)
{
    model = userModel;
}//setModel(String)
public String getModel()
{
    return model;
}//getModel()

public void setLoanAmount(int userLoan)
{
    loanAmount = userLoan;
}//setLoanAmount(int)
public int getLoanAmount()
{
    return loanAmount;
}//getLoanAmount()

public void setInterestRate(int userInterestRate)
{
    interestRate = userInterestRate;
}//setInterestRate(int)
public int getInterestRate()
{
    return interestRate;
}//getInterestRate()

public void setMonthlyPayment(double userMonthlyPayment)
{
    monthlyPayment = userMonthlyPayment;
}//setMonthlyPayment(double)
public double getMonthlyPayment()
{
    return monthlyPayment;
}//getMonthlyPayment()


public double getTotalInterest()
{
    return interestTotal;
}//getTotalInterest()

public double getTotalPrice()
{
    return interestTotal + loanAmount;
}//getTotalPrice

public int getNumberOfPayments()
{
    return numberOfPayments;
}

public void calculateEverything()
{
    double remainingAmountInCalculation = getMonthlyPayment();
    while (remainingAmountInCalculation >= 0)
    {   

        interest = remainingAmountInCalculation * ((interestRate / 100.0) / 12.0);
        interest = Math.round(interest * 100.0) / 100.0;
        remainingAmountInCalculation =  (remainingAmountInCalculation + interest) - monthlyPayment;
        interestTotal += interest;
        ++numberOfPayments;
    }
}
}//CarLoanMethods

该计划应按我的意图行事。我知道这需要一些工作,但是。是的。

2 个答案:

答案 0 :(得分:1)

我一直有这个问题。 我真的找不到一个明确的解决方案(一个让它在100%的时间内工作的解决方案),但至少我可以调试。

首先,您需要检查javaw是否已在使用该端口。要在Windows中执行此操作,您有两种选择:

  • 转到任务管理器 - >资源监控 - >网络。

并检查监听端口(javaw使用5001和8080)

  • run - > cmd - >然后键入:netstat -n

您将在收听时看到端口5001和8080。

如果您看到打开的端口不打算调试。正常运行应用程序,停止它,等待几秒钟然后再次检查。

如果您在收听时没有看到它们,那么您可以进行调试,但不要通过菜单进行调试;去运行 - >调试配置 - >并从那里按调试。

我知道这不是一个明确的解决方案(这个问题已经有1年了)但是这对我来说足够让我调试并继续开发。

答案 1 :(得分:0)

This解决方案说这可能是因为调试器想要使用它的端口。

我认为它也可能是阻止它的防火墙,确保不是问题。