Java(maven):如何知道错误的位置(无用的回溯)(Java (maven) : how to know where lies the error (useless backtrace))
我正在用maven编写我的第一个项目( 这里 )。 当我使用
mvn -Dtest=EchoTest test
运行mvn -Dtest=EchoTest test
,我得到了一个BUILD FAILUREnonAcceptedTypeVerification(EchoTest) Time elapsed: 0.044 sec <<< ERROR! java.lang.NullPointerException at EchoTest.initialize(EchoTest.java:50)
我怎样才能更准确地知道代码中的哪一行触发
NullPointerExcepion
? 换句话说:如何让Maven打印整个回溯?我尝试了
mvn -e
,并在target
子目录中搜索。编辑
以下是引发NullPointerException的行(在EchoText.java中):
@Before public void initialize() throws InterruptedException { system = new EchoActorSystem(); echo_actor = system.actorOf(); <-- line 50 }
关键是
EchoActorSystem
是一个非常复杂的类,方法actorOf
做了很多工作,从system
调用许多函数。 例如,它调用super.actorOf()
然后修复结果的某些属性,依此类推。 我通过添加许多Sysytem.out.println
搜索错误的行,但我确信这不是正确的工作方式。I'm writing my first project with maven (here). When I run the tests with
mvn -Dtest=EchoTest test
, I get a BUILD FAILURE withnonAcceptedTypeVerification(EchoTest) Time elapsed: 0.044 sec <<< ERROR! java.lang.NullPointerException at EchoTest.initialize(EchoTest.java:50)
How can I know more precisely what line in my code triggers the
NullPointerExcepion
? In other words : how to ask Maven to print the whole backtrace ?I tried
mvn -e
, and searched in thetarget
subdirectory.EDIT
Here are the lines provoking the NullPointerException (in EchoText.java) :
@Before public void initialize() throws InterruptedException { system = new EchoActorSystem(); echo_actor = system.actorOf(); <-- line 50 }
The point is that
EchoActorSystem
is a quite complex class and the methodactorOf
makes tons of work, calling many functions fromsystem
. For example it callssuper.actorOf()
and then fix some properties of the result, and so on. I'm searching the faulty line by adding manySysytem.out.println
, but I'm sure that this is not the right way to work.
原文:https://stackoverflow.com/questions/35506936
最满意答案
character
是一种不应该使用的糟糕数据类型。 这只是其中一个原因。 请参阅字符类型 - postgresql手册 。将这些字段更改为
text
或varchar(n)
。 对需要一个长度的check
约束的text
通常是最佳选择。ALTER TABLE thetable ALTER COLUMN colname TYPE text;
顺便说一下,如果你发布SQL并且 - 最好是在
psql
中运行该SQL的输出,它会更容易回答你的问题,这会产生可复制和粘贴的纯文本输出。
character
is an awful data type that should not be used. This is just one of the reasons. See character types - postgresql manual.Change those fields to
text
or tovarchar(n)
.text
with acheck
constraint on length where one is required is usually the best option.ALTER TABLE thetable ALTER COLUMN colname TYPE text;
BTW, it's easier to answer your questions if you post the SQL and - preferably - the output of running that SQL in
psql
, which produces copy-and-pasteable plain text output.
相关问答
更多-
问题是,为什么要阻止此表的其他插入? 对我来说,看起来你想确保同一个tableID没有相交的间隔。 您可能在Java代码中检查了这一点,并且您不希望其他插入干扰检查。 如果是这样,则根本不需要锁定:使用EXCLUDE约束。 为此,您需要: 将两个timestamp字段更改为一个tsrange字段。 安装btree_gist扩展名(它包含在contribs中)。 你的表格如下: CREATE TABLE IF NOT EXISTS bookings ( bookingID SERIAL PRIMARY ...
-
如何在PostgreSQL中的字段中找到2个字符之间的值(How to find the value between 2 characters within a field in PostgreSQL)[2023-02-21]
怎么样 select regexp_replace(name, ' ".+?"$', '') FirstName, substring(name from '"(.+?)"') NickName from names http://sqlfiddle.com/#!15/6728f/1 How about select regexp_replace(name, ' ".+?"$', '') FirstName, substring(name from '"(.+?)"') NickName from nam ... -
Rails和Postgresql创建一个自动从1递增的字段(Rails & Postgresql create a field that auto increments from 1)[2022-04-30]
据我所知,你想要一个基于主要ID的二级身份证? 身份密钥只能基于表,不能依赖于另一个密钥。 您必须在代码中执行此操作,然后将其保存到before_create上的新字段中。 最简单的方法是,对于您想要id的每个订单,根据主键是否获得小于或等于您正在使用的订单的所有订单的计数。 它是一个简单的查询计算。 From what I can tell, you want a secondary id based on the primary id? The identity key can only be tabl ... -
考虑到您可以直接从Interface Builder为任何给定的文本字段设置大写设置为“Word”(因此甚至不需要代码!),或者如果您的iOS开发人员正在向您收费,则使用一行代码(如果它是自动创建的)对于这次升级,那么你就被扯掉了。 - 编辑:如果您想知道,代码将类似于以下内容.-- [bookTitleField setAutocapitalizationType:UITextAutocapitalizationTypeWords]; Considering that you can set the c ...
-
Cocoa:停止字段编辑器自动完成空格键(Cocoa: Stopping the field editor from auto-completing on space key)[2022-10-31]
我承认,在我通过Google-fu发现一个可接受的答案之前, 我已经提前一段时间摸索了这个问题。 从原始回答者那里公然偷走了魔法代码: @interface MLFieldEditor : NSTextView @end @implementation MLFieldEditor - (void)insertCompletion:(NSString *)word forPartialWordRange:(NSRange)charRange movement:(NSInteger)movement i ... -
如何使用postgresql无限制字符解析字符串字段(How to parse string field with unlimited characters postgresql)[2022-04-22]
您可以使用substring()函数。 它会是这样的: select substring(col from 'R4.([0-9.]+) ') You can use the substring() function. It would be something like this: select substring(col from 'R4.([0-9.]+) ') -
我怀疑你想要update ,而不是insert : UPDATE generic.spa SET spa_cos_zenith = cos(radians(spa.spa_zenithangle)); INSERT插入新行,因此您要复制行。 新行中唯一的列是COS()值。 旧行中没有任何变化。 I suspect you want update, not insert: UPDATE generic.spa SET spa_cos_zenith = cos(radians(spa.spa_ ...
-
Postgresql函数自动将's'字符添加到字符串的末尾(Postgresql function auto add 's' character to the end of string)[2022-04-19]
正如手册解释: 代替: RAISE NOTICE 'WHAT IN HERE: query %s', _qry; 你需要使用: RAISE NOTICE 'WHAT IN HERE: query %', _qry; RAISE语句的占位符没有“类型修饰符”,它是一个普通的% As the manual explains: instead of: RAISE NOTICE 'WHAT IN HERE: query %s', _qry; you need to use: RAISE NOTICE 'WHA ... -
我的PostgreSQL自动在字段值后插入许多空格字符(My PostgreSQL auto inserts many space characters after the value of a field)[2022-07-27]
character是一种不应该使用的糟糕数据类型。 这只是其中一个原因。 请参阅字符类型 - postgresql手册 。 将这些字段更改为text或varchar(n) 。 对需要一个长度的check约束的text通常是最佳选择。 ALTER TABLE thetable ALTER COLUMN colname TYPE text; 顺便说一下,如果你发布SQL并且 - 最好是在psql中运行该SQL的输出,它会更容易回答你的问题,这会产生可复制和粘贴的纯文本输出。 character is an a ... -
PostgreSQL插入问号而不是unicode字符(PostgreSQL inserts question marks instead of unicode characters)[2022-05-25]
在深入研究遗留代码后,我发现并解决了问题。 数据库层运行得很好; 当系统尝试使用ByteArrayInputStream将相同的值重新插入数据库时发生此问题。 通过在包含foo_name的String中执行getBytes()来填充ByteArrayInputStream。 但是,在调用此方法时应定义UTF-8编码。 通过更改: String name = "日本語"; InputStream is = new ByteArrayInputStream(name.getBytes()); 至: Strin ...