简体   繁体   English

Libgdx-如何在Eclipse中调试我的Libgdx项目?

[英]Libgdx - How do i Debug my Libgdx project in Eclipse?

As I'm currently ironing out the creases of my knowledge with Libgdx, Before I start a project, I feel like I should know how to debug specific 'standard' run time errors whilst debugging Android application(s). 由于我目前正在用Libgdx消除知识的不足,因此在开始项目之前,我觉得我应该知道在调试Android应用程序时如何调试特定的“标准”运行时错误。 It would save me a-lot of time pondering on why my application doesn't seem to run when loading the game. 这将使我节省大量时间来思考为什么在加载游戏时我的应用程序似乎无法运行。 The documentation is very scattered as for most Open-Source projects, but every coin has two sides; 与大多数开源项目一样,文档非常分散,但是每个硬币都有两个方面。 where Libgdx bathes in freedom of development, it lacks in documentation. Libgdx享有发展自由的地方,但缺乏文档。 The aim of this post is to answer the very simple, but beneficial question. 这篇文章的目的是回答一个非常简单但有益的问题。

How do I debug my Libgdx Project in Eclipse? 如何在Eclipse中调试Libgdx项目?

The answer to some may be very simple, but to others not so much but highly necessary. 对某些人的答案可能非常简单,但对其他人的答案则不是很多,但非常有必要。 I'm using Libgdx 1.5.5 and Eclipse 4.4 (Luna) for this. 我为此使用Libgdx 1.5.5和Eclipse 4.4(Luna)。

When you're in eclipse and your application crashes, you'll want to go over and jump into Debug perspective. 当您处于eclipse中并且应用程序崩溃时,您将需要跳过并跳至Debug透视图。

Window > Open Perspective > Debug 窗口>打开透视图>调试

Once there with a few simple clicks you should be able to get some information about the error you've found, the next time you run it. 只需单击几下鼠标,您就应该能够在下次运行该错误时获得有关已找到的错误的一些信息。 See image below: 见下图:

在此处输入图片说明

In my case, I've purposely used an old packed texture without the frames for one animation, so I know i'd get a NullPointerException. 就我而言,我特意使用了没有帧的旧打包纹理来制作一个动画,所以我知道我会得到一个NullPointerException。 This is a very common error and a good example to start with. 这是一个非常常见的错误,也是一个很好的例子。

Libgdx Android - GL Thread (NullPointerException) & Missing Class File Libgdx Android-GL线程(NullPointerException)和缺少类文件

Lets further break down the image: 让我们进一步分解图像:

  1. This is where you can analyze the threads and see how they're running when the application is going. 在这里您可以分析线程,并在应用程序运行时查看它们的运行方式。 It's essentially a timeline of the interactions the threads make throughout the application. 从本质上讲,这是线程在整个应用程序中进行交互的时间轴。 you can use this look for leaks and better to spot which thread your error occurs on, in the image it shows an error has been caught on the GL Thread. 您可以使用此外观查找泄漏,并更好地发现您的错误发生在哪个线程上,该图像显示GL线程中已捕获错误。 NullPointerException (as mentioned above). NullPointerException(如上所述)。

    if you wish to look deeper into the APIs way of threading, have a look here . 如果您想更深入地了解API的线程方式,请在此处查看

  2. This is where you'll be setting up your breakpoints, as you can see already from the image I've got mine setup. 在这里,您将设置断点,正如您从图像中已经看到的那样,您已经可以看到它。 This just shows you what area you'll be looking for in regards to the exceptions, in this case you'll be adding breakpoints to the GdxRuntimeException , this allows the system to stop debugging and display the problem when they catch an exception from the GdxRuntime family. 这只是显示您要在异常方面寻找的区域,在这种情况下,您将向GdxRuntimeException添加断点,这将使系统停止调试并在它们从GdxRuntime捕获异常时显示问题。家庭。

    more on breakpoints here . 更多关于断点的信息

    3 : http://www.vogella.com/tutorials/EclipseDebugging/article.html 3http : //www.vogella.com/tutorials/EclipseDebugging/article.html

    In order to set these up you'll need to click on the button right next to the 2 area of the image it looks almost like J! 为了进行设置,您需要单击图像2区域旁边的按钮,它看起来几乎像J! and when hovered over it'll say "add Java Exception Breakpoint", click on that and then 3 will pop up. 当鼠标悬停在它上面时,它会说“添加Java异常断点”,单击它,然后会弹出3

  3. This is the dialog box thats opens when you add a new Java Exception breakpoint, there will be numerous options and a search bar, time in Gdx into the search bar and you'll find GdxRuntimeException , click on that, click ok. 当您添加新的Java Exception断点时,这是打开的对话框,将有许多选项和一个搜索栏,将Gdx中的时间插入搜索栏中,您将找到GdxRuntimeException ,单击它,然后单击确定。 Now you have a breakpoint set for the 'standard' Gdx runtime exceptions. 现在,您已经为“标准” Gdx运行时异常设置了一个断点。 It'll make it alot easier to find errors in your code. 这将使查找代码中的错误变得更加容易。

  4. Logcat : The final clue in the puzzle to finding out where the error is. Logcat :找到错误所在的难题的最后线索。 This is Logcat, this will log any errors coming from the Android device, I normally filter the errors tab and concentrate on the red. 这是Logcat,它将记录来自Android设备的所有错误,我通常会过滤“错误”标签并集中显示红色。 You'll need to spend a little time getting to know what are 'common' errors and what are actual errors. 您需要花一些时间来了解什么是“常见”错误以及什么是实际错误。 Then you should be able to work out what the error is. 然后,您应该能够找出错误所在。 Obviously, fixing things is always trial and error [pun intended]. 显然,解决问题总是反复试验的。

    The logcat tells me that theres something wrong the Libgdx library that imports the TextureRegion and using that information with the threads we can see that somewhere a texture region is being passed over with a null value, with a bit of luck you'll be able to go straight to your Assets manager and get it sorted. logcat告诉我,导入TextureRegion的Libgdx库TextureRegion并在线程中使用了该信息,我们可以看到某个纹理区域正以空值传递,如果运气好的话,您将能够直接联系您的资产经理并进行排序。

Note : In the top left corner of the image, you'll notice how you can change perspectives (not sure how updated this in regards to what version of Eclipse has it) but it comes in very handy when you're doing the trial and error. 注意 :在图像的左上角,您会注意到如何更改视角(不确定如何更新该版本的Eclipse),但是在进行试用和调试时非常方便错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM