如何运行一个Android Activity类的主要方法是什么? [英] How to run the main method of an Android Activity class?
问题描述
我想通过中执行它来检查一个 Android的活动的私有方法活动的的公共静态无效的主要(字串[] args)的这是我创建的方法。
I'd would like to examine a private method of an Android Activity by executing it within the Activity's public static void main(String[] args) method which I created.
我使用的Eclipse ADT 和我运行的活动的一个 Java应用程序的幼稚的做法导致:
I use Eclipse ADT and my naive approach of running the Activity as a Java application resulted in:
已经由Java运行时环境检测到一个致命错误:结果
内部错误(classFileParser.cpp:3174),PID = 2936,TID = 2980结果
错误:ShouldNotReachHere()
A fatal error has been detected by the Java Runtime Environment:
Internal Error (classFileParser.cpp:3174), pid=2936, tid=2980
Error: ShouldNotReachHere()
所以,我看着在运行配置并发现了的Android 3.1 是唯一的入口在引导条目部分的类路径。我设法配置的构建路径的项目,以便在 JRE 在引导条目过。然后,我删除了的Android 3.1 项,并添加的android.jar 到用户条目
So I looked at the Run Configuration and found out that Android 3.1 is the sole entry in the Bootstrap Entries section of Classpath. I managed to configure the Build Path of the project so that the JRE is in the Bootstrap Entries too. Then I removed the Android 3.1 entry and added android.jar to User Entries.
执行的结果在运行配置是一个RuntimeException:
The result of executing the Run Configuration is a RuntimeException:
在异常线程主了java.lang.RuntimeException:存根结果!
在android.content.Context(Context.java:4)
Exception in thread "main" java.lang.RuntimeException: Stub!
at android.content.Context.(Context.java:4)
另一种执行一些测试将启动一个的JUnit 的考验。但是,在一个私有方法的情况下这是麻烦的。
An alternative of executing some tests would be to fire up a JUnit test. But in the case of a private method this is cumbersome.
有没有办法成功运行一个Android Activity类的主要方法是什么?
Is there a way to successfully run the main method of an Android Activity class?
推荐答案
目前手头的问题的另一种选择,如果私人
法 - 这应该通过审查主要方法的执行 - 可提取到另一个类。当然,这意味着,该方法突然变得至少保护
。
There is another option for the problem at hand, if the private
method - which should be examined through the execution of a main method - can be extracted to another class. This of course means that the method suddenly became at least protected
.
但是,如果该方法是在不脱离机器人派生类内definded。 app.Activity 一个主要方法可以定义。你只需要调整的运行配置在Eclipse。
But if the method is definded within a class that does not derive from android.app.Activity a main method can be defined. You only have to adjust the Run Configuration in Eclipse.
- 运行是运行的Java应用程序的类。这将生成一个名为像类的新运行配置
- 编辑新creaded运行配置
- 删除的Android 从库中的引导条目在类路径标签
- 添加JRE 6左右到项目的构建路径
- 此JRE添加到引导条目在类路径标签
- 添加的android.jar ,它驻留在平台的目录中的 Android SDK中在用户条目 在类路径标签
- Run the class with Run as Java Application. This generates a new Run Configuration named like the class
- Edit the newly creaded Run Configuration
- Delete the Android library from Bootstrap Entries in the Classpath tab
- Add JRE 6 or so to the build path of the project
- Add this JRE to the Bootstrap Entries in the Classpath tab
- Add android.jar, which resides in the platforms directory of the Android SDK in User Entries in the Classpath tab
这篇关于如何运行一个Android Activity类的主要方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!