w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » JAVA » Page 53
How to recall variables made in if() functions in Java
You can't. You have to declare it before the if block in order to use it after it. String x2 = null; if(x>2.5){ x2 = "X =" + Double.toString(x); } System.out.println(x2);

Categories : Java

String Base64 or physical image file
base64 encoded data will be bigger than raw data and then you yet need to decode it on client. So what's the point? Serve "normal" images, so client app does not need to do any "magic" to display it. Also you'd be able to use classes like Glide or Picasso to and delegate loading/caching etc to them /wo any hassle

Categories : Java

Android - SharedPreferences - can't get my value
Are you retrieving the shared preferences from the same pref. In your addElement method, you use the "MentalCalculationSaveData" one. Make sure you use the same one to retrieve. Also what is the implementation of your isKeyExists. You can try to use sharedPreferences's contains method to check if the key exist or not. In addition, not sure what is your getInt() method. You can use sharedPrefer

Categories : Java

No results found error in Parse
couple things are wrong in your codes remove query.get(), this is supposed to load the object by Id you cannot cast List to String[] do a for loop and ParseObject.getString("title");

Categories : Java

java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
If I'm not mistaken that code means Android found a reference when it expected a color value or failed to convert reference to color. Looking at your code this line stands out <item name="android:textColor">@style/MyActionBarTitleText</item> Despite you can have a reference in textColor I'm not sure you can set it as a style. So try to reference your color directly <item name="

Categories : Java

ArrayList with images JAVA
The JScrollPane has a JComponent as viewport. You should add your components to the viewport view and not to the JScrollPane directly. Hence it consists of JScrollBars, header, the JViewport etc. The "thing" which is scrolled ist the JComponent set as viewport. Hence you must set a View containing all your images as viewport of the JScrollPane and it should work. See JScrollPanel JavaDoc for fur

Categories : Java

JPanel not displaying properly with GridBagLayout
It would be simpler to just use a BorderLayout, but otherwise, your problem is that you don't set weighty to a positive value for your second component. Here is a small snippet that illustrates both options and allowing you to switch from to another. import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt

Categories : Java

Finding unique numbers from sorted array in less than O(n)
I don't think it can be done in less than O(n). Take the case where the array contains 1 2 3 4 5: in order to get the correct output, each element of the array would have to be looked at, hence O(n).

Categories : Java

