我想在Android上运行Java代码。但是我对 Activity 不熟悉。如何在 Activity 上调用WordPuzzle?

Android Activity :

public class Puzzle extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

Java代码:
public class WordPuzzle {.....

  public Set<String> findWords(char[][] puzzle, Set<String> words) {.....

  private int findMinimumWordLength(Set<String> words) {.....

  private Set<String> findPossibleWords(char[][] puzzle, int minimumWordLength) {.....

  public void main(String args[]) {
            WordPuzzle program = new WordPuzzle();
            char[][] puzzle = {
                                {'F','Y','Y','H','N','R','D'},
                                {'R','L','J','C','I','N','U'},
                                {'A','A','W','A','A','H','R'},
                                {'N','T','K','L','P','N','E'},
                                {'C','I','L','F','S','A','P'},
                                {'E','O','G','O','T','P','N'},
                                {'H','P','O','L','A','N','D'}
                              };
            Set<String> words = new HashSet<String>();
            words.add("FRANCE");
            words.add("POLAND");
            words.add("JAPAN");
            words.add("HOLLAND");
            Set<String> wordsFound = program.findWords(puzzle, words);
            for(String word : wordsFound) {
                System.out.println(word);
            }
        }
    }
}

最佳答案

  public class Puzzle extends Activity {

     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            WordPuzzle wp = new WordPuzzle(); // you need to make main() a static function to avoid this
            String args[] = {""};
            wp.main(args);
  }

但我认为System.out.println()不会起作用,至少在用户可以查看的地方不起作用。
将layout.main更改为TextView,然后将输出放在此处

08-26 00:36