Android – repeat LinearLayout with slight changes

I have a vertical LinearLayout, which I want to fill with horizontal LinearLayouts (which act like rows). Each of these should effectively be identical, except several items within them use a number, which should increase each time.

For example:

<LinearLayout android:id="@+id/row1" >
    <SeekBar
        android:id="@+id/seekBar"
        android:tag="1"
    />
</LinearLayout>
<LinearLayout android:id="@+id/row2" >
    <SeekBar
        android:id="@+id/seekBar"
        android:tag="2"
    />
</LinearLayout>
<LinearLayout android:id="@+id/row3" >
    <SeekBar
        android:id="@+id/seekBar"
        android:tag="3"
    />
</LinearLayout>

In JavaScript, I might use something like this to ‘automate’ their creation:

for (var i = 0; i < count; i++) {
    child = document.createElement("div");
    child.id = "row" + i;
    parent.appendChild(child);
}

Is there a way to ‘automate’ the creation of these, such that I can just have a single ‘model’ of one, then iterate over it several times, ‘passing in’ the number each time? I can use a Java-based or XML-based solution.

I’ve tried using for each one, which solved part of the problem, but couldn’t find an effective way to ‘pass in’ a different number each time. (The numbers are to identify the inputs within the rows from Java – if there’s a better way to manage this, that could also be helpful).

BufferedImage disable dithering when reducing color using custom ColorModel?

I’m creating an image with a custom palette (in other words a custom colormodel):

 BufferedImage img = new BufferedImage(orgImg.getWidth(), orgImg.getHeight(),
      BufferedImage.TYPE_BYTE_INDEXED,
      cm);
 Graphics2D g2 = img.createGraphics();
    g2.drawImage(orgImg, 0, 0, null);
    g2.dispose();

Note that the “cm” variable is a my custom colormodel with a palette of 256 colors.

The “orgImg” variable is a full colored (24 big argb) image.

The above code results in a copy of “orgImg” with 256 colors using the palette defined in the colormodel.

This works nicely.

But java uses dithering to reduce colors. Is it possible to disable this dithering?

Note that i need to use my own palette so that the final images matches a specific color palette.

Adding Paypal button in Play framework Java 2.6

I am trying to implement the button of the payment method Paypal. So I wanted to follow the guide on the website. I am using Java and the Play framework 2.6.

They give the following code on the website to add in your own code:

<!DOCTYPE html>

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>

<body>
<div id="paypal-button"></div>

  <script>
    paypal.Button.render({

        env: 'production', // Or 'sandbox',

        commit: true, // Show a 'Pay Now' button

        payment: function() {
            // Set up the payment here
        },

        onAuthorize: function(data, actions) {
            // Execute the payment here
       }

    }, '#paypal-button');
  </script>
</body>

My code is a little bit different Because I have for the head a different file (called main.scala.html). So the main looks like this:

@*
* This template is called from the `index` template. This template
* handles the rendering of the page header and body tags. It takes
* two arguments, a `String` for the title of the page and an `Html`
* object to insert into the body of the page.
*@
@(title: String)(content: Html)

<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- These are the meta and scripts for paypal-->
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="https://www.paypalobjects.com/api/checkout.js" data-version-4></script>


        @* Here's where we render the page title `String`. *@
        <title>@title</title>

            <!-- Loading third party fonts -->
            <link href="@routes.Assets.versioned("fonts/another_font.css")" rel="stylesheet" type="text/css">

        <!-- Loading weather css file -->
        <link rel="stylesheet" href="@routes.Assets.versioned("stylesheets/bootstrap.css")">
        <link rel="stylesheet" href="@routes.Assets.versioned("stylesheets/weather.css")">

        <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">

        <script src="@routes.Assets.versioned("javascripts/jquery-3.2.1.min.js")" type="text/javascript"></script>
        <script src="@routes.Assets.versioned("javascripts/bootstrap.js")" type="text/javascript"></script>

    </head>
    <body>
        @* And here's where we render the `Html` object containing
        * the page content. *@
        @content
    </body>
</html>

