Matcher throws IllegalStateException after accessing group

I'm trying to write simple command parser class for my project. Here's what I have: Main.java public static void main(String[] args) { CmdParser p = new CmdParser(args); String st = p.getSourceType(); } CmdParser.java import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CmdParser { private String[] args; public Cm

Matcher在访问组之后抛出IllegalStateException

我正在为我的项目编写简单的命令解析器类。 以下是我的: Main.java public static void main(String[] args) { CmdParser p = new CmdParser(args); String st = p.getSourceType(); } CmdParser.java import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CmdParser { private String[] args; public CmdParser(String[] args) { this.

Mockito: List Matchers with generics

Mockito offers: when(mock.process(Matchers.any(List.class))); How to avoid warning if process takes a List<Bar> instead? For Java 8 and above, it's easy: when(mock.process(Matchers.anyList())); For Java 7 and below, the compiler needs a bit of help. Use anyListOf(Class<T> clazz) : when(mock.process(Matchers.anyListOf(Bar.class))); In addition to anyListOf above, you can a

Mockito:列出泛型的匹配器

Mockito提供: when(mock.process(Matchers.any(List.class))); 如果process取而代之的是List<Bar>如何避免警告? 对于Java 8及更高版本,这很容易: when(mock.process(Matchers.anyList())); 对于Java 7及更低版本,编译器需要一些帮助。 使用anyListOf(Class<T> clazz) : when(mock.process(Matchers.anyListOf(Bar.class))); 除了上面的anyListOf之外,您始终可以使用以下语法显式指定泛型: when(moc

ListView Items' background get mixed up when scrolling listView

I'm trying to change the background of a specific item in the list view titled "Different Item". As I scroll down the list, all the items' backgrounds are correct. When I reach the end of the list (where "Different Item" is), and scroll back up, there are some random items that get the same background as "Different Item". I believe this is due to the view

滚动listView时,ListView Items的背景会混淆

我试图改变标题为“不同项目”的列表视图中特定项目的背景。 当我向下滚动列表时,所有项目的背景都是正确的。 当我到达列表的末尾(“不同项目”所在的位置),并向上滚动时,会有一些随机项目获得与“其他项目”相同的背景。 我相信这是由于我使用的视图持有者模式,以及android再次使用每个视图再次使用的事实,但我不太了解这个问题以及如何解决它。 这是我的MainActivity.java import android.support.v7.app.AppCompatActivi

Insert a single view inside a listview makes listItem non clickable

I am inflating a view inside a list item on listItemClick .The list item contains a check box. When the check box is clicked a linear layout containing two/three edit text fields and buttons gets inflated to that list view ( done by getView method of cursor adapter, the inflating view is dynamically created ) . the list view is registered with on item click listener . After the layout being i

在listview中插入单个视图使listItem不可点击

我在listItemClick上的列表项内部放大视图。列表项包含一个复选框。 单击复选框时,包含两个/三个编辑文本字段和按钮的线性布局会被充气到该列表视图(通过游标适配器的getView方法完成,动态创建充气视图)。 列表视图在项目点击侦听器上注册。 在布局被充气后,onItemClick监听器不会被调用特定的项目。 帮我 我的getView代码 TextView text1 = (TextView) view.findViewById (R.id.text); text1.setText("tex

Where will code stop running when app is killed from task manager on Android

If a user is running my app and decides to kill it via the task manager, are there any guarantees about how much code will be executed before the process dies? I feel like it could stop running at any arbitrary line, however I guess I don't really know the answer to this. An example use case is for stopping and restarting a background alarm. If I wanted to cancel an alarm, do some work,

在Android上的任务管理器中杀死应用程序时代码停止运行的位置

如果用户正在运行我的应用程序并决定通过任务管理器终止它,是否有任何有关在进程死亡之前将执行多少代码的保证? 我觉得它可以停止在任何任意线路上运行,但是我想我并不真的知道这个答案。 一个示例用例是停止并重新启动后台警报。 如果我想取消闹钟,做一些工作,然后重置闹钟,我觉得应用可能会在“取消闹钟”步骤之后但在“重置闹钟”步骤之前停止运行。 这会让我处于一种我不想进入的状态,因为我总是希望我的闹钟能够在

How do I parse command line arguments in Java?

在Java中解析命令行参数的好方法是什么? Check these out: http://commons.apache.org/cli/ http://www.martiansoftware.com/jsap/ Or roll your own: http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html For instance, this is how you use commons-cli to parse 2 string arguments: import org.apache.commons.cli.*; public class Main { public static void main(String[] args) throws E

如何解析Java中的命令行参数?

在Java中解析命令行参数的好方法是什么? 检查这些: http://commons.apache.org/cli/ http://www.martiansoftware.com/jsap/ 或者推出自己的: http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html 例如,这是你如何使用commons-cli来解析2个字符串参数: import org.apache.commons.cli.*; public class Main { public static void main(String[] args) throws Exception { Options o

How to find an available port?

I want to start a server which listen to a port. I can specify port explicitly and it works. But I would like to find a port in an automatic way. In this respect I have two questions. In which range of port numbers should I search for? (I used ports 12345, 12346, and 12347 and it was fine). How can I find out if a given port is not occupied by another software? If you don't mind the

如何找到一个可用的端口?

我想启动一个监听端口的服务器。 我可以明确指定端口并且它可以工作。 但我想自动找到一个端口。 在这方面我有两个问题。 我应该搜索哪些端口号码范围? (我用端口12345,12346和12347,这很好)。 我如何知道给定的端口是否未被其他软件占用? 如果您不介意使用的端口,请将ServerSocket构造函数的端口指定为0,并且它将侦听任何空闲端口。 ServerSocket s = new ServerSocket(0); System.out.println("listening on

version showing different versions

I have java 7 and java 8 both installed on my windows system under C:Program FilesJava In the environment's path I specified the path of java 7 like this. %JAVA_HOME%/bin where JAVA_HOME = C:Program FilesJavajdk1.7.0_17 But when I type javac -version it shows javac 1.7.0_17 which makes sense but when I do java -version it shows java version "1.8.0" Java(TM) SE Runtime Environment (bu

版本显示不同的版本

我在Windows系统下安装了C:Program FilesJava下的java 7和java 8 在环境的路径中,我这样指定了java 7的路径。 %JAVA_HOME%/bin其中JAVA_HOME = C:Program FilesJavajdk1.7.0_17 但是当我键入javac -version它显示了javac 1.7.0_17 ,这是有道理的 但是当我做java -version显示 java version "1.8.0" Java(TM) SE Runtime Environment (build 1.8.0-b132) Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mod

unix "which java" equivalent command on windows?

Possible Duplicate: Is there an equivalent of 'which' on windows? Failed to find it on Google, but just wondering if there is a way to reveal location of java by an equivalent command from Windows prompt. Basically I have info from client that he doesn't set the JAVA_HOME but still can run java programs. I suspect it then must because the path to that java is set in the system

Unix的“哪些Java”等效命令在Windows上?

可能重复: 是否有相当于Windows上的“哪个”? 无法在Google上找到它,但只是想知道是否有方法通过Windows提示符下的等效命令来显示java的位置。 基本上我有来自客户端的信息,他没有设置JAVA_HOME,但仍然可以运行Java程序。 我怀疑它一定是因为这个java的路径被设置在系统PATH环境变量中,但是这太快而无法快速迭代,也是非常痛苦的(必须挖掘到子文件夹)。 预先感谢您的任何建议! 你可以试试: c:> for %i in

Composite Views & Composite Presenters

I found M. Fowler article on Passive View pattern. I would like to apply it in my application. I use Swing for UI. I spent several hours searching tutorials or examples how to implement it but not much useful found. Could anybody help to understand the design or provide good examples here? By "M" in MVP I understand "Domain Model". MVP = Model View Presenter The basic

复合视图和复合演示文稿

我在被动视图模式中找到M. Fowler的文章。 我想申请它在我的申请。 我使用Swing进行UI。 我花了几个小时搜索教程或例子如何实现它,但没有发现太多有用的东西。 任何人都可以帮助理解设计或在这里提供很好的例子吗? MVP中的“M”我理解“域模型”。 MVP =模型视图演示者 基本的想法是,你将UI的呈现逻辑与视图分开,所以你可以用简单的JUnit测试来模拟视图并测试演示者,而不是用你的“视图逻辑”来混淆swing(可能由设计者