【问题标题】:Unable to use the debugger ( Cannot connect to VM )无法使用调试器(无法连接到 VM)
【发布时间】:2015-01-19 22:46:17
【问题描述】:

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

“启动 CarLoanUser”遇到问题 无法连接到虚拟机 无法连接到虚拟机 com.sun.jdi.connect.TransportTimeoutException

在控制台中:

本机方法中的致命错误: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

该程序应该按我的预期工作。我知道它需要一些工作,但是是的。

【问题讨论】:

    标签: java eclipse window


    【解决方案1】:

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

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

    • 进入任务管理器 -> 资源监视器 -> 网络。

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

    • 运行 -> cmd -> 然后输入:netstat -n

    您会在监听时看到端口 5001 和 8080。

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

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

    我知道这不是一个确定的解决方案(而且这个问题已经存在 1 年了),但这对我来说足以让我调试并继续开发。

    【讨论】:

    • 注意:我已经检查了几次防火墙是否阻止它。我肯定需要检查资源监视器并等待 javaw 实例死亡,然后才能进行调试。由于某种原因,编译会杀死当前进程,而调试不会。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 2018-07-01
      • 1970-01-01
      相关资源
      最近更新 更多