乳宁在Android标准的Java code [英] Runing a standard Java code on Android
本文介绍了乳宁在Android标准的Java code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要运行在Android上我的Java code。但我不熟悉Activites。我怎么能叫WordPuzzle上的活动?
Android的活动:
公共类益智延伸活动{
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
}
Java的code:
公共类WordPuzzle {.....
公共设置<字符串> findWords(的char [] []谜题,设置<字符串>的话){.....
私人诠释findMinimumWordLength(集<字符串>的话){.....
私人设置<字符串> findPossibleWords(的char [] []拼图,诠释minimumWordLength){.....
公共无效的主要(字串的args []){
WordPuzzle程序=新WordPuzzle();
的char [] []拼图= {
{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'}
};
设置<字符串>字=新的HashSet<字符串>();
words.add(FRANCE);
words.add(波兰);
words.add(JAPAN);
words.add(荷兰);
设置<字符串> wordsFound = program.findWords(拼图,字);
对(串词:wordsFound){
的System.out.println(字);
}
}
}
}
解决方案
公共类益智延伸活动{
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
WordPuzzle WP =新WordPuzzle(); //你需要做的main()静态函数来避免这个
字符串的args [] = {};
wp.main(参数);
}
但我不认为的System.out.println()
将工作,至少不会在这里用户可以查看它。
更改layout.main到的TextView
,并把你的输出有可能
I want to run my Java code on Android. But I'm not familiar with Activites. How can I call WordPuzzle on an Activity?
Android activity:
public class Puzzle extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
Java code:
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);
}
but i dont think System.out.println()
will work, at least not where the user could view it.
Change layout.main to a TextView
and put your output there maybe
这篇关于乳宁在Android标准的Java code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文