Get the command line arguments in NetBeans 7.1.2 - netbeans

I am using NetBeans 7.1.2. My error is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at javaapplication1.JavaApplication1.main(JavaApplication1.java:17)
Java Result: 1
My program is:
package javaapplication1;
/**
*
* #author Administrator
*/
public class JavaApplication1 {
/**
* #param args the command line arguments
*/
public static void main(String[] ar) {
int a=Integer.parseInt(ar[1]);
System.out.println(a);
// TODO: Code application logic here
}
}

FYI, the first parameter is ar[0], for example in the command line below ar[0] is "123":
java JavaApplication1 123
See this web page for more information on Java command-line arguments.

Related

Extend repository in TYPO3 9.5 LTS / Extbase

I'm trying to extend this IndexRepository to add my own method for a special search.
In the controller I inject my own IndexRepository with:
use Webian\Iancalendar\Domain\Repository\IndexRepository;
/**
* Inject index repository.
*
* #param IndexRepository $indexRepository
*/
public function injectIndexRepository(IndexRepository $indexRepository)
{
$this->indexRepository = $indexRepository;
}
What I did is working but I get this warning:
PHP Warning
Core: Error handler (BE): PHP Warning: Declaration of Webian\Iancalendar\Controller\
BackendController::injectIndexRepository(Webian\Iancalendar\Domain\Repository\IndexRepository $indexRepository)
should be compatible with HDNET\Calendarize\Controller\
AbstractController::injectIndexRepository(HDNET\Calendarize\Domain\Repository\IndexRepository $indexRepository)
in /typo3conf/ext/iancalendar/Classes/Controller/BackendController.php line 42
That's because I'm using my own Webian\Iancalendar\Domain\Repository\IndexRepository that extends HDNET\Calendarize\Domain\Repository\IndexRepository. If I use the original one the warning doesn't appear but obviously my own method is not called.
How can I avoid that warning?
You should either not extend HDNET\Calendarize\Controller\AbstractController but the default AbstractController of Extbase, then you will need to implement all required logic yourself.
Or you just use a different name for your injection method:
use HDNET\Calendarize\Controller\AbstractController;
use MyNamespace\MyExtension\Domain\Repository\IndexRepository;
class MyController extends AbstractController
{
...
/**
* The index repository.
*
* #var IndexRepository
*/
protected $myIndexRepository;
/**
* Inject index repository.
*
* #param IndexRepository $myIndexRepository
*/
public function injectMyIndexRepository(IndexRepository $myIndexRepository)
{
$this->myIndexRepository = $myIndexRepository;
}
...
class IndexRepository extends \HDNET\Calendarize\Domain\Repository\IndexRepository
{
...
// My method that extends \HDNET\Calendarize\Domain\Repository\IndexRepository functionalities
public function findByStartDate(DateTime $startDate = null, DateTime $endDate = null)
{
...
The method name does not really matter, only that it starts with inject and has a type hint indicating the dependency to inject.

Netbeans Example App does not have main Method

The code below was generated by netbeans. When I right click it there is an error that it does not have a main method. What should I do? It is on xubuntu using netbeans IDE 10 JDK 11 . I created the app using netbeans.org/kb/docs/java/quickstart.html. I right click HelloWorldApp.java and choose run. then I get the error .Error screenshot
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package helloworldapp;
/**
*
* #author peter
*/
public class HelloWorldApp {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

Java Program output printed in random position in Eclipse console

I have a JUnit class in Eclipse project. It is like the following:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*some other imports*/
public class _JunitTests{
final Logger logger = LoggerFactory.getLogger(_JunitTests.class);
public void test(int num){
logger.info("**** tests no."+num+" ***");
/* some code */
}
#Test
public static void test1() {
test(1);
}
#Test
public static void test2() {
test(2);
}
#Test
public static void test3() {
test(3);
}
#Test
public static void test1() {
test(1);
}
}
When I run all the tests, I was expecting output such as[class information of info is ignored]
**** tests no.1 ***
/* somethings */
**** tests no.2 ***
/* somethings */
**** tests no.3 ***
/* somethings */
However, the result shown in console is usually messed up like:
**** tests no.1 ***
**** tests no.2 ***
**** tests
/* somethings */
no.3 ***
/* somethings */
/* somethings */
This happens a lot before with my other codes when there are Exception messages.
My guess before is stderr and stdout are handled in different threads, and so the result would be displayed without a certain order.
Since the info from Logger is also red in Eclipse console, my guess is that it uses stderr to display the message? is it the case? if so, is there a way to solve the problem of messed up order? thanks.
Which logging framework do you use with SLF4J? It could be that the logging framework is configured to write the log messages asynchronously in a background thread.
You can try to replace the log call with a System.out.println() and see if that produces the output you expect. If it does you may want to reconfigure the logging framework to log the messages synchronously.

NetBeans PHPUnit test generation ignoring #assert annotation

I have an abstract class where source code looks like this:
/*
* #assert (0) == NULL
*/
public static function factory($num) {
if ($num==0)
return NULL;
//do some other stuff
}
If I delete the previously generated test file and use the "Create PHPUnit tests", it creates a new unit test file that doesn't seem to have taken the assert into account at all:
/**
* #covers {className}::{origMethodName}
* #todo Implement testFactory().
*/
public function testFactory() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
I must be doing something silly, but I can't figure out what. Is the failure to expand the class name and method name in the generated #covers annotation perhaps a clue?
I'm running NetBeans 7.0.1 on a Mac with PHP 5.3.6 and PHPUnit 3.6.2.
All annotations must appear in DocBlock comments which start with /** and not /*. You're missing an asterisk.
/**
* #assert (0) == NULL
*/
public static function factory($num) {

How to use the JFace FileDialog from within an Eclipse plugin in a modeless way?

I am writing an Eclipse plugin, and in response to some action I am interesting in starting a series of operations (within a separate job). One of these operations is to request the user to provide a filename, which I'm trying to do with the JFace JDialog.
However, I'm not clear how to do this in a modeless way; for example, where do I obtain a display and shell? How do I ensure the UI continues to work while the developer can edit stuff in the dialog?
May be you could see how Eclipse itself does it:
FindAndReplaceDialog.java
/**
* Creates a new dialog with the given shell as parent.
* #param parentShell the parent shell
*/
public FindReplaceDialog(Shell parentShell) {
super(parentShell);
fParentShell= null;
[...]
readConfiguration();
setShellStyle(SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE | SWT.RESIZE);
setBlockOnOpen(false);
}
/**
* Returns this dialog's parent shell.
* #return the dialog's parent shell
*/
public Shell getParentShell() {
return super.getParentShell();
}
/**
* Sets the parent shell of this dialog to be the given shell.
*
* #param shell the new parent shell
*/
public void setParentShell(Shell shell) {
if (shell != fParentShell) {
if (fParentShell != null)
fParentShell.removeShellListener(fActivationListener);
fParentShell= shell;
fParentShell.addShellListener(fActivationListener);
}
fActiveShell= shell;
}
It does manage its parent shell depending on the focus of the Dialog.
/**
* Updates the find replace dialog on activation changes.
*/
class ActivationListener extends ShellAdapter {
/*
* #see ShellListener#shellActivated(ShellEvent)
*/
public void shellActivated(ShellEvent e) {
fActiveShell= (Shell)e.widget;
updateButtonState();
if (fGiveFocusToFindField && getShell() == fActiveShell &&
okToUse(fFindField))
fFindField.setFocus();
}
/*
* #see ShellListener#shellDeactivated(ShellEvent)
*/
public void shellDeactivated(ShellEvent e) {
fGiveFocusToFindField= false;
storeSettings();
[...]
fActiveShell= null;
updateButtonState();
}
}
A ShellAdapter is provides default implementations for the methods described by the ShellListener interface, which provides methods that deal with changes in state of Shell.
The importent thing is that the style value should include SWT.MODELESS.
The style is one of the most important things in SWT you should look at, because you can control and initialize a lot only because of the styel value.