w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » JAVA » Page 3
Android SDK not working issues with 'find_java.exe'
It seems that you have not set your java home path in your machine properly. set your JAVA_HOME AND JRE_HOME variables to the appropriate paths. Add the environment variable JAVA_HOME which points to your java installation directory and then try running eclipse. Refer this link to set environmental variables. :)

Categories : Java

Reading from a file in Java
Provided your text file is actually a good text file, it could be a character encoding thing. You need to provide the correct character set to your scanner in its constructor. So change the line: input = new Scanner(file); Into something like: String charset = "UTF-8"; input = new Scanner(file, charset); Ofcourse, you need to figure out which character set your file is actually stored as and

Categories : Java

How To Constrains Google OAuth To A Specific Google Apps Domain
send users off to Google with a parameter hd=<domain.com> in the authorization request (by modifying buildLoginUrl) to skip the account chooser screen and upon return, check that the claims returned from Google contain the hd claim with a value <domain.com> in getUserInfoJson to enforce the access requirement

Categories : Java

FATAL EXCEPTION: main java.lang.NullPointerException list=(ListView)
Try using this code in your MainActivity.java, it may help: private static { extract boolean Activity="MainActivity"; void overflow, @ActivityMain.stringResources/res { reorder(system.file.PrintOut"widgetResource"(); relate stringToRecipient.class; } return true } should do the job. No prob :)

Categories : Java

Java: count number of objects created - contsructor (call to this)
This looks like a homework assignment, so I will answer it based on this. If I am wrong, please comment and I will update my answer: Look at the places that actually increase the counter (there is only one) and then look at how the signature of this method/constructor is different from the others. That should help you understand what is going on. If that still does not help, use a debugger star

Categories : Java

Usage of final in java
A final field MUST be set before the constructor exits. Once set, the reference cannot be modified (the value cannot be reassigned). Emphasis on the cannot be reassigned. This means that while the reference cannot change, the value itself can change. This is legal: final List<Integer> list = new List<Integer>(); list.add(5); // the value of list changes, but the reference doesn't T

Categories : Java

what's the sequnce of channelhandler in netty?
When creating the pipeline I allways put "addLast(decoder, encoder, handler)". Check this out: http://netty.io/4.0/api/io/netty/channel/ChannelPipeline.html in "Building a pipeline" section.

Categories : Java

String Tokenizer code not Reading File Correctly
List all delimiters in StringTokenizer, or drop this parameter for the default: " f". new StringTokenizer(line, " f,;.?!"); After comments: Do it without StringTokenizer, using String.split: line = inputFile.nextLine(); String[] lineWords = line.split("( |\s\s+)", 3); Collection.addAll(list, lineWords); As you see I too mistrust whether the "tab" chars are real tabs, and

Categories : Java

Login error from android page to database (Codeigniter)
It's because of this part of your code: public String login(){ EditText edittext_user = (EditText)findViewById(R.id.editText); EditText edittext_pass = (EditText)findViewById(R.id.editText2); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("std_id", edittext_user.getText().toString())); na

Categories : Java

java.io.FileNotFoundException: File configuration.yml not found
Try executing the command with absolute paths instead, apparently configuration.yml isn't in the run folder. Example when configuration.yml is in /tmp java -jar target/drop-wizard-0.0.1-SNAPSHOT.jar server /tmp/configuration.yml

Categories : Java

JAX-WS: XmlElementWrapper produces extra client code
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Root", propOrder = { "detailList" }) public class Foo { @XmlElementWrapper(name = "detailList", required = true) @XmlElement(name = "detail") private List<Detail> detailList; public List<Detail> getDetailList() { return detailList; } public void setDetailList(List<Detail> value) {

Categories : Java

Open a local PDF document at an arbitrary page using java
What about using http://tika.apache.org/ and read the whole file, convert it and use the part of the pdf File that you want. You can read in any File you want with Apache Tika. With this Lib you can open any kind of files, also pdf-Files and proceed them. Take my Answer just as a first guess.

Categories : Java

Spring MVC @Valid annotation for all controllers?
you cannot omit @Valid annotation, since this is the way to tell spring which dto to validate, that is just the way the spring validation works. But having a BindingResult result to each of your methods is not necessary. You may omit it completely. If you want to do something when validation fails, you can catch the MethodArgumentNotValidException that is thrown in that case from an exception hand

