Function that saves any possibility of a root diagram in an array

I want to return any possibility of something like a root diagramm in an one dimensional array. It is not knwon how many branches the root (or tree) has, so I probably need to use something like recoursion. I basically want to use recoursion until it reaches one end of a branch and save that in an array and repeat that process until all possible ends are in the array and then I want to return that array. Is there a good solving for that problem, or do I need to make two functions, one returning one ending and one returning all these endigns in an array?
Thanks for helping me out,
bb :*

P.S.: I do it in Java

JSONObject return empty:false

After some researchs, I didn’t have found any solutions to this problem:
when I create a JSONObject (org.json) from a file, it return “empty”:false. Why does it return this and how can I fix it?


JSONObject config = new JSONObject(Files.readAllLines(Paths.get("config/maj.json")));



Files.readAllLines is working return the right value.


Boolean use in an if statement

public static int search(int[] a, int target)
    int i=0;
    boolean found = false;
    while((i<a.length) &&  ! found)
        if (a[i] == target)
        found = true;   
        else i++;
    if (found) return i;
    else return -1;

I dont understand the if statement part. So how i am reading it in my head is found is set to false. If not found…so if not false (since found = false), do whatever. So basically im reading it as a double negative and seeing if (true) dow whatever. But it doesnt make sense. I know its not an inifite loop and it runs fine but I dont get the logic, it must not be a double negative. Thanks!

So i get that we could just return i, much easier yes I agree. I just am having trouble with the logic of the boolean value being used in the loop with the not “!” symbol.

Basically if i wrote this i would say (ignoring everything else)

found = true //found is true to begin with
while (!found) //while not true
continue to next index //continue until ….actually i’m getting very confused now because to break the loop we would continue until found is false which logically is backwards

Android Dagger: I can’t provide an external class without @Inject constructor

I’m writing an Android app with use of Dagger and Kotlin.

I want to inject java.text.SimpleDateFormat class into my class DateHelper