Is there any design pattern to use?
I think you should go with decorator pattern and use composition. A Complex should have a Basic member, which could manage the Basic part of the Complex type. Below a short example. package main; public class Main { public static void main(String[] args) { Basic basic = new BasicImpl(); basic.basicOp(); // main.BasicImpl.op() Complex ca = new ConcreteComple

Categories : Java

Spring Integration 4.1.0 Migration problems
The code from AbstractSimpleMessageHandlerFactoryBean says: else if(!(this.handler instanceof AbstractReplyProducingMessageHandler)) { if (logger.isDebugEnabled()) { logger.debug("adviceChain can only be set to AbstractReplyProducingMessageHandler or its subclass, " + ((IntegrationObjectSupport) this.handler).getComponentName() + " doesn't support it.");

Categories : Java

Memory overflow Java
You can increase heap size using the cmd-line flags For example: java -Xmx6g myprogram You can get a full list (or a nearly full list, anyway) by typing java -X.

Categories : Java

How to use jackcess to connect to a Microsoft Access database (.accdb)?
I haven't quite implemented/used jackcess yet. But to use External jars, like in eclipse you need to right click "JRE System Library" in your project. Build path >> Configure Build Path & then use the Button "Add external JARs" to browse and finally import your jar file. Then you can create a program by the use of its classes & methods, without any error of unknown class.

Categories : Java

Driver not found: [com.mysql.jdbc.Driver] no matter what i do
Solved, in case anyone stumbles upon similar problem: running clean isn't enough, running reload after inserting the dependency solved it for me. (I don't know how is this in older versions, but that is how it is in 2.3.6

Categories : Java

code not working after catching an exception
You should get rid of your while loop. If an exception is thrown, catch it, but don't continue the loop, since as long as quantityField.getText() doesn't change (actually you change it to "" in the catch block, but that will still throw the same exception), you will keep getting this exception over and over again, and the loop will never terminate.

Categories : Java

Whats wrong with my loop?
You're only creating a single Frame. You create the Frame with Frame retrievedFrame = new Frame(); and then for each line you change the frame number of that frame and add it to the list again. What you probably want is to create a new Frame each time: if (al.get(i).contains("FrameNumber:")) { temp = al.get(i).replace("FrameNumber: ", ""); temp = temp.trim(); Fram

Categories : Java

How to recursively compile a collection of packages in Java
There are no "bin files" in Java, this language only compiles bytecode Compiling multiple packages using the command line in Java Eclipse : http://stackoverflow.com/a/7218929/351861 via console : javac folder1/*.java folder2/*.java folder3/*.java

Categories : Java

How to check annotation before loading class?
Here's a simple example of class annotation: @SomeAnnotation(name="someName", value="someValue") public class Meta {} The Meta definition: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface SomeAnnotation { public String name(); public String value(); } Access to the class annotation and load class: Class clazz = Meta.class; ClassLoader classLoader = cla

Categories : Java

TreeSets to match lotto numbers?
You should read the docs of the TreeSet() constructor you are using : /** * Constructs a new, empty tree set, sorted according to the * natural ordering of its elements. All elements inserted into * the set must implement the {@link Comparable} interface. * Furthermore, all such elements must be <i>mutually * comparable</i>: {@code e1.compareTo(e2)} must not throw a * {@code Cl

Categories : Java

Adding extra type parameter to interface method prevents override
I think this may have to do with binary compatibility, though the exact error message you are getting may possibly be confusing. Think about code written before adding the MoreParams interface: Params params = new ParamsSubClass(); String str1 = params.test(String.class); String str2 = params.<>test(String.class); String str3 = params.<String>test(String.class); When you instead of

Categories : Java

How to sorting list interface
Couple of issues in your code (I just went through add,getentry and sort method): In getEntry method, Remember index always start with 0 and go after till length - 1, so you should change our method to: public T getEntry(int givenPosition) { T result = null; if ((givenPosition >= 0) && (givenPosition < length)) { Node currentNode = firstNode; for (int i = 0; i < givenP

Categories : Java

How to count number of occurance of character in each string in java?
Recall that a character is an unsigned integral type (i.e. a number) with the range of 0..65535. If you know that all your characters are in the range 0..127, i.e. the first group of UNICODE code points which includes all digits, letters of Latin alphabet in both cases, and many common special characters, you can make an array of counters: int[] counts = new int[128]; for (int i = 0; i < s.len

Categories : Java

Android Prompt Dialogue Box Upon Event Triggered
It's because onTouch listener is called multiple times, i.e. when your finger lands on the screen (ACTION_DOWN) and when you move your finger up (ACTION_UP). You want to show the dialog when the latter one fires: ratingBar.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP

Categories : Java

Sort jtree Nodes alphabeticly
dir.listFiles() - doesn't guarantee order of files, because of you need to sort it by yourself like next: DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) { File[] tmp = dir.listFiles(); List<File> ol = new ArrayList<File>(Arrays.asList(tmp)); Collections.sort(ol, new Comparator<File>() { @Override public int compare(File o1,

Categories : Java

which hibernate query languge is more efficient
These are examples of SQL which will be generated from your HQL The first (from Cat as cat where cat.id = 123): select c.* from Cat c where c.id=123; // no joins - OK The second (from Cat as cat where cat.mate.id = 69): select c.* from Cat c where c.mate_id=69; // no joins (because cat.mate.id is the identifier in Mate) // that's why it's efficient If you had this HQL: "from Cat as cat wher

Categories : Java

How to load items of a category from database in a depandent spinner
I Solved the issue; May be you have a good imporovement. final Categories categories = null; final List<Categories> AllCategories ; AllCategories = (List<Categories>) getAll(categories); final ArrayList<String> list = new ArrayList<String>(); for (int i=0;i<AllCategories.size();i++) { String val=AllCategories.get(i).getName().toString();

Categories : Java

ThreadPool executor and huge amount of clients connected simultaneously
If you are going to have really huge amount of clients, you should consider NIO for it, because creating thread for each client will be too expensive. NIO uses selectors and channels and doesn't require to create new thread for each connection. See image. Did you hear about netty ? I don't know what you are going to implement but seems like it will be useful.

Categories : Java

How to include a Double Variable in a String Variable in Java?
You can use Double.toString(double). String beta = "Alpha has a value of " + Double.toString(alpha);

Categories : Java

Multiple assignment at once in java
tl;dr: No, there isn't such a thing in Java. You can assign initial values to variables like this: int foo = 1, bar = 2; But if your want (1, 2, 3) to be the result of a method call, this is not possible in Java. Java does not allow returning multiple values. Python allows this: def foo(): return 1, 2, 3 a, b, c = foo() The main point, why this does not work in Java is, that the left

Categories : Java

Selenium "Element not found" due to incorrect XPATH
You need to wait for "Result" to get populated. Here is the updated code snippet, it should work for you: //add this line if (!selenium.isElementPresent("//*[@id='content']/p[2]/span/font/b")){ Thread.sleep(2000); } // verify if the result is 5 String result = selenium.getText("//*[@id='content']/p[2]/span/font/b"); System.out.println(result); //update this line

Categories : Java

SWT , TreeViewer , CellEditor with ComboBox
Figured it out. following code added to the SetValue() method solves it. m_tree = (Tree)getViewer.getControl(); TreeItem[] ti = m_tree.getSelection(); CCombo c = ((CCombo)cellEditor.getControl()); String str = c.getItem(c.getSelectionIndex()); ti[0].setText(1, str );

Categories : Java

Why do my changes in ActionListener not take effect immediately?
The button won't be repainted until control returns to the Swing event queue. Calling that function on the event dispatch thread is blocking the event queue. As a workaround, tell it to run the function later (as soon as it's done repainting things): In Java 8+: EventQueue.invokeLater(() -> callingFunction()); In old Java: EventQueue.invokeLater(new Runnable() { @Override public v

Categories : Java

java.lang.RuntimeException: Unable to instantiate activity (unable to open DEX file)
Check that the package name matches in your build.gradle, AndroidManifest.xml and in your RondaOptionsActivity.java. Looks like it's supposed to be: com.bendev.ronda.game.activity

Categories : Java

Scala overloading not choosing most specific method
Your definition of Exp and interpret are not fully visible and not sure I understand what you are trying to represent but here's 2 ideas: Try to use operator overloading defining a + and a - methods for more DSL-esque operations Even better so, you can think of the addition, subtraction or any other operation as bahaviours and define them as functions. This way (single data representation with m

Categories : Java

Quiz algorithm - harder to get q answered correct / easier to get q answered wrong
I would implement it more like this: You make a float array with one entry per question, that indicates the factor of how often the question is asked. Initially, all questions have a factor of 1. The trick is to lower the factor when an answer has been answered correctly. For instance, you could halve it. To pick a question to ask, you sum up all factors in the array (if you have 250 questions,

Categories : Java

Getting data from tables using parse.com android
these values are retrieved with ParseObject so in your for loop, just categoryAttributes.getString("$column_name") if your column is a Pointer, and you want it to be returned with your query. you need to query.include("$pointer_column_name");

Categories : Java

display emoji in Java (jFrame)
First things first: what is an "emoji"? It is a code point in the "emoticons" Unicode block. You will note that this block is outside the BMP (Basic Multilingual Plane), since all code points for this block are greater than U+FFFF. Second point: how are they treated by your display? It all depends on your display's capabilities, and post treatment. By "capabilities", it is understood that your

Categories : Java

TCP Gateway Spring integration video tutorials
I am not aware of a video but there's a simple sample app that shows the use of both inbound and outbound gateways to invoke an echo service over TCP. It uses the default CRLF to delimit messages; be sure to read the section about (de)serializers in the documentation.

Categories : Java

What's the Rubygems / Packagist equivalent for Android?
Gradle is the default dependency management system for Android and it uses the Maven Central Repository to find remote dependencies. You can look at this repo on http://search.maven.org/. For more information about it: http://developer.android.com/sdk/installing/studio-build.html#dependencies

Categories : Java

Java JFrame window is not updating
Your render() function is not being called. You need to call repaint() to do this. This will call render() and update the JFrame. Resizing the window repaints the window automatically, which is why it worked only after you resized it.

Categories : Java




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