eclipse(android 开发)启动活动中的运行时错误:是否有办法在 Windows 中的 eclipse 中单步执行源代码?
我正在尝试在 Eclipse 中(在 Windows 中)制作 Android 游戏。当我在模拟器和手机上运行程序时,我不断收到 NullPointerExceptions 和 ClasscastExceptions。我有 2 个类(活动),每个类都有自己的 xml 布局。主要活动运行完美。但是,当我启动第二个活动时:
final Intent i = new Intent(this, Arrowscreen.class);
...
startActivity(i);
我收到了前面提到的异常。它总是指向未找到的源。 是否有办法在 Windows 中的 Eclipse 中单步执行源代码? 我已经查看了 http://source .android.com,但是windows好像没有解决办法。我尝试遵循 cygwin 的 linux 说明,但它似乎不起作用(如果可能的话,我更喜欢在 Windows 中工作)。
我对 Android 开发还是个新手,所以我可能错过了一些重要的东西。 这个清单声明有什么问题吗?:
<activity android:name=".Arrowscreen"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我不会发布我的整个代码示例,因为它很长,但我会告诉你它使用了加速度计、gps 和一个可运行的主程序在带有“postDelayed”的计时器上循环。 GPS 精确位置权限也在清单中。我被困住了,所以任何帮助将不胜感激。谢谢!
编辑:以下是我得到运行时异常的代码部分
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.arrow);
img=(ImageView)findViewById(R.id.ArrowBackground);
arrow1=(ImageView)findViewById(R.id.turningArrow);
GPSx=(TextView)findViewById(R.id.textView1);
GPSy=(TextView)findViewById(R.id.textView2);
MGNTx=(TextView)findViewById(R.id.textView3);
MGNTy=(TextView)findViewById(R.id.textView4);
angle = 0;
lastAngle = 0;
arrowAngle = 0;
mValues[0]=0; mValues[1]=0; mValues[2]=0;
//mStartTime = System.currentTimeMillis();
mHandler.removeCallbacks(UpdateArrow);
mHandler.postDelayed(UpdateArrow, 400);
I am trying to make an android game in eclipse (in windows). I keep getting nulpointerexceptions, and classcastexceptions when i run my program both on the emulator and on my phone. I have 2 classes(activities), each with their own xml layout. the main activity runs perfectly. However when I launch the second activity with:
final Intent i = new Intent(this, Arrowscreen.class);
...
startActivity(i);
I get the previously mentioned exceptions. It always points to the source, which is not found. Is there anyway to step through the source in eclipse in windows? I have looked at http://source.android.com, but there seems to be no solution for windows. I tried to follow the linux instructions from cygwin, but it doesn't seem to work(and i'd prefer to work in windows if possible).
I am still new to android development, so i may be missing something important. Is there anything wrong with this manifest declaration?:
<activity android:name=".Arrowscreen"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I will refrain from posting my whole code sample because it is lengthy, but i will tell you that it uses the accelerometer, gps, and a runnable for the main loop on a timer with "postDelayed". the gps fine location permission is in the manifest also. I am stuck, so any help would be much appreciated. Thanks!
edit: the following is the part of my code where i get the runtime exception
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.arrow);
img=(ImageView)findViewById(R.id.ArrowBackground);
arrow1=(ImageView)findViewById(R.id.turningArrow);
GPSx=(TextView)findViewById(R.id.textView1);
GPSy=(TextView)findViewById(R.id.textView2);
MGNTx=(TextView)findViewById(R.id.textView3);
MGNTy=(TextView)findViewById(R.id.textView4);
angle = 0;
lastAngle = 0;
arrowAngle = 0;
mValues[0]=0; mValues[1]=0; mValues[2]=0;
//mStartTime = System.currentTimeMillis();
mHandler.removeCallbacks(UpdateArrow);
mHandler.postDelayed(UpdateArrow, 400);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非我误解了你的问题...
在 Eclipse 中,在 Activity 中 onCreate 的第一行设置断点,并以调试模式启动应用程序(运行 -> 调试为 -> Android 应用程序)。
关于这样做的两篇博客文章:
1. http://www.droidnova.com/debugging-in -android-using-eclipse,541.html
2. http ://www.latenightpc.com/blog/archives/2007/11/21/starting-a-debug-session-for-android-with-adt
Unless I've misunderstood your question...
In Eclipse, set a breakpoint at the first line of onCreate in your Activity, and launch the app in debug mode (Run -> Degub As -> Android Application).
Two Blog posts on doing this:
1. http://www.droidnova.com/debugging-in-android-using-eclipse,541.html
2. http://www.latenightpc.com/blog/archives/2007/11/21/starting-a-debug-session-for-android-with-adt
检查您的“Arrowscreen”类是否扩展了“Activity”类,如果不是,请先这样做......
我认为这可能会有所帮助。
……
....
}
在 AndroidMainfest.xml
<意图过滤器>
<动作 android:name="android.intent.action.RUN" />
<类别 android:name="android.intent.category.LAUNCHER" />
Check out ur "Arrowscreen" class extends "Activity" class or not, if not first do that...
I think this may help.
.....
....
}
in AndroidMainfest.xml
<activity android:name="Arrowscreen"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>