class DateHelper @Inject constructor(var dateFormat: SimpleDateFormat) {

I have a module, which @Provides SimpleDateFormat.

class DateModule {
    fun dateFormat(): SimpleDateFormat {
        return SimpleDateFormat("yyyy-MM-dd", Locale.US)

and a Dagger component:

@Component(modules = arrayOf(MyAppModule::class, DateModule::class))
interface MyAppComponent {

Lastly my Application:

open class MyApplication : Application() {
    private lateinit var myAppComponent: MyAppComponent

    override fun onCreate() {
        myAppComponent = createGraph()

    open fun createGraph(): MyAppComponent {
        return DaggerMyAppComponent.builder().myAppModule(MyAppModule(this)).build()

    fun getAppComponent(): MyAppComponent {
        return myAppComponent


Now, I’m trying to @Inject DateHelper into my Fragment:

class CoffeeNoteFragment : Fragment(), DatePickerDialog.OnDateSetListener {
    @Inject lateinit var dateHelper: DateHelper
    override fun onCreate(savedInstanceState: Bundle?) {
        (activity.application as MyApplication).getAppComponent().inject(this)

Unfortunately I’m getting compile-time error

error: [com.example.mateusz.coffeenotes.application.MyAppComponent.inject(com.example.mateusz.coffeenotes.CoffeeNoteFragment)] java.text.SimpleDateFormat cannot be provided without an @Inject constructor or from an @Provides-annotated method.
  java.text.SimpleDateFormat is injected at
  com.example.mateusz.coffeenotes.database.DateHelper is injected at
  com.example.mateusz.coffeenotes.CoffeeNoteFragment is injected at

I don’t understand why I’m getting this error, since I’m @Providing the SimpleDateFormat. Obviously I cannot add @Inject constructor, since I don’t own the SimpleDateFormat class.

Any help what I’m missing?

Internationalization in Java

I try to use I18N in my program but it doesn’t work properly. Console doesn’t show German symbol, just “?” instead of it.

Here is my code:

import java.util.Locale;
import java.util.ResourceBundle;

public class LocaleDemo {

public static void main(String[] args) {

            Locale l = new Locale("ge", "GE");
            ResourceBundle r = ResourceBundle.getBundle("Bundle_ge");

public static void displayValues(ResourceBundle bundle) {
    System.out.println("hello message:" + bundle.getString("wish"));

File has this text: wish=großer

And here is the result:

enter image description here

What is my mistake? Thank you in advance.

Background that triggers notification outside UI

I have a project I am working on where I am using JSON to pull some data from a website. I want to send a notification to the user outside the UI when a certain part of the data is too low.

I have looked around and the best thing I have found so far is notification but I dont know how to make that run in the background like a service?

thank you in advance

Populate a RadioGroup with RadioButtons from a string-array

I have a layout that includes an empty RadioGroup.

I’d like to populate this RadioGroup with the items from a string-array that I have defined in strings.xml.

The array in strings.xml looks like this:

<string-array name="currency_symbols">
    <item>$ - Dollar</item>
    <item>€ - Euro</item>
    <item>£ - Pound</item>
    <item>¥ - Yen</item>
    <item># - Other</item>

I am then trying to create a RadioButton and add it to the RagioGroup with teh following:

RadioGroup currencySettingRadioGroup = (RadioGroup) settings_dialog.findViewById(;

RadioButton rb = new RadioButton(this);
String[] currency_symbols_options_array = getResources().getStringArray(R.array.currency_symbols);
for ( String this_currency_option: currency_symbols_options_array ) {

The currencySettingRadioGroup.removeAllViews(); was added because I’m getting the following error, but it makes no difference:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

The line that is apparently causing the problem is the currencySettingRadioGroup.addView(rb); line…

How do I do this properly?

getting inputs one after the other in from one JTextField java

I’m new to Java, and I’m working on what is supposed to be a basic representation of a bookstore, where a user can add books, textbooks or workbooks to the bookstore(an arraylist). I have to use a GUI for this, and the only elements allowed are a JTextArea, and a JTextField. My problem is that in the actionlistener, the initial input in the textfield just becomes the input for the rest of the prompts that follow it, without allowing the user to put anything in. Is there a way to fix this? Below is a snippet of my code.

public static void main(String[] args){

    BookStore b = new BookStore();

String input;
public BookStore() {

    setSize(800, 500);
    setLayout(new GridLayout(1, 2));

    textField = new JTextField(25);
    panel = new JPanel();
    textField.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae) {
                The majority of your code should be written here.
                Note that this scope has access to the fields textField
                and textArea.
            //input = textField.getText();

            if(Integer.parseInt(textField.getText()) == 1) {
                input = textField.getText(); //this just uses the input already present in the JTextField; how can i fix that
                if(Integer.parseInt(input) == 1) {
                    textArea.append("Enter the title of the book: ");
                    tempTitle = textField.getText();//This also uses the input from the original getText() without allowing any input to be entered
                    ret = addBook(BT_BOOK, tempTitle);

How to execute a python script from a servlet?

I have written the following code for the servlet:


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Summarize extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        PrintWriter out = resp.getWriter();
        String str = req.getParameter("txt");

        try {
            Process p = Runtime.getRuntime().exec("python");
            BufferedReader in = new BufferedReader(new InputStreamReader(
            StringBuffer buf = new StringBuffer("");
            String line = null;
            while ((line = in.readLine()) != null) {
            out.println("this is summarize class");
        } catch (Exception e) {

This code won’t return anything but If I write the same code in a simple java class the code works perfectly fine.

I have also checked the python script, it’s running perfectly fine.
Is there any way to fix this?

Code runs fine on one PC. But gives null pointer on another

So, I have a piece of code which works fine on a desktop but not on my laptop. I am using java’s RecursiveAction class to create a Flyweight to compute fibonacci number. The exact same code runs fine on one pc but gives a null pointer exception on another.

Also lets say I run it about 10 times on my pc and it will work 1 out of those 10 times.