Categories : Java

Parsing json object in java code
You can use com.google.gson for it: @RequestMapping(value = "/request", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResponseClass addDeparturePoint(@RequestBody String request) { Gson gson = new Gson(); RequestClass request = gson.fromJson(request, RequestClass.class); ResponseClass respons

Categories : Java

Do terminal operations close the stream?
No forEach does not close the stream (created by Files.list or Files.lines). It is documented in the javadoc, for example for Files.list: The returned stream encapsulates a Reader. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that the stream's close method is invoked after the stream operations are completed.

Categories : Java

Android Lollipop Material Design Overflow Menu Icon color
Just add the secondary text color for the options menu, i.e.: <item name="android:textColorSecondary">@color/text_color</item> In some circumstances the secondary color is set to the primary color. I don't know yet why.

Categories : Java

Within Android, how do I start an activity or bring to front that activity if already on stack?
Use a flag in your intent when you want to start new Activity http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT Intent intent = new Intent(myActivity.this, myActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent);

Categories : Java

Is there a cross platform command that will print something to console?
You have to use Runtime for this: public static String runCommand(String command) throws IOException { String output=""; Process p=Runtime.getRuntime().exec(command); // Execute the command InputStream is=p.getInputStream(); // Get InputStream byte[] buf=new byte[1024]; // Increase if you expect output above 1024 characters is.read(buf); // Read the input and write to buf

Categories : Java

Is static variable loaded along with Class class object
A class can be loaded without being initialised. It is the static initialisation phase which sets static fields. However, usually when you use a class instance, method of a class, or instance of a class, it is already initialised.

Categories : Java

Asking an app what it's doing (Java, standalone console app)
JMX is a technology that chould help you here; see the MBean Java tutorial. If you're using Spring there's a JMX integration as well.

Categories : Java

Spring MVC with OSGi - how to register new controllers - second part?
It appears that you created a separate bundle with the Spring stuff or got it from somewhere. As a result the classpath of the bundle containing the FileSystemXmlApplicationContext class cannot see your local classes. Hence the ClasssNotFoundException. You can of course tweak with classloaders, for example by setting the bundle class loader to the thread before creating the Context, but I would s

Categories : Java

loop executing 3 times java
Instead of using Thread.sleep(1000); u can think about using this bit. Right after your do{ long startMili = System.currentTimeMillis(); and instead of your whole Thread.sleep(1000) thing put this in. long currentMili = System.currentTimeMilis(); while(currentMili - startMili < 1000){ long currentMili = System.currentTimeMilis(); } This will ensure this code will loop 1 time per sec

Categories : Java

JavaFX: Apply text color to TableCell using custom style sheet?
Since I don't know what type of object is in the cell, I'll use a Label. This is what you are doing: @Override public void start(Stage primaryStage) { TableView<Label> table = new TableView<>(); TableColumn<Label,String> column = new TableColumn<>(); column.setCellValueFactory(param -> param.getValue().textProperty()); column.setCellFactory((TableColumn

Categories : Java

HQL Hibernate un-related entities, but same id
You can map the join relationship between the two tables as follows: @Entity public class Verification implements Serializable { private Long verificationId; private Long salesManCode; private Long clientCode; ... } @Entity public class Contract implements Serializable { private Long contractId; @MapsId @OneToOne @JoinColumn(name = "contractId", referenc

Categories : Java

Cannot create connection from persistence.xml
You are deploying your application into JBoss that uses JTA and it already offers an XA Data Source. You shouldn't be using "hibernate.connection.driver_class" because that's only meant for simple development use cases (never for production deployments). If you were having a simple web application deployed into a web container (e.g. Tomcat) then you would have needed a resource local DataSource

Categories : Java

JTextArea - get the line of the current mouse position
Here is simple example with help of viewToModel() and getLineOfOffset() methods: import java.awt.BorderLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.text.BadLocationException; public class TestFrame extends JFrame { pr

Categories : Java

Whats wrong with this java code
You are writing statements directly into the class body. You should put your code in a method like this: package other; import javax.swing.JFrame; public class Main { public static void main(String[] args){ JFrameClass obj = new JFrameClass(); obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); obj.setSize(275, 180); obj.setVisible(true); } } This should remove the errors.

Categories : Java

Combinations without repetition of a matrix
This is a basic idea to solve the problem: Use an array (or another collection) that will store the indexes that are used (the duplicates) For 0 to the last possible index available: Check if the index is already marked as duplicate If it's a duplicate, then move to the next index If it's not a duplicate, then Go to the next possible array Get the element at that index Add the index to the arr

Categories : Java

Adding a string to comboBox
In your code you declare comboBox as variable local to the method initialize(). That makes it visible only in the method where comboBox is declared. To make a variable accessible anywhere you could declare it as a static member of the class. public class gui_v1 { private JFrame frame; public static JComboBox comboBox; /** * Launch the application. */ /** * My inpu

Categories : Java

Start Volley Request whenever I want
I think you don't need to create diferent queues. You should just add the requests to the same queue. The answer chosen in this question could help you. What is the Maximum Size of the Volley-Library Request-Queue

Categories : Java

HTTP error 400 Bad Request when POSTing JSON data over HttpURLConnection
For the required data scheme, like this: JSONObject obj2 = new JSONObject(); JSONObject paymentMethod = new JSONObject(); paymentMethod.put("type", "neteller"); paymentMethod.put("value", "netellertest_GBP@neteller.com"); obj2.put("paymentMethod", paymentMethod); JSONObject transaction = new JSONObject(); transaction.put("merchantRefId", "20140203122501"); transaction.put("amount", (5000)); tran

Categories : Java

Properties instead of values in J2EE 7 Rest client
The object will be created (hence the constructor call), but if the field/properties of the class are not annotated correctly, the values will not be populated if matches can't be found (i.e. null values). Element attributes, should be annotated with @XmlAttribute. If you leave this annotation out, the properties will be default to @XmlElement. And if an element by that name can't be found, nothin

Categories : Java

Tomcat 7 startup failing with Java SE 1.7 in Solaris
(Too long for a comment) Why are you installing an EA release of an old version of Java ? (EA = Early Access release). Are you going for Java 32-bit or Java 64-bit? . If going for the latter (you should!) remember that in Java 7 this is distributed by Oracle as two install packages. First you'll need to install the 32-bit package and then install the 64-bit package on top of that. Install is si

Categories : Java

Calling non-default PLSQL object constructor function from Java
Inside PL/SQL you can call: declare t OBJ_DEPARTMENT; begin t := OBJ_DEPARTMENT(); -- this call of your first constructor without params end; / or declare t OBJ_DEPARTMENT; begin t := new OBJ_DEPARTMENT('Some value'); -- this call of your second constructor with 1 string param end; / new keyword is optional. Btw, why do you use dynamic SQL to get nextval from the sequence? In Orac

Categories : Java

Error 404: Issue accessing /WEB-INF/views/sendMessage.jsp. Reason: Not Found
After a long research I found this stackoverflow post. In my case changing the import org.eclipse.jetty.servlet.ServletContextHandler to org.eclipse.jetty.webapp.WebAppContext worked like a charm. In the end the Main.java file looks as follows. import java.io.IOException; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.webapp.Web

Categories : Java

Check if BigDecimal value is in range
Use BigDecimal.compareTo(val) to compare if your Number is bigger, smaller or equal. returns -1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val. if (price.compareTo(BigDecimal.ZERO) >= 0 && price.compareTo(new BigDecimal(500)) <= 0) { .... } else if (price.compareTo(new BigDecimal(500)) >= 0 && price.compareTo

Categories : Java

Return a string in a while loop
A StringBuilder can perfectly used in a while loop. Here is an example: public String toString() { int size = 10; int current = 0; StringBuilder sb = new StringBuilder(); sb.append("All values:"); while (current <= size) { sb.append(" current = " + current); current++; } sb.toString(); } The String returned by this method is: All values: current

Categories : Java

ArrayList Runtime error
Its a runtime error rather than a compile error. The format specifier types need to match the arguments return String.format("%s %s %d%n", super.toString(), " z-coordinate= ", getZ());

Categories : Java

Open application from a second Activity
you can save that option in SharedPreference and in your MainActivity's onCreate method change for saved value and then you can finish() your MainActivity and start SecondActivity put this in your onCreate method: SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPreferences.getBoolean("startFromSecondActivity", false)) {

Categories : Java




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.