The Content that gets called in the Main for the body looks like this:

    @main("ReStart") {
    <body>
            <!-- Payment Methods -->
                        @*TODO*@
                        <div class="col-md-9">
                            <h2>payment methodes</h2>
                            <div id="paypal-button"></div>

                            <script>
                                    paypal.button.render({

                                        env: 'production', // Or 'sandbox',

                                        commit: true, // Show a 'Pay Now' button

                                        payment: function() {
                                            // Set up the payment here
                                        },

                                        onAuthorize: function(data, actions) {
                                            // Execute the payment here
                                        }

                                    }, '#paypal-button');
                            </script>
                        </div>
        <!-- Required for the banner -->
        <script src="@routes.Assets.versioned("javascripts/jquery-1.11.1.min.js")"></script>

        <script src="@routes.Assets.versioned("javascripts/plugins.js")"></script>
        <script src="@routes.Assets.versioned("javascripts/app.js")"></script>

    </body>
}

In the Main file i added the meta and the script links. In the content file there is the call to render the button, but for some reason i just can’t render it.

Things i tried:

  1. Downloaded the checkout.js and used the following script tag

     <script src="@route.Assets.Versioned("javascript/checkout.js")"></script>
    
  2. I tried the script tags (with link and downloaded js file) in both files. In the Main and in the content file.

It looks so simple but for some reason I can’t figure it out.

Android: How can I get id/text of all selected radiobuttons in recyclerview

I am building a quiz application.
I have a recyclerview which holds multiple cards, each containing many radiobuttons.
I have a submit button at the end of recyclerview. When a user clicks on submit he gets his scores on how he fared in the quiz.
One approach I thought was to check the selected radiobutton in each view individually and compare its string with the correct answer.
How to implement this functionality?

Screenshots from my app:
Image1
Image2

Android Nullpointer exception crash from SkuDetails

When I run my app on Android 6.0 +, I get this error

Process: com.screenoflight.android2, PID: 21013
                                     java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String utils.SkuDetails.getPrice()' on a null object reference
                                     at com.screenoflight.android2.PurchaseActivity$3.onIabSetupFinished(PurchaseActivity.java:282)
                                     at utils.IabHelper$1.onServiceConnected(IabHelper.java:292)
                                     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1227)
                                     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1244)
                                     at android.os.Handler.handleCallback(Handler.java:739)
                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                     at android.os.Looper.loop(Looper.java:148)
                                     at android.app.ActivityThread.main(ActivityThread.java:5517)
                                     at java.lang.reflect.Method.invoke(Native Method)
                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I don’t understand why this is happening because when I run on my personal phone Android 5.1, the price of the in-app purchase shows up fine. But when I try my test phone on 6.0 it crashes giving me a null pointer. I’m really stumped on what the issue here is.

mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        @Override
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                Log.d(TAG, result.toString());
            } else {

                Log.d(TAG, "allgood");

            }
        }

    });

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        @Override
        public void onIabSetupFinished(IabResult result) {
            try {
                String price = mHelper.queryInventory(true, null, null).getSkuDetails(ITEM_SKU_5).getPrice();

                Log.d(TAG, price);

                activateButton.setText("Purchase " + price);

I’ve gathered that it’s an issue with the Runtime permissions. I have added the prompt to allow the permissions to run but I’m not sure why it’s not working.

String[] perms = {"android.permission.READ_PHONE_STATE", "android.permission.CALL_PHONE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"};

    int permsRequestCode = 200;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(perms, permsRequestCode);
        }

I’m completely lost on the reason for this crash aswell, I just don’t get why it’s even after I allow the permissions through.

I just destroyed my Company’s project. What now? [on hold]

This code used to work and I don’t know what I did but if I add servlets in my web.xml everything stops working…

I get a huge error:

SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1015)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at
org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1899)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at
javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at
javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at
javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at
javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at
javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200) at
sun.rmi.transport.Transport$1.run(Transport.java:197) at
java.security.AccessController.doPrivileged(Native Method) at
sun.rmi.transport.Transport.serviceCall(Transport.java:196) at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method) at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748) Caused by:
java.lang.NoClassDefFoundError:
com/github/dockerjava/core/DockerClientConfig at
java.lang.Class.getDeclaredFields0(Native Method) at
java.lang.Class.privateGetDeclaredFields(Class.java:2583) at
java.lang.Class.getDeclaredFields(Class.java:1916) at
org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at
org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:270)
at
org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:139)
at
org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at
org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:417)
at
org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:891)
at
org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:388)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at
org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5519)
at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
… 42 more Caused by: java.lang.ClassNotFoundException:
com.github.dockerjava.core.DockerClientConfig at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
… 56 more

