Java 无法看到另一个文件中的方法

Java 无法看到另一个文件中的方法,java,methods,Java,Methods,我有一个java程序的问题,我必须使类。我要把两个字母转换成一个位置。然后,我将获取一条消息,并使用基本字符交换对其进行加密。我似乎有一个问题,我的驱动程序文件中的调用无法看到我试图在操作文件中调用的方法。我肯定我遗漏了一些简单的东西,而且做得不对,但是我读的文档越多,我就越困惑。有人能给我解释一下我做错了什么吗。我正在尝试从驱动程序文件调用操作文件中的getCountry方法。错误就在这条线上 locH = loc.getCountry(locationLetters); Driver.j

我有一个java程序的问题,我必须使类。我要把两个字母转换成一个位置。然后,我将获取一条消息,并使用基本字符交换对其进行加密。我似乎有一个问题,我的驱动程序文件中的调用无法看到我试图在操作文件中调用的方法。我肯定我遗漏了一些简单的东西,而且做得不对,但是我读的文档越多,我就越困惑。有人能给我解释一下我做错了什么吗。我正在尝试从驱动程序文件调用操作文件中的getCountry方法。错误就在这条线上

locH = loc.getCountry(locationLetters); 
Driver.java

/**
Program Name: Action
Date:4/14/2016

Program Description: This program is going to handle the window where the user enters data.
It is also going to be what is going to call the methods of the Actions class
Methods: Driver(),
*/
import javax.swing.*;    // For the Swing classes
import java.awt.event.*; // For the ActionListener Interface

import java.util.Scanner; //for the keyboard


public class Driver extends JFrame
{
 //delcare
  private String locationLetters; //this is going hold the users letter selection
  private String message; //this is going to hold the users message  

  private String locH; //for the holder of location selection
  private String messH; //to hold the message before change it to an array

  Scanner keyboard = new Scanner (System.in);//to make the keyboard
  /**
  This method is the constuctor that is going to make the window for the program to use.
  */
 public Driver()
 {
  System.out.println("sup nerd");

  yourmom();
 }//end of Driver()

 public String yourmom()
 {
  System.out.println("Please entner the two charater key for the location you want to message");
  locationLetters = keyboard.next();

  System.out.println("Please enter the message you would like to have encrypted.");
  message = keyboard.next();


 locH = loc.getCountry(locationLetters);
 return locH;

 }//end of yourmom()


 public static void main(String[] arg)
 {
  Actions loc = new Actions();
  Actions mess = new Actions();
  new Driver();


 }//end of main

}//end of Driver class
Actions.java

/**
Program Name: Action
Date:4/14/2016
Program Description: This program is going to handle all the encryption actions as well
loction where the message is being sent.
Methods:Location(),
*/


public class Actions
{
 //decare

 public String messE; //this is for the message that is going to be ecrypted

 public String getCountry(String locHA)
 {
  locHA.toUpperCase();
  if(locHA == "FR")
   locHA = "France";
  if(locHA == "GB")
   locHA = "Great Britain";
  if(locHA == "CA")
   locHA = "Canada";
  if(locHA == "JA")
   locHA = "Japan";
  if(locHA == "RU")
   locHA = "Russia";
  if(locHA == "GE")
   locHA = "Germany";
  if(locHA == "AU")
   locHA = "Australia";
  if(locHA == "MX")
   locHA = "Mexico";
  return locHA;    
 } 
}//end of action class 

我知道这可以在一个文件中完成,但我的老师想要在两个文件中完成。我知道我遗漏了一些简单的东西,但我不理解我一直在阅读的关于使用对象的文档。你能指出我做错了什么吗?我将非常感激。谢谢。

更改主数据,以便将重要数据传递到驱动程序:

public static void main(String[] arg) {
    Actions loc = new Actions();
    Actions mess = new Actions();
    new Driver(loc, mess);
}
然后在主构造函数中使用这些操作:

public Driver(Actions loc, Actions mess) {
    // use parameters to set fields so that the parameter references can be 
    // used elsewhere in the class
    this.loc = loc;
    this.mess = mess;

    System.out.println("sup nerd");
    yourmom(loc); // and pass references where needed
}
类似地,在yourmom()方法中使用loc引用

另外,不要使用
==
比较字符串=。请改用
equals(…)
equalsIgnoreCase(…)
方法。了解
==
检查两个对象引用是否相同,这不是您感兴趣的。另一方面,这些方法检查两个字符串是否具有相同顺序的相同字符,这就是这里的问题所在。所以不是

if(locHA == "FR")
    locHA = "France";

在你的主课上。
你可以把公众带出二等舱,因为二等舱不那么容易到达

这是因为您在方法
main()
中声明了
loc
,并试图从方法
yourmom()
访问它。另外,不要发布代码的链接;将代码粘贴到问题本身。代码必须在问题本身中。不是在巴斯德宾。此外,当询问错误时,请张贴错误内容。@Grimmjow91:如果您想在评论中通知某人,请在其姓名前预先挂起
@
。因此,如果你想通知用户2004685,请将
@user2004685
放在你对他的评论中。@HovercraftFullOfEels啊,谢谢。谢谢@user2004685,明白了。另外,关于不使用pastebin的部分也被提到,我对此有疑问。每当我使用.equals时,它都不起作用,我也不知道为什么。
// always use curly braces too!
if("FR".equals(locHA)) {
    locHA = "France";
}
// if you want to allow more liberal capitalization
if("FR".equalsIgnoreCase(locHA)) {
    locHA = "France";
}
Actions.getCountry();