新手开始编码,目前正在做一个制作“约会网站”的小项目。我正在完成它,但是我决定编译我的代码,一个错误出现了,尽管我已经创建了一个对象?
仅供参考,我已经创建了一个练习
类,看起来像这样:
public class Practice {
String name;
short age;
int height;
public Practice ( String name, short age, int height ) {
this.name = name;
this.age = age;
this.height = height;
}
}
import java.util.Scanner;
public class Dating {
public static void kathHeightDiff () {
if ( user1.height > katherine.height )
System.out.println("You are 5 taller");
else
System.out.println("You are 6 taller");
}
public static void main (String[] args) {
System.out.println("Hello kind sir. Are you interested in love? Press 1 for yes, other numbers for no");
int userAnswer = IO.readInt();
if ( userAnswer == 1 ) {
System.out.println("Nice! What is your name?");
String userName = IO.readString();
System.out.println("Cool. What is your age?");
Scanner age = new Scanner(System.in);
short userAge = age.nextShort();
System.out.println("What is your height in inches? 5'0 is 60, 5'6 is 66, 6'0 is 72");
int userHeight = IO.readInt();
Practice priya = new Practice( "Priya", (short)19, 62);
Practice katherine = new Practice ( "Katherine", (short)18, 63);
Practice jed = new Practice ("Jedidiah", (short)20, 67);
Practice yourMom = new Practice ("Your mom", (short)53, 61);
Practice umayma = new Practice ("Umayma", (short)19, 63);
Practice nawal = new Practice ("Nawal" , (short)20, 64);
Practice user1 = new Practice( userName, (short)userAge, userHeight);
System.out.println("Do you have a desired height? If so, press 1");
int hPreference = IO.readInt();
System.out.println();
if ( hPreference == 1 ) {
System.out.println("How tall in inches? 5'0 is 60, 5'6 is 66, 6'0 is 72 ");
int desiredHeight = IO.readInt();
System.out.println();
}
System.out.println("Which band member would you rather date?");
System.out.println();
System.out.println("A for drummer");
System.out.println("B for guitarist");
System.out.println("C for Singer");
System.out.println("D for piano guy");
System.out.println();
char bandMember = IO.readChar();
switch (bandMember) {
case 'A':
System.out.println("You picked A ( Drummer )");
System.out.println("You sure love your full-arms workout");
break;
case 'B':
System.out.println("You picked B ( Guitarist )");
System.out.println("All you need is your fingers");
break;
case 'C':
System.out.println("You picked C ( Singer )");
System.out.println("Maybe you like some mouth action");
break;
case 'D':
System.out.println("You picked D ( Piano Guy )");
System.out.println("Classic, I see");
break;
default:
System.out.println("No choice? I respect your choice");
break;
}
System.out.println();
System.out.println("What ball is life?");
System.out.println();
System.out.println("A for basketball");
System.out.println("B for Soccer");
System.out.println("My balls");
System.out.println("D for Football");
System.out.println();
char ball = IO.readChar();
switch (ball) {
case 'A':
System.out.println("You picked A ( Basketball )");
System.out.println("You're a baller too");
break;
case 'B':
System.out.println("You picked B ( Soccer )");
System.out.println("Messi > Ronaldo");
break;
case 'C':
System.out.println("You picked C ( Human balls )");
System.out.println("Nice");
break;
case 'D':
System.out.println("You picked D ( Football )");
System.out.println("Ehh");
break;
default:
System.out.println("Just pick something");
break;
}
System.out.println();
System.out.println("Vacation?");
System.out.println();
System.out.println("A for London?");
System.out.println("B for Seoul?");
System.out.println("C for Paris?");
System.out.println("D for Cancun?");
char trip = IO.readChar();
System.out.println();
switch (trip) {
case 'A':
System.out.println("You picked A ( London )");
System.out.println("Brexit or no?");
break;
case 'B':
System.out.println("You picked B ( Seoul )");
System.out.println("A complimentary visit to North Korea after");
break;
case 'C':
System.out.println("You picked C ( Paris )");
System.out.println("City of Love, just like my mattress");
break;
case 'D':
System.out.println("You picked D ( Cancun )");
System.out.println("Everyday is Spring Break");
break;
default:
System.out.println("Get out of the house");
}
System.out.println();
if ( bandMember == 'A' && ball == 'A' && trip == 'A' ) {
System.out.println("Your match is " + katherine.name + ". Press 1 for details, other to leave");
int details = IO.readInt();
if ( details == 1 ) {
System.out.println("Her name is " + katherine.name );
System.out.println("Her age is " + katherine.age );
System.out.println("Her height is " + katherine.height + " inches");
System.out.println();
kathHeightDiff();
}
} else {
System.out.println("OK BYE HAVE A WONDERFUL TIME");
}
}
}
}
它说它找不到user1。身高和凯瑟琳。在我的
kathHeightDiff()方法中,heigh
t。我有点困惑,因为当我做Practice user1=new Practice(用户名,(短)年龄,用户身高)
时,我不是已经创建了它吗?
您在main()方法中创建了一个局部变量。因此,其范围是:主要方法。
如果一个变量应该由多个方法使用,则必须将该变量作为参数传递给这些方法调用,或者必须将该局部变量转换为周围类的字段。
当我加上 遇到错误 找不到DefaultConfig_Enterprise{name=main,dimension=null,minsdkversion=defaultapiversion{mapilevel=14,mcodeName='null'},targetsdkversion=defaultapiversion{mapilevel=30,mcodeName='null'},rendersc
问题内容: 新的Java程序员在尝试运行Java程序时经常会遇到这些消息。 这是什么意思,是什么原因引起的,应该怎么做才能解决? 问题答案: 当你使用java命令从命令行运行Java应用程序时,例如, 该命令将加载你指定的类,然后查找名为的入口点方法。更具体地说,它正在寻找一种声明如下的方法: 入口点方法的特定要求是: 该方法必须在指定的类中。 方法的名称必须为 ,且大小写精确为1。 方法必须是。
问题内容: 我试图以编程方式生成一组按钮,并使它们在片段中可单击。但是,我得到: 到目前为止,这是我的代码: 此外,android studio在此行上突出显示“标签”: 我有这个:“ ” 问题答案: 替换此行: 与:
确切错误:“错误:在类节点中找不到Main方法,请将Main方法定义为:public static void Main(string[]args)或JavaFX应用程序类必须扩展JavaFX.application.application” 但主要功能已经定义。
我在生成签名的apk时出错 它在构建APK时工作正常。 这里有什么问题?