out 20, 2017 4:10:24 PM org.apache.tomcat.util.modeler.BaseModelMBean
invoke SEVERE: Exception invoking method manageApp
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1019)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at
org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1899)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at
javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at
javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at
javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at
javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at
javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200) at
sun.rmi.transport.Transport$1.run(Transport.java:197) at
java.security.AccessController.doPrivileged(Native Method) at
sun.rmi.transport.Transport.serviceCall(Transport.java:196) at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method) at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

out 20, 2017 4:10:24 PM org.apache.tomcat.util.modeler.BaseModelMBean
invoke SEVERE: Exception invoking method createStandardContext
javax.management.RuntimeOperationsException: Exception invoking method
manageApp at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:309)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at
javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at
javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at
javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at
javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at
javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200) at
sun.rmi.transport.Transport$1.run(Transport.java:197) at
java.security.AccessController.doPrivileged(Native Method) at
sun.rmi.transport.Transport.serviceCall(Transport.java:196) at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method) at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748) Caused by:
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1019)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at
org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1899)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
… 33 more

Code structure

The code works without the servlet tags but there is no errors only a warning “Configure Data Sources”….

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <servlet>
        <servlet-name>GeneralSetup</servlet-name>
        <servlet-class>com.atp.Controllers.ManageGeneralSetup</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>GeneralSetup</servlet-name>
        <url-pattern>/GeneralSetup</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Clients</servlet-name>
        <servlet-class>com.atp.Controllers.ManageClients</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Clients</servlet-name>
        <url-pattern>/Clients</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Accounts</servlet-name>
        <servlet-class>com.atp.Controllers.ManageAccounts</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Accounts</servlet-name>
        <url-pattern>/Accounts</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Transactions</servlet-name>
        <servlet-class>com.atp.Controllers.ManageTransactions</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Transactions</servlet-name>
        <url-pattern>/Transactions</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Login</servlet-name>
        <servlet-class>com.atp.Controllers.Login</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Login</servlet-name>
        <url-pattern>/Login</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Logout</servlet-name>
        <servlet-class>com.atp.Controllers.Logout</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Logout</servlet-name>
        <url-pattern>/Logout</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>DockerIntegration</servlet-name>
        <servlet-class>com.atp.Controllers.DockerIntegration</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>DockerIntegration</servlet-name>
        <url-pattern>/DockerIntegration</url-pattern>
    </servlet-mapping>

</web-app>

Communication in Netty Nio java

I want to create a communication system with two clients and a server in Netty nio. More specifically, firstly, I want when two clietns are connected to send a true message from the server and after that to be able to echnage information between the two clients. I am using the code provided from this example. The code from ClientHandler:

public class ClientHandler extends ChannelInboundHandlerAdapter {
 public final Promise<Object> promise;
 public ClientHandler(Promise<Object> promise) {
    this.promise = promise;
 }
 @Override
 public void channelActive(ChannelHandlerContext ctx) throws Exception {
    RequestData msg = new RequestData();
    msg.setIntValue(123);
    msg.setStringValue("all work and no play makes jack a dull boy");
    ctx.writeAndFlush(msg);
 }

 @Override
 public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    System.out.println(msg);
    promise.trySuccess(msg);
    ctx.close();
 }
} 

The code for the server handler:

public class ProcessingHandler extends ChannelInboundHandlerAdapter {
 final ChannelGroup channels =
         new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
 @Override
 public void channelActive(ChannelHandlerContext ctx) throws Exception {
 }
 @Override
 public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
     RequestData requestData = (RequestData) msg;
     ResponseData responseData = new ResponseData();
     channels.add(ctx.channel());

     for (Channel ch : channels) {
         System.out.println(ch);
     }

     if(channels.size() == 2) {
         responseData.setIntValue(1);
         ChannelFuture future = ctx.writeAndFlush(responseData);
         future.addListener(ChannelFutureListener.CLOSE);
         System.out.println(requestData);
     }
     else {
         responseData.setIntValue(0);
         ChannelFuture future = ctx.writeAndFlush(responseData);
         future.addListener(ChannelFutureListener.CLOSE);
         System.out.println(requestData);
     }
 }
}

And the main code for the Client is:

