java屏幕输入字符串,Java:使用键盘类输入字符串

本文介绍了在Java控制台应用中使用Keyboard类遇到的编译错误,指导读者如何通过导入uitl.Keyboard解决'Unresolved compilation problem',包括包导入规则和查看类所在的包结构。
摘要由CSDN通过智能技术生成

I'm trying to input information in Java console application but I can't seem to run it.

This is how my Java file looks like:

public class Ovning1_3

{

public static void main(String args[])

{

String name;

System.out.println("Enter your name");

name = Keyboard.readString();

System.out.println(name);

}

}

But I get the error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

Keyboard cannot be resolved

at Ovning1_3.main(Ovning1_3.java:9)

I have a keyboard.class file in my source folder.

I'm using Eclipse with Ubuntu.

解决方案

Unresolved compilation problem:

means that the code could not be compiled.

You have to import Keyboard, something like

import uitl.Keyboard

When you use classes from a different package (not the same package of the current class), you have to import the class. If the class is also in the same package then you need not import.

Classes are generally grouped into Packages.

How do you know the package? Go to the first like of the class. This should be something like package xyz meaning that the current class in the xyz package. The class will be in a folder called xyz then (This is the rule for packages: when you want to have a class in a package, say abc.xyz then the class should have a package declaration - the first line of the code - to be package abc.xyz and the file should be present in a folder xyz which in then should be in a folder abc.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值