Running A Test With A File?
Jun 11, 2014
I just wrote a java program with eclipse that has to read many-many inputs from the user. I want to test it, but I really don't want to type it everytime again and again...
Can I just write all inputs in a text file and let eclipse read this file so instead of typing it again and again, Eclipse reads every line whenever it waits for a user input?
View Replies
ADVERTISEMENT
Nov 6, 2014
We've got a java web app (running on a Solaris machine with Weblogic) and from time to time it stops working due to this error:
Java Code: java.net.SocketException: Too many open files mh_sh_highlight_all('java');
For what I've read we are somehow exceeding the established limit of file descriptors, and it seems that this may be caused for many reasons, not only open files that we forgot to close.
I am making a list of everything that may consume a file descriptor in the system mentioned above, so I can start reanalyzing the app... if needed, as I don't know if we're wasting them or if the limit is just insufficient.
View Replies
View Related
May 19, 2014
This is my program: RemoteXMLRead.java
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.apache.commons.io.filefilter.WildcardFileFilte r;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
[code]....
It is working fine when i run in Eclipse, but is giving error when i run in cmd.. What i need to do to over come this..
View Replies
View Related
Apr 16, 2015
I am working on a management gui for a program. I have implemented the start server button. But now I need to get something working so that when I press stop server the javaw.exe process which is running the the other jar file is stopped and ended.
The gui is going to be using a javaw.exe as well and I don't want to end the entire thing.
I just want to end the javaw.exe process that is running the other jar file.
This is my code for starting it:
JButton btnNewButton_2 = new JButton("Start Server");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Runtime rt = Runtime.getRuntime();
try {
Process pr = rt.exec("java -jar DEDServer_release.jar");
[Code] ....
I just need to figure out what to do to stop it now.
View Replies
View Related
Apr 24, 2014
import acm.util.* ;
import acm.program.*;
import java.awt.* ;
class Chap6_ex1 extends ConsoleProgram {
public void run() {
println("This program displays a randomly schosen card.");
int number = rgen.nextInt(1 ,13);
int suit = rgen.nextInt(1 ,4);
[Code] ....
I am running the this from a Linux command line , in the cmd first i use :
javac -classpath acm.jar Chap6_ex1.java
end then :
java -cp .:acm.jar Chap6_ex1
The output i m getting after second command is :
Exception in thread "main" acm.util.ErrorException: Cannot determine the main class.
at acm.program.Program.main(Program.java:1358)
I know the problem is from the RandomGenerator class in packet acm.util.* but i dont know how to fix the problem . Every other program has worked . What I am missing or how this whole issue of packet importing works when running a java file from cmd ?
View Replies
View Related
May 22, 2014
I'm running a jar of an application and library jars from lwjgl. I'm creating a java process. It's working on Windows but not on linux.
I tried replacing the semicolons with colons but it didn't work, it just said "Main class not found: Application.natives.linux" or something like that. gamePath is the path the application is in. osName is the name of the operating system.
Here's my code:
String jarRunner = String.format("java -Djava.library.path="%snatives/" + osName + "" -cp "%sjar/lwjgl.jar;%sjar/lwjgl_util.jar;%sjar/jinput.jar;%sjar/slick.jar;%sApplication.jar" main.Main", gamePath, gamePath, gamePath, gamePath, gamePath, gamePath);
Process p = Runtime.getRuntime().exec(jarRunner);
[Code] ....
How can I make it work on linux?
View Replies
View Related
Oct 14, 2014
So this is probably pretty simple but I can't seem to figure it out. My teacher wants us to write a code that scans a text file, then outputs some text based information AND displays an applet bar graph of the data sorta like this for the text:
Sample Bar Graph
1-10 |*****
11-20 |******
21-30 |**
31-40 |*
41-50 |***********
51-60 |******
61-70 |********
71-80 |***
81-90 |****
91-100 |****
and then an applet thats the same info just a little more graphic. My code interprets the input well, but when i try to make an applet output, the code basically forgets all of my variables and starts anew (when i just state the public static graphic (paint) class after everything) OR it refuses to scan the input file (if i switch the public class from main.....throw ExceptionIO to just public class graphic(paint))
Also, as a side note, any way to have java automatically determine how many separate lines there are in a text file without me having to manually count them.
import java.util.Scanner;
import javax.swing.JApplet;
import java.awt.*;
import java.io.*;
public class Project2 extends JApplet {
[Code] ....
View Replies
View Related
Jul 10, 2014
I'm trying to run a command line executable file using java but there is no output. On the task manager a conhost process opens when the application is run. I've tried
1)try {
Runtime.getRuntime().exec("D: est.exe");
} catch (Exception e) {
e.printStackTrace();
}
2)String[] cmd = { "D: est.exe"};
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
and
3)//Runtime.getRuntime().exec("D: est.exe", null, new File("D:"));
same thing happens i.e. nothing happens.
View Replies
View Related
Feb 17, 2015
I have JUnit exposure only in writing simple programs. Here I have one of the usecases requirement pupose I am generating data file(s) by Java programming and calling this data by Hashmap. My file containing two columns
(1) TimeStamp
(2) Speed.
The file is tab formatted file. The business requirement is to check wether the first column should not be 00000000000000 or NULL or BLANK. My question is, how do I check the first field in a file contaning valid information in Junit test case?
Sample File: ( - tab delimited)
1421103602000 542
0000000000000 989
<NULL> 000
1421103603000 588
1421103604000 700
Unfortunately, I am unable to send my Java code here, It was giving some error while attaching in this thread.
View Replies
View Related
Feb 27, 2014
I have a program that is a XML-parser, and it works fine when I'm running it from NetBeans. But when I create a JAR-file and run the very same program, it cannot find the xml file. Consider this small program that addresses my problem:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
[Code] .....
View Replies
View Related
Nov 27, 2013
I have followed the Java tutorial on JAAS Authentication and Authorization. All the sample code in the tutorials works fine also when running under a security manager. Now I am trying to modify the LoginModule class, so that it uses a password file to look up users and passwords, but as soon as I try to run the code under a security manager, I get a Security Exception. I suppose it has something to do with the code havent been granted any access to read the password file? So I tried to add this to the policy file:
grant codebase "file:./sample/module/-" {
permission java.io.FilePermission "sample/module/passwords.txt", "read";
};
It didn't do any difference. why I get this Security Exception?
The only difference from my code to the tutorial code, is that I have added the lines:
Scanner scanner = null;
try {
scanner = new Scanner(new File("src/sample/module/passwords.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
to the login() method of the SampleLoginModule class...
View Replies
View Related
Oct 1, 2014
I have style sheet file (e.g. myStyle.xslt). I am trying to decide where to put this file in my web application so that both src and test can access it. All my source in packages inside /src folder and test code in packages inside /test folder.
View Replies
View Related
May 3, 2015
This is a program that prompts a menu using the do-while iteration. If user input is not valid, the menu should be reprompted once. But when I run the code and enter an invalid value, the menu is prompted 3 times.
class Menu {
public static void main(String args[])
throws java.io.IOException {
char choice;
do {
[code]....
View Replies
View Related
Aug 3, 2014
I want to test that a function has no any exceptions.In C++ and Google Test Framework (GTest) it will look like this:
ASSERT_NO_THROW({
actual = divide(a, b);
});
How will it look in Java?
View Replies
View Related
Jun 11, 2014
I would like to test whether the first word in a line is is a valid var name (e.g sequence of letters, digits and "_", it may not start with a digit, if "_" is the first char it must be followed by a letter). I tried this simple code:
String namePattern = "_[a-zA-Z0-9]+";
String text = "__c";
Pattern pattern = Pattern.compile(namePattern);
Matcher matcher = pattern.matcher(text);
"__c" is an illegal var name.
But it returns the string "_c", where it is supposed to return an empty matcher.
where am I wrong here?
View Replies
View Related
Jun 12, 2014
One: is it possible to test code offline with one device, preferably an android tablet?
Two: if, not, is it possible, online with just an android tablet?
Three:if not, is it possible using the internet on my smart phone and with no internet on my tablet - and no, I can't use my smartphone as a hotspot?
I want to test code I wrote on droid edit. An app I purchased for writing code. I'm using Java.
View Replies
View Related
Nov 18, 2014
In my integration test, I tried to use resttemplate to send a Get request to a dummy server created by MockMvcBuilders. However I got an error:I/O error on GET request for `"http://localhost:8080/test"`:Connection refused:(In the function testAccess(), url is `"http://localhost:8080/test"`). My code is as below:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest("server.port=8080")
public class MyTest {
private MockMvc mockMvc = null;
[code]....
View Replies
View Related
Oct 12, 2014
Write a Java program that reads a positive, non-zero integer as input and checks if the integer is deficient, perfect, or abundant.A positive, non-zero integer, N, is said to be perfect if the sum of its positive proper divisors (i.e., the positive integers, other than N itself, that divide N exactly) is equal to the number itself. If this sum is less than N, the number is said to be deficient. If the sum is greater than N, the number is said to be abundant.
For example, the number 6 is perfect, since 6 = 1 + 2 + 3, the number 8 is deficient, since 8 > 1 + 2 + 4, while the number 12 is abundant, since 12 < 1 + 2 + 3 + 4 + 6.
Sample Output:
Input N: 5
5 is deficient.
Input N: 6
6 is perfect.
Input N: 18
18 is abundant.
View Replies
View Related
Feb 17, 2014
I have a directories in UNIX:
/home/t_bmf/Java/HelloWorld/src/helloworld :will contain a .java file
/home/t_bmf/Java/HelloWorld/bin :will contain all .class file
Let say a have a code:
package helloworld;
public class HelloWorld {
public static void main(String[] arg) {
System.out.println("Hello World");
}
}
a command to compile this even outside the directory /home/t_bmf/Java/HelloWorld/src/helloworld
javac -d /home/t_bmf/Java/HelloWorld/bin /home/t_bmf/Java/HelloWorld/src/helloworld/HelloWorld.java
This will generate a directory /home/t_bmf/Java/HelloWorld/bin/helloworld and file inside this is HelloWorld.class
To run this program I must be in directory /home/t_bmf/Java/HelloWorld/bin and using this command:
java helloworld.HelloWorld
Question:
I already how to run the HelloWorld.class, but I must be in helloworld /home/t_bmf/Java/HelloWorld/bin to run it. Is there's a way to run the class even when I am not in directory /home/t_bmf/Java/HelloWorld/bin? Let's say I'm in /home/t_bmf, can I still run the HelloWorld.class?
View Replies
View Related
Jun 11, 2014
I've got a problem with my home made game. When I created it as a JFrame application it runs smoothly, but when I tried to convert it to a JApplet the graphic is "lagging". I can see the graphics blinking/flashing .....
Here is the code:
public class FallingBalls extends JApplet implements KeyListener,
ActionListener {
// VARIABLES //
boolean gameOver;
boolean win;
// Buttons
JButton start, pause, restart;
// Character "The Runner" (32px x 32 px)
[code]....
View Replies
View Related
Nov 23, 2014
I'm getting back into the swing of things with Java after using I'm asked to utilize a simple GUI in order to take in the starting data, I cannot seem to get this to work. I'm getting this error Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Input.buildPanel(Input.java:53)
at Input.<init>(Input.java:27)
at InputDemo.main(InputDemo.java:5)
I've created two classes
import javax.swing.*;
public class Input extends JFrame {
private JPanel panel;
private JLabel messageLabel;
private JLabel messageLabel1;
private JLabel messageLabel2;
private JTextField shiftHrs;
[code]....
View Replies
View Related
Apr 1, 2014
I have a problem with running my hello world aplication. Here is the code.
public class HelloWorld {
public static void mаin(String[] args) {
System.out.println("Hello world!");
}
}
It compiles fine. But I get an exception when I try to run it.Here is the error message I'm getting:
Exception in thread "main" java.lang.NoSuchMethodException: HelloWorld.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1605)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
Process finished with exit code 1
View Replies
View Related
Mar 30, 2014
I've been playing around with this for about an hour.
Java Code:
Runtime runTime = Runtime.getRuntime();
try {
Process process = runTime.exec("notepad");
} catch (IOException e) {
e.printStackTrace();
} mh_sh_highlight_all('java');
So that works. Notepad will open.
However, I'm trying to get other programs to open. Specifically, this program: C:Octave3.2.4_gcc-4.4.0inoctave-3.2.4.exe...However, using that in place of notepad doesn't work. I'm assuming that there is some sort of system variable that explains why simply typing "notepad" works? As if you type notepad into the run box, notepad will open. Soo does that snippet work by going through some sort of system variables?How would I go about opening other programs, such as the one I referenced above.
View Replies
View Related
Jun 8, 2014
Tried to run ServiceServerImpl.class with rmic and got this error. Below is the command prompt text pasting.
"C:Program FilesJavajdk1.7.0_21in>rmic.exe ServiceServerImpl
error: File .ServiceServerImpl.class does not contain type ServiceServerImpl as expected, but type serviceserver.ServiceServerImpl. Please remove the file, or make sure it appears in the correct subdirectory of the class path.
error: Class ServiceServerImpl not found.
2 errors "
Here is the source code of the class file. Using Windows 8. I copied the .class file to the rmic.exe 's location later. didn't work either way. It is in a package called "serviceserver"
package serviceserver;
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
public class ServiceServerImpl extends UnicastRemoteObject implements ServiceServer
{
HashMap serviceList;
[Code] ....
View Replies
View Related
Jul 2, 2014
I have make the immutable class as below, Now my question is how I can test if my this class/object is immutable
package com.learning;
import java.util.*;
import java.util.Map.Entry;
public final class ImmutableTest {
private final int id;
private final String name;
private final HashMap<String, String> hm ;
[Code]...
How I can Test If it is immutable class without looking ?
View Replies
View Related
May 17, 2014
I am not sure how to add all the possibilities of elements in an array and find the greatest sum. I want to do this recursively. I don't need any code. How I would do it.
View Replies
View Related