public class NettyClient {
 public static void main(String[] args) throws Exception {
     String host = "localhost";
     int port = 8080;
     EventLoopGroup workerGroup = new NioEventLoopGroup();
     Promise<Object> promise = workerGroup.next().newPromise();

     try {
         Bootstrap b = new Bootstrap();
         b.group(workerGroup);
         b.channel(NioSocketChannel.class);
         b.option(ChannelOption.SO_KEEPALIVE, true);
         b.handler(new ChannelInitializer<SocketChannel>() {
             @Override
             public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new RequestDataEncoder(), new ResponseDataDecoder(), new ClientHandler(promise));
             }
         });

         ChannelFuture f = b.connect(host, port).sync();

         Object msg = promise.get();
         System.out.println(msg.toString());

         f.channel().closeFuture().sync();
     }
     finally {
         workerGroup.shutdownGracefully();
     }
 }
}

It seems that the channelRead in the serverHandler works when the first client is connceted so it always return 1 but when a second client is connected does not change to 2. How can I check properly from the server when both clients are connected to the server? How can I read this value dynamically from my main function of the Client? Then which is the best way to let both clients communicate?

How do I avoid using if statements with a large amount of variables in java

I am attempting to create a program that asks for the user to input the name of 6 items out of a large list. It then totals up all the attributes of said items and displays the total of all the attributes as well as the cost. The only way I can see doing this would require a huge amount of if and else if statements along with a for loop. With the amount of items I need to use it would be atleast 1000 lines long of if and else statements and that would take a whole lot of time to write out.

Here is a sample of my code

import java.util.Scanner;
public class MyProgram
{
public static void main(String[] args)
  {
    Scanner one = new Scanner(System.in);
    System.out.print("Champion: ");
    String champion = one.next();
    System.out.print("Item 1: ");
    String item1 = one.next();
    System.out.print("Item 2: ");
    String item2 = one.next();
    System.out.print("Item 3: ");
    String item3 = one.next();
    System.out.print("Item 4: ");
    String item4 = one.next();
    System.out.print("Item 5: ");
    String item5 = one.next();
    System.out.print("Item 6: ");
    String item6 = one.next();
    int totalhealth = 0;
    int totalad = 0;
    int totalap = 0;
    int totalarmor = 0;
    int totalmr = 0;
    int totalcdr = 0;
    int totalmana = 0;
    int totalcstr= 0;
    int totalls = 0;
    int totalatcksp = 0;
    int totalcost = 0;
    for(int i = 0; i < 6; i++)
    {
        int itemhealth = 0;
        int itemad = 0;
        int itemap = 0;
        int itemarmor = 0;
        int itemmr = 0;
        int itemcdr = 0;
        int itemmana = 0;
        int itemcstr = 0;
        int itemls = 0;
        int itematcksp = 0;
        int itemcost = 0;
        if(i == 0)
        {
            if(item1.equals("abyssal mask"))
        {
            itemhealth = 350;
            itemmana = 300;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2900;
        }
        else if (item1.equals("adaptive helm"))
        {
            itemhealth = 350;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2800;
        }
        else if (item1.equals("aegis of the legion"))
        {
            itemarmor = 30;
            itemmr = 30;
            itemcost = 1100;
        }
        else if (item1.equals("aether wisp"))
        {
            itemap = 30;
            itemcost = 850;
        }
        else if (item1.equals("amplifying tome"))
        {
         itemap = 20;
         itemcost = 435;
        }
        else if (item1.equals("ancient coin"))
        {
            itemcdr = 5;
            itemcost = 350;
        }
        else if (item1.equals("archangel's staff"))
        {
            itemap = 80;
            itemmana = 250;
            itemcost = 3100;
        }
        else if (item1.equals("ardent censer"))
        {
            itemap = 60;
            itemcdr = 10;
            itemcost = 2300;
        }
        else if (item1.equals("athene's unholy grail"))
        {
            itemap= 30;
            itemmr = 30;
            itemcdr = 10;
            itemcost = 2100;
        }
        else if (item1.equals("b.f.sword"))
        {
            itemad = 40;
            itemcost = 1300;
        }
        else if (item1.equals("bami's cinder"))
        {
            itemhealth = 200;
            itemcost = 900;
        }
    }
        if(i == 1)
    {
        if(item2.equals("abyssal mask"))
        {
            itemhealth = 350;
            itemmana = 300;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2900;
        }
        else if (item2.equals("adaptive helm"))
        {
            itemhealth = 350;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2800;
        }
        else if (item2.equals("aegis of the legion"))
        {
            itemarmor = 30;
            itemmr = 30;
            itemcost = 1100;
        }
        else if (item2.equals("aether wisp"))
        {
            itemap = 30;
            itemcost = 850;
        }
        else if (item2.equals("amplifying tome"))
        {
         itemap = 20;
         itemcost = 435;
        }
        else if (item2.equals("ancient coin"))
        {
            itemcdr = 5;
            itemcost = 350;
        }
        else if (item2.equals("archangel's staff"))
        {
            itemap = 80;
            itemmana = 250;
            itemcost = 3100;
        }
        else if (item2.equals("ardent censer"))
        {
            itemap = 60;
            itemcdr = 10;
            itemcost = 2300;
        }
        else if (item2.equals("athene's unholy grail"))
        {
            itemap= 30;
            itemmr = 30;
            itemcdr = 10;
            itemcost = 2100;
        }
        else if (item2.equals("b.f.sword"))
        {
            itemad = 40;
            itemcost = 1300;
        }
        else if (item2.equals("bami's cinder"))
        {
            itemhealth = 200;
            itemcost = 900;
        }

    }
    if(i == 2)
    {
        if(item3.equals("abyssal mask"))
        {
            itemhealth = 350;
            itemmana = 300;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2900;
        }
        else if (item3.equals("adaptive helm"))
        {
            itemhealth = 350;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2800;
        }
        else if (item3.equals("aegis of the legion"))
        {
            itemarmor = 30;
            itemmr = 30;
            itemcost = 1100;
        }
        else if (item3.equals("aether wisp"))
        {
            itemap = 30;
            itemcost = 850;
        }
        else if (item3.equals("amplifying tome"))
        {
         itemap = 20;
         itemcost = 435;
        }
        else if (item3.equals("ancient coin"))
        {
            itemcdr = 5;
            itemcost = 350;
        }
        else if (item3.equals("archangel's staff"))
        {
            itemap = 80;
            itemmana = 250;
            itemcost = 3100;
        }
        else if (item3.equals("ardent censer"))
        {
            itemap = 60;
            itemcdr = 10;
            itemcost = 2300;
        }
        else if (item3.equals("athene's unholy grail"))
        {
            itemap= 30;
            itemmr = 30;
            itemcdr = 10;
            itemcost = 2100;
        }
        else if (item3.equals("b.f.sword"))
        {
            itemad = 40;
            itemcost = 1300;
        }
        else if (item3.equals("bami's cinder"))
        {
            itemhealth = 200;
            itemcost = 900;
        }
    }
        if(i == 3)
    {
        if(item4.equals("abyssal mask"))
        {
            itemhealth = 350;
            itemmana = 300;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2900;
        }
        else if (item4.equals("adaptive helm"))
        {
            itemhealth = 350;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2800;
        }
        else if (item4.equals("aegis of the legion"))
        {
            itemarmor = 30;
            itemmr = 30;
            itemcost = 1100;
        }
        else if (item4.equals("aether wisp"))
        {
            itemap = 30;
            itemcost = 850;
        }
        else if (item4.equals("amplifying tome"))
        {
         itemap = 20;
         itemcost = 435;
        }
        else if (item4.equals("ancient coin"))
        {
            itemcdr = 5;
            itemcost = 350;
        }
        else if (item4.equals("archangel's staff"))
        {
            itemap = 80;
            itemmana = 250;
            itemcost = 3100;
        }
        else if (item4.equals("ardent censer"))
        {
            itemap = 60;
            itemcdr = 10;
            itemcost = 2300;
        }
        else if (item4.equals("athene's unholy grail"))
        {
            itemap= 30;
            itemmr = 30;
            itemcdr = 10;
            itemcost = 2100;
        }
        else if (item4.equals("b.f.sword"))
        {
            itemad = 40;
            itemcost = 1300;
        }
        else if (item4.equals("bami's cinder"))
        {
            itemhealth = 200;
            itemcost = 900;
        }
    }
        if(i == 4)
    {
        if(item5.equals("abyssal mask"))
        {
            itemhealth = 350;
            itemmana = 300;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2900;
        }
        else if (item5.equals("adaptive helm"))
        {
            itemhealth = 350;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2800;
        }
        else if (item5.equals("aegis of the legion"))
        {
            itemarmor = 30;
            itemmr = 30;
            itemcost = 1100;
        }
        else if (item5.equals("aether wisp"))
        {
            itemap = 30;
            itemcost = 850;
        }
        else if (item5.equals("amplifying tome"))
        {
         itemap = 20;
         itemcost = 435;
        }
        else if (item5.equals("ancient coin"))
        {
            itemcdr = 5;
            itemcost = 350;
        }
        else if (item5.equals("archangel's staff"))
        {
            itemap = 80;
            itemmana = 250;
            itemcost = 3100;
        }
        else if (item5.equals("ardent censer"))
        {
            itemap = 60;
            itemcdr = 10;
            itemcost = 2300;
        }
        else if (item5.equals("athene's unholy grail"))
        {
            itemap= 30;
            itemmr = 30;
            itemcdr = 10;
            itemcost = 2100;
        }
        else if (item5.equals("b.f.sword"))
        {
            itemad = 40;
            itemcost = 1300;
        }
        else if (item5.equals("bami's cinder"))
        {
            itemhealth = 200;
            itemcost = 900;
        }
    }
        if(i == 5)
    {
        if(item6.equals("abyssal mask"))
        {
            itemhealth = 350;
            itemmana = 300;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2900;
        }
        else if (item6.equals("adaptive helm"))
        {
            itemhealth = 350;
            itemmr = 55;
            itemcdr = 10;
            itemcost = 2800;
        }
        else if (item6.equals("aegis of the legion"))
        {
            itemarmor = 30;
            itemmr = 30;
            itemcost = 1100;
        }
        else if (item6.equals("aether wisp"))
        {
            itemap = 30;
            itemcost = 850;
        }
        else if (item6.equals("amplifying tome"))
        {
         itemap = 20;
         itemcost = 435;
        }
        else if (item6.equals("ancient coin"))
        {
            itemcdr = 5;
            itemcost = 350;
        }
        else if (item6.equals("archangel's staff"))
        {
            itemap = 80;
            itemmana = 250;
            itemcost = 3100;
        }
        else if (item6.equals("ardent censer"))
        {
            itemap = 60;
            itemcdr = 10;
            itemcost = 2300;
        }
        else if (item6.equals("athene's unholy grail"))
        {
            itemap= 30;
            itemmr = 30;
            itemcdr = 10;
            itemcost = 2100;
        }
        else if (item6.equals("b.f.sword"))
        {
            itemad = 40;
            itemcost = 1300;
        }
        else if (item6.equals("bami's cinder"))
        {
            itemhealth = 200;
            itemcost = 900;
        }
    }
System.out.println("Champion: " + champion);
System.out.println("Total health: " + totalhealth);
System.out.println("Total AD: " + totalad);
System.out.println("Total AP: " + totalap);
System.out.println("Total armor: " + totalarmor);
System.out.println("Total magic resist" + totalmr);
System.out.println("Total CDR: %" + totalcdr);
System.out.println("Total mana: " + totalmana);
System.out.println("Total Critical Strike Chance: " + totalcstr);
System.out.println("Total Life Steal: %" + totalls);
System.out.println("Total Attack Speed: " + totalatcksp);
System.out.println("Total Cost: " + totalcost + "g");


    }
  }
}

I am a highschool student on my first year of CS. This may have a simple answer that I am unaware of so I am open to all answers, even the most obvious.

API call Throwing error during verification in JAVA

I am try to make an API call with below code . I am able to print till “getMMHost();” in below code . After that , I get error as :

[java] org.apache.http.impl.client.ClientParamsStack@3e694b3f
[java] res  code  : 405
[java] java.lang.ArrayIndexOutOfBoundsException: 1
BUILD SUCCESSFUL

Code :

String url ="/api//sr?bid="+cluster+"&mode=1";
	System.out.println(url);  
	
	HttpHost httpHost = getMMHost();
	System.out.println(httpHost);  //(I am able to print till here )
	

	DefaultHttpClient httpclient = (DefaultHttpClient) verifiedClient(new DefaultHttpClient());
	
	
	HttpPost httpost = verifiedPost(url,user,password);
	
	HttpResponse response = httpclient.execute(httpHost, httpost);
	
	System.out.println(response.getParams());
	int respCode = response.getStatusLine().getStatusCode();

I aint sure if the info I have provided is enough . Can it be related to the SSL of httpClient ? DO I need to POST the URL and the credentials ? THis thing is driving me crazy .Any help is much appreciated .