问:
Unable to find a suitable main class, please add a 'mainClass' property, Spring boot
Hi friends i am developing a spring boot maven based project and and i have created a maven submodules but when i try to run my project it gives an error

```<code>[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project demo-jhipster: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project demo-jhipster: Unable to find a suitable main class, please add a 'mainClass' property
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
</code>```

my parent pom and child pom is

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>1.2.5.RELEASE</version>
        <relativePath />
    </parent>

    <groupId>com.aquevix.demo</groupId>
    <artifactId>demo-jhipster</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>demo_jhipster</name>

    <prerequisites>
        <maven>3.0.0</maven>
    </prerequisites>
    <modules>
        <module>JhipsterSubmodule</module>
    </modules>

    <properties>
        <assertj-core.version>3.1.0</assertj-core.version>
        <awaitility.version>1.4.0</awaitility.version>
        <commons-io.version>2.4</commons-io.version>
        <commons-lang.version>2.6</commons-lang.version>
        <gatling-maven-plugin.version>2.1.6</gatling-maven-plugin.version>
        <gatling.version>2.1.6</gatling.version>
        <hibernate.version>4.3.10.Final</hibernate.version>
        <hikaricp.version>2.4.0</hikaricp.version>
        <jacoco-maven-plugin.version>0.7.4.201502262128</jacoco-maven-plugin.version>
        <java.version>1.8</java.version>
        <javax.inject.version>1</javax.inject.version>
        <joda-time-hibernate.version>1.4</joda-time-hibernate.version>
        <liquibase-hibernate4.version>3.5</liquibase-hibernate4.version>
        <liquibase-slf4j.version>1.2.1</liquibase-slf4j.version>
        <liquibase.version>3.4.1</liquibase.version>
        <mapstruct.version>1.0.0.CR1</mapstruct.version>
        <maven-enforcer-plugin.version>1.3.1</maven-enforcer-plugin.version>
        <maven-sortpom-plugin.version>2.3.0</maven-sortpom-plugin.version>
        <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <metrics-spark-reporter.version>1.2</metrics-spark-reporter.version>
        <metrics-spring.version>3.1.2</metrics-spring.version>
        <!-- Sonar properties -->
        <project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
        <run.addResources>false</run.addResources>
        <sonar-maven-plugin.version>2.6</sonar-maven-plugin.version>
        <sonar.exclusions>src/main/webapp/assets/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/dist/**/*.*</sonar.exclusions>
        <sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
        <sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>

        <sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
        <sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>

        <sonar.sources>${project.basedir}/src/main/</sonar.sources>
        <sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
        <sonar.tests>${project.basedir}/src/test/</sonar.tests>
        <spring-security.version>4.0.2.RELEASE</spring-security.version>
        <springfox.version>2.0.3</springfox.version>
        <usertype-core.version>4.0.0.GA</usertype-core.version>

    </properties>

    <dependencies>
        // dependencies..
    </dependencies>
    <build>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>**/*.xml</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>com.google.code.sortpom</groupId>
                <artifactId>maven-sortpom-plugin</artifactId>
                <version>${maven-sortpom-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>sort</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sortProperties>true</sortProperties>
                    <nrOfIndentSpace>4</nrOfIndentSpace>
                    <sortDependencies>groupId,artifactId</sortDependencies>
                    <sortPlugins>groupId,artifactId</sortPlugins>
                    <keepBlankLines>true</keepBlankLines>
                    <expandEmptyElements>false</expandEmptyElements>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>${gatling-maven-plugin.version}</version>
                <configuration>
                    <configFolder>src/test/gatling/conf</configFolder>
                    <dataFolder>src/test/gatling/data</dataFolder>
                    <resultsFolder>target/gatling/results</resultsFolder>
                    <bodiesFolder>src/test/gatling/bodies</bodiesFolder>
                    <simulationsFolder>src/test/gatling/simulations</simulationsFolder>
                    <!-- This will force Gatling to ask which simulation to run
                      This is useful when you have multiple simulations -->
                    <simulationClass>*</simulationClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven-enforcer-plugin.version}</version>
                <executions>
                    <execution>
                        <id>enforce-versions</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <rules>
                        <requireMavenVersion>
                            <message>You are running an older version of Maven. JHipster requires at least Maven 3.0</message>
                            <version>[3.0.0,)</version>
                        </requireMavenVersion>
                        <requireJavaVersion>
                            <message>You are running an older version of Java. JHipster requires at least JDK ${java.version}</message>
                            <version>[${java.version}.0,)</version>
                        </requireJavaVersion>
                    </rules>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Xmx256m ${surefireArgLine}</argLine>
                    <!-- Force alphabetical order to have a reproducible build -->
                    <runOrder>alphabetical</runOrder>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.2.4</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <defaultOutputDirectory>${project.build.directory}/generated-sources</defaultOutputDirectory>
                    <processors>
                        <processor>org.mapstruct.ap.MappingProcessor</processor>
                    </processors>
                    <options>
                        <mapstruct.suppressGeneratorTimestamp>true</mapstruct.suppressGeneratorTimestamp>
                        <mapstruct.defaultComponentModel>spring</mapstruct.defaultComponentModel>
                    </options>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${sonar-maven-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>pre-unit-tests</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <destFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</destFile>
                            <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>
                    <!-- Ensures that the code coverage report for unit tests is created after unit tests have been run -->
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</dataFile>
                            <outputDirectory>${project.testresult.directory}/coverage/jacoco</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>${liquibase.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.javassist</groupId>
                        <artifactId>javassist</artifactId>
                        <version>3.18.2-GA</version>
                    </dependency>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate4</artifactId>
                        <version>${liquibase-hibernate4.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-jpa</artifactId>
                        <version>${project.parent.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                    <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
                    <driver />
                    <url />
                    <defaultSchemaName />
                    <username />
                    <password />
                    <referenceUrl>hibernate:spring:com.aquevix.demo.domain?dialect=</referenceUrl>
                    <verbose>true</verbose>
                    <logging>debug</logging>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
                    <arguments>
                        <argument>--spring.profiles.active=dev</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>fast</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <arguments>
                                <argument>--spring.profiles.active=dev,fast</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-undertow</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.trecloux</groupId>
                        <artifactId>yeoman-maven-plugin</artifactId>
                        <version>0.4</version>
                        <executions>
                            <execution>
                                <id>run-frontend-build</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <buildTool>grunt</buildTool>
                                    <buildArgs>build --force --no-color</buildArgs>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <yeomanProjectDirectory>${project.basedir}</yeomanProjectDirectory>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>2.5</version>
                        <configuration>
                            <filesets>
                                <fileset>                                       <directory>src/main/webapp/dist</directory>
                                </fileset>
                                <fileset>
                                    <directory>.tmp</directory>
                                </fileset>
                                <fileset>
                                    <directory>node_modules</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <arguments>
                                <argument>--spring.profiles.active=prod</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>INFO</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>
</code>```

and chile pom is

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>demo-jhipster</artifactId>
        <groupId>com.aquevix.demo</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>JhipsterSubmodule1</artifactId>
</project>
</code>```

I have googled but not found any solution please help in this regard!

答:
If you are using IntellJ IDEA, maybe you can do it like this:

```<code><plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>add.your.main.class.application.reference.here</mainClass>
    </configuration>
</plugin>
</code>```

This solved my error.

Body:
Hi friends i am developing a spring boot maven based project and and i have created a maven submodules but when i try to run my project it gives an error

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project demo-jhipster: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project demo-jhipster: Unable to find a suitable main class, please add a 'mainClass' property
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)

my parent pom and child pom is

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>1.2.5.RELEASE</version>
        <relativePath />
    </parent>

    <groupId>com.aquevix.demo</groupId>
    <artifactId>demo-jhipster</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>demo_jhipster</name>

    <prerequisites>
        <maven>3.0.0</maven>
    </prerequisites>
    <modules>
        <module>JhipsterSubmodule</module>
    </modules>

    <properties>
        <assertj-core.version>3.1.0</assertj-core.version>
        <awaitility.version>1.4.0</awaitility.version>
        <commons-io.version>2.4</commons-io.version>
        <commons-lang.version>2.6</commons-lang.version>
        <gatling-maven-plugin.version>2.1.6</gatling-maven-plugin.version>
        <gatling.version>2.1.6</gatling.version>
        <hibernate.version>4.3.10.Final</hibernate.version>
        <hikaricp.version>2.4.0</hikaricp.version>
        <jacoco-maven-plugin.version>0.7.4.201502262128</jacoco-maven-plugin.version>
        <java.version>1.8</java.version>
        <javax.inject.version>1</javax.inject.version>
        <joda-time-hibernate.version>1.4</joda-time-hibernate.version>
        <liquibase-hibernate4.version>3.5</liquibase-hibernate4.version>
        <liquibase-slf4j.version>1.2.1</liquibase-slf4j.version>
        <liquibase.version>3.4.1</liquibase.version>
        <mapstruct.version>1.0.0.CR1</mapstruct.version>
        <maven-enforcer-plugin.version>1.3.1</maven-enforcer-plugin.version>
        <maven-sortpom-plugin.version>2.3.0</maven-sortpom-plugin.version>
        <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <metrics-spark-reporter.version>1.2</metrics-spark-reporter.version>
        <metrics-spring.version>3.1.2</metrics-spring.version>

        <project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
        <run.addResources>false</run.addResources>
        <sonar-maven-plugin.version>2.6</sonar-maven-plugin.version>
        <sonar.exclusions>src/main/webapp/assets/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/dist/**/*.*</sonar.exclusions>
        <sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
        <sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>

        <sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
        <sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>

        <sonar.sources>${project.basedir}/src/main/</sonar.sources>
        <sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
        <sonar.tests>${project.basedir}/src/test/</sonar.tests>
        <spring-security.version>4.0.2.RELEASE</spring-security.version>
        <springfox.version>2.0.3</springfox.version>
        <usertype-core.version>4.0.0.GA</usertype-core.version>

    </properties>

    <dependencies>
        // dependencies..
    </dependencies>
    <build>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>**/*.xml</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>com.google.code.sortpom</groupId>
                <artifactId>maven-sortpom-plugin</artifactId>
                <version>${maven-sortpom-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>sort</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sortProperties>true</sortProperties>
                    <nrOfIndentSpace>4</nrOfIndentSpace>
                    <sortDependencies>groupId,artifactId</sortDependencies>
                    <sortPlugins>groupId,artifactId</sortPlugins>
                    <keepBlankLines>true</keepBlankLines>
                    <expandEmptyElements>false</expandEmptyElements>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>${gatling-maven-plugin.version}</version>
                <configuration>
                    <configFolder>src/test/gatling/conf</configFolder>
                    <dataFolder>src/test/gatling/data</dataFolder>
                    <resultsFolder>target/gatling/results</resultsFolder>
                    <bodiesFolder>src/test/gatling/bodies</bodiesFolder>
                    <simulationsFolder>src/test/gatling/simulations</simulationsFolder>

                    <simulationClass>*</simulationClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven-enforcer-plugin.version}</version>
                <executions>
                    <execution>
                        <id>enforce-versions</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <rules>
                        <requireMavenVersion>
                            <message>You are running an older version of Maven. JHipster requires at least Maven 3.0</message>
                            <version>[3.0.0,)</version>
                        </requireMavenVersion>
                        <requireJavaVersion>
                            <message>You are running an older version of Java. JHipster requires at least JDK ${java.version}</message>
                            <version>[${java.version}.0,)</version>
                        </requireJavaVersion>
                    </rules>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Xmx256m ${surefireArgLine}</argLine>

                    <runOrder>alphabetical</runOrder>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.2.4</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <defaultOutputDirectory>${project.build.directory}/generated-sources</defaultOutputDirectory>
                    <processors>
                        <processor>org.mapstruct.ap.MappingProcessor</processor>
                    </processors>
                    <options>
                        <mapstruct.suppressGeneratorTimestamp>true</mapstruct.suppressGeneratorTimestamp>
                        <mapstruct.defaultComponentModel>spring</mapstruct.defaultComponentModel>
                    </options>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${sonar-maven-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>pre-unit-tests</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>

                            <destFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</destFile>

                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</dataFile>
                            <outputDirectory>${project.testresult.directory}/coverage/jacoco</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>${liquibase.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.javassist</groupId>
                        <artifactId>javassist</artifactId>
                        <version>3.18.2-GA</version>
                    </dependency>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate4</artifactId>
                        <version>${liquibase-hibernate4.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-jpa</artifactId>
                        <version>${project.parent.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                    <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
                    <driver />
                    <url />
                    <defaultSchemaName />
                    <username />
                    <password />
                    <referenceUrl>hibernate:spring:com.aquevix.demo.domain?dialect=</referenceUrl>
                    <verbose>true</verbose>
                    <logging>debug</logging>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
                    <arguments>
                        <argument>--spring.profiles.active=dev</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>

                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>fast</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <arguments>
                                <argument>--spring.profiles.active=dev,fast</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>

                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-undertow</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.trecloux</groupId>
                        <artifactId>yeoman-maven-plugin</artifactId>
                        <version>0.4</version>
                        <executions>
                            <execution>
                                <id>run-frontend-build</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <buildTool>grunt</buildTool>
                                    <buildArgs>build --force --no-color</buildArgs>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <yeomanProjectDirectory>${project.basedir}</yeomanProjectDirectory>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>2.5</version>
                        <configuration>
                            <filesets>
                                <fileset>                                       <directory>src/main/webapp/dist</directory>
                                </fileset>
                                <fileset>
                                    <directory>.tmp</directory>
                                </fileset>
                                <fileset>
                                    <directory>node_modules</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <arguments>
                                <argument>--spring.profiles.active=prod</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>

                <logback.loglevel>INFO</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

and chile pom is

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>demo-jhipster</artifactId>
        <groupId>com.aquevix.demo</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>JhipsterSubmodule1</artifactId>
</project>

I have googled but not found any solution please help in this regard!

Body:
If you are using IntellJ IDEA, maybe you can do it like this:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>add.your.main.class.application.reference.here</mainClass>
    </configuration>
</plugin>

This solved my error.


来源: stackexchange

问:
How to take the DidFinishProcessingPhoto(from IAVCapturePhotoCaptureDelegate) responsibility out of the ViewController
I'm trying to create a single responsibility straight forward testable Ios based Class  that does one thin and one thing only: Start session(previewing it to the injected UIView) and handle saving photo to Photo Library.

I have the classes and interface below. I have a problem that I can't see how to solve: I can't make CapturingCamera implement IAVCapturePhotoCaptureDelegate because the DidFinishProcessingPhoto method is not triggered... the only way it can get called if I make the calling UIViewController implement IAVCapturePhotoCaptureDelegate and call DidFinishProcessingPhoto

But I don't like that because I would like to encapsulate it in the CapturingCamera class.

I'm not sure what I am missing here or if this is a xamarin limitation (I hope the problem is with me)

please share your knowledge, thanks

```<code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AVFoundation;
using CoreMedia;
using Foundation;
using UIKit;

namespace IosCameraLibrary2017
{
    public interface ICapturingCamera
    {
        AVCaptureSession CaptureSession { get; }
        AVCaptureDevice CaptureDevice { get; }
        AVCaptureDeviceInput CaptureDeviceInput { get; }
        AVCaptureVideoPreviewLayer PreviewLayer { get; }
        UIView View { get; }
        IAVCapturePhotoCaptureDelegate CaptureDelegate { get; }
        IntPtr Handle { get; }

        AVCaptureVideoPreviewLayer GetWorkingPreview();
        void TakePicture();

        void Dispose();
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AVFoundation;
using CoreFoundation;
using CoreMedia;
using CoreVideo;
using Foundation;
using Photos;
using UIKit;

namespace IosCameraLibrary2017
{
    public class CapturingCamera : ICapturingCamera
    {
        public AVCaptureSession CaptureSession { get; private set; }
        public AVCaptureDevice CaptureDevice { get; private set; }
        public AVCaptureDeviceInput CaptureDeviceInput { get; private set; }
        public AVCaptureVideoPreviewLayer PreviewLayer { get; private set; }
        public UIView View { get; private set; }
        public IAVCapturePhotoCaptureDelegate CaptureDelegate { get; private set; }

        public CapturingCamera(UIView view, IAVCapturePhotoCaptureDelegate captureDelegate)
        {
            CaptureSession = new AVCaptureSession();
            CaptureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video);
            CaptureDeviceInput = AVCaptureDeviceInput.FromDevice(CaptureDevice);
            View = view;
            CaptureDelegate = captureDelegate;
        }

        public AVCaptureVideoPreviewLayer GetWorkingPreview()
        {
            CaptureSession.AddInput(CaptureDeviceInput);
            CaptureSession.StartRunning();
            PreviewLayer = new AVCaptureVideoPreviewLayer(CaptureSession);
            PreviewLayer.Frame = View.Bounds;
            View.Layer.AddSublayer(PreviewLayer);
            return PreviewLayer;
        }

        public void TakePicture()
        {
            var output = new AVCapturePhotoOutput();
            CaptureSession.AddOutput(output);
            var settings = AVCapturePhotoSettings.Create();
            var previewPixelType = settings.AvailablePreviewPhotoPixelFormatTypes.First();

            var keys = new[]
            {
                new NSString("kCVPixelBufferPixelFormatTypeKey"),
                new NSString("kCVPixelBufferWidthKey"),
                new NSString("kCVPixelBufferHeightKey"),
            };

            var objects = new NSObject[]
            {
                // don't have to be strings... can be any NSObject.
                previewPixelType,
                new NSString("160"),
                new NSString("160")
            };

            var dicionary = new NSDictionary<NSString, NSObject>(keys, objects);

            //settings.PreviewPhotoFormat = dicionary;
            settings.PreviewPhotoFormat = new NSDictionary<NSString, NSObject>(CVPixelBuffer.PixelFormatTypeKey, settings.AvailablePreviewPhotoPixelFormatTypes[0]);

            output.CapturePhoto(settings, CaptureDelegate);
        }

        public IntPtr Handle { get; }
        public void Dispose()
        {
            //
        }
    }
}

using System;
using System.Linq;
using AVFoundation;
using CoreMedia;
using CoreVideo;
using Foundation;
using IosCameraLibrary2017;
using Photos;
using UIKit;

namespace XamarinIosTry2
{
    public partial class ViewController : UIViewController, IAVCapturePhotoCaptureDelegate
    {
        private ICapturingCamera cameraManager;

        public ViewController(IntPtr handle) : base(handle){}

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (!AppDelegate.IsDesignTime)
            {
                cameraManager = new CapturingCamera(viewCamera,this);
                cameraManager.GetWorkingPreview();
            }
        }

        [Export(
            "captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error:")]
        public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput,
            CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer,
            AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings,
            NSError error)
        {
            if (photoSampleBuffer == null)
            {
                Console.WriteLine($"Error occurred while capturing photo: {error}");
                return;
            }

            NSData imageData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer);
            PHPhotoLibrary.RequestAuthorization(status =>
            {
                if (status == PHAuthorizationStatus.Authorized)
                {
                    PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() =>
                    {
                        PHAssetCreationRequest.CreationRequestForAsset().AddResource(PHAssetResourceType.Photo, imageData, null);
                    }, (success, err) =>
                    {
                        if (!success)
                        {
                            Console.WriteLine($"Error occurred while saving photo to photo library: {err}");
                        }
                        else
                        {
                            Console.WriteLine("Photo was saved to photo library");
                        }
                    });
                }
                else
                {
                    Console.WriteLine("Not authorized to save photo");
                }
            });
        }

        partial void BtnAction_TouchUpInside(UIButton sender)
        {
            cameraManager.TakePicture();
        }

    }
}
</code>```

答:
Subclassing AVCapturePhotoCaptureDelegate should work fine:

```<code>public class CapturingCamera : AVCapturePhotoCaptureDelegate, ICapturingCamera
{
    // Implement your ICapturingCamera interface methods...

    public override void DidFinishProcessingPhoto(AVCapturePhotoOutput output, AVCapturePhoto photo, NSError error)
    {
       ~~~
    }
}
</code>```

Then in your call AVCapturePhotoOutput.CapturePhoto inside your CapturingCamera instance pass it this for the delegate.

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to create a single responsibility straight forward testable Ios based Class  that does one thin and one thing only: Start session(previewing it to the injected UIView) and handle saving photo to Photo Library.

I have the classes and interface below. I have a problem that I can't see how to solve: I can't make CapturingCamera implement IAVCapturePhotoCaptureDelegate because the DidFinishProcessingPhoto method is not triggered... the only way it can get called if I make the calling UIViewController implement IAVCapturePhotoCaptureDelegate and call DidFinishProcessingPhoto

But I don't like that because I would like to encapsulate it in the CapturingCamera class.

I'm not sure what I am missing here or if this is a xamarin limitation (I hope the problem is with me)

please share your knowledge, thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AVFoundation;
using CoreMedia;
using Foundation;
using UIKit;

namespace IosCameraLibrary2017
{
    public interface ICapturingCamera
    {
        AVCaptureSession CaptureSession { get; }
        AVCaptureDevice CaptureDevice { get; }
        AVCaptureDeviceInput CaptureDeviceInput { get; }
        AVCaptureVideoPreviewLayer PreviewLayer { get; }
        UIView View { get; }
        IAVCapturePhotoCaptureDelegate CaptureDelegate { get; }
        IntPtr Handle { get; }

        AVCaptureVideoPreviewLayer GetWorkingPreview();
        void TakePicture();

        void Dispose();
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AVFoundation;
using CoreFoundation;
using CoreMedia;
using CoreVideo;
using Foundation;
using Photos;
using UIKit;

namespace IosCameraLibrary2017
{
    public class CapturingCamera : ICapturingCamera
    {
        public AVCaptureSession CaptureSession { get; private set; }
        public AVCaptureDevice CaptureDevice { get; private set; }
        public AVCaptureDeviceInput CaptureDeviceInput { get; private set; }
        public AVCaptureVideoPreviewLayer PreviewLayer { get; private set; }
        public UIView View { get; private set; }
        public IAVCapturePhotoCaptureDelegate CaptureDelegate { get; private set; }

        public CapturingCamera(UIView view, IAVCapturePhotoCaptureDelegate captureDelegate)
        {
            CaptureSession = new AVCaptureSession();
            CaptureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video);
            CaptureDeviceInput = AVCaptureDeviceInput.FromDevice(CaptureDevice);
            View = view;
            CaptureDelegate = captureDelegate;
        }

        public AVCaptureVideoPreviewLayer GetWorkingPreview()
        {
            CaptureSession.AddInput(CaptureDeviceInput);
            CaptureSession.StartRunning();
            PreviewLayer = new AVCaptureVideoPreviewLayer(CaptureSession);
            PreviewLayer.Frame = View.Bounds;
            View.Layer.AddSublayer(PreviewLayer);
            return PreviewLayer;
        }

        public void TakePicture()
        {
            var output = new AVCapturePhotoOutput();
            CaptureSession.AddOutput(output);
            var settings = AVCapturePhotoSettings.Create();
            var previewPixelType = settings.AvailablePreviewPhotoPixelFormatTypes.First();

            var keys = new[]
            {
                new NSString("kCVPixelBufferPixelFormatTypeKey"),
                new NSString("kCVPixelBufferWidthKey"),
                new NSString("kCVPixelBufferHeightKey"),
            };

            var objects = new NSObject[]
            {
                // don't have to be strings... can be any NSObject.
                previewPixelType,
                new NSString("160"),
                new NSString("160")
            };

            var dicionary = new NSDictionary<NSString, NSObject>(keys, objects);

            //settings.PreviewPhotoFormat = dicionary;
            settings.PreviewPhotoFormat = new NSDictionary<NSString, NSObject>(CVPixelBuffer.PixelFormatTypeKey, settings.AvailablePreviewPhotoPixelFormatTypes[0]);

            output.CapturePhoto(settings, CaptureDelegate);
        }

        public IntPtr Handle { get; }
        public void Dispose()
        {
            //
        }
    }
}

using System;
using System.Linq;
using AVFoundation;
using CoreMedia;
using CoreVideo;
using Foundation;
using IosCameraLibrary2017;
using Photos;
using UIKit;

namespace XamarinIosTry2
{
    public partial class ViewController : UIViewController, IAVCapturePhotoCaptureDelegate
    {
        private ICapturingCamera cameraManager;

        public ViewController(IntPtr handle) : base(handle){}

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (!AppDelegate.IsDesignTime)
            {
                cameraManager = new CapturingCamera(viewCamera,this);
                cameraManager.GetWorkingPreview();
            }
        }

        [Export(
            "captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error:")]
        public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput,
            CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer,
            AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings,
            NSError error)
        {
            if (photoSampleBuffer == null)
            {
                Console.WriteLine($"Error occurred while capturing photo: {error}");
                return;
            }

            NSData imageData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer);
            PHPhotoLibrary.RequestAuthorization(status =>
            {
                if (status == PHAuthorizationStatus.Authorized)
                {
                    PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() =>
                    {
                        PHAssetCreationRequest.CreationRequestForAsset().AddResource(PHAssetResourceType.Photo, imageData, null);
                    }, (success, err) =>
                    {
                        if (!success)
                        {
                            Console.WriteLine($"Error occurred while saving photo to photo library: {err}");
                        }
                        else
                        {
                            Console.WriteLine("Photo was saved to photo library");
                        }
                    });
                }
                else
                {
                    Console.WriteLine("Not authorized to save photo");
                }
            });
        }

        partial void BtnAction_TouchUpInside(UIButton sender)
        {
            cameraManager.TakePicture();
        }

    }
}

Body:
Subclassing AVCapturePhotoCaptureDelegate should work fine:

public class CapturingCamera : AVCapturePhotoCaptureDelegate, ICapturingCamera
{
    // Implement your ICapturingCamera interface methods...

    public override void DidFinishProcessingPhoto(AVCapturePhotoOutput output, AVCapturePhoto photo, NSError error)
    {
       ~~~
    }
}

Then in your call AVCapturePhotoOutput.CapturePhoto inside your CapturingCamera instance pass it this for the delegate.


问:
Set properties of multiple QLineEdit using a loop
I was wondering if it is possible to set multiple setFixedHeight() properties using a for loop:

```<code>for num in range(1, 6):
    self.LineEdit[num].setFixedHeight()
</code>```

currently I have twelve QLineEdit boxes

LineEdit1, LineEdit2, ... , LineEdit12 and I'm hoping to do this with less code. I tried the above method, and it did not iterate through the LineEdit boxes as I had expected. Would self.LineEdit[num] only work for a list?

答:
You may use findChildren() function.

e.g.

```<code>for ctl in self.findChildren(QtGui.QLineEdit):
    ctl.setFixedHeight()
</code>```

Please note this will call setFixedHeight() on all Line Edits.

Body:
I was wondering if it is possible to set multiple setFixedHeight() properties using a for loop:

for num in range(1, 6):
    self.LineEdit[num].setFixedHeight()

currently I have twelve QLineEdit boxes

LineEdit1, LineEdit2, ... , LineEdit12 and I'm hoping to do this with less code. I tried the above method, and it did not iterate through the LineEdit boxes as I had expected. Would self.LineEdit[num] only work for a list?

Body:
You may use findChildren() function.

e.g.

for ctl in self.findChildren(QtGui.QLineEdit):
    ctl.setFixedHeight()

Please note this will call setFixedHeight() on all Line Edits.


问:
Why doesn't this code work? Combination of for and if for a "test" login page
I'm trying to make some kind of login page (I don't care about security or some sort. This is a test, and I'm not even that advanced of a coder. And I'm struggling with the coding. I want to make it as:

```<code>    If the username was filled in as "Ardent" and the password as "1",
        Say something like "Welcome!"
    If the username or(and) the password are(is) incorrect,
        alert("The username and password is incorrect.");
and make it loop, leading to asking for username and password again.
</code>```

So, this is what I coded (I could not find out how this can work, so I don't even have the basic structure of it).

```<code>for([id == prompt("What is your ID?"), password == prompt("What is your password?")];
     id == "Ardent" || password == "1" ;) {

    prompt("What is your ID?");
    prompt("What is your password?");
    if(id == "Ardent" || password == "1") {
        alert("Welcome back!");
    }
}
</code>```

Thank you!
Sorry if it is actually a complete mess :(
I'm so bad at coding and I'm just a beginner.

答:
Javascript 'prompts' return a String or false if empty, so a variable has to be assigned like so...

```<code>var id = prompt("What is your ID?");
var password = prompt("What is your password?");
if (id == "Ardent" || password == "1") {
    alert("Welcome back!");
}
</code>```

As far as I can tell from the code example provided the 'for-loop' is superfluous to requirements.

For completeness, it is best to check that the required String is actually returned from a prompt() before proceeding, so something like this is usually undertaken...

```<code>/* declare variables before setting */
var id, password;

/* prompt for id with default string */
id = prompt(
    'What is your ID?',
    'Enter ID here...'
);

/* check if correct value is returned */
if (id === 'Ardent') {
    /* prompt for password with default string */
    password = prompt(
        'What is your password?',
        'Enter PASSWORD here...'
    );

    /* check if correct value is returned */
    if (password === '1') {
        alert('Welcome Back!');
    } else {
        /* handle incorrect password */
    }

} else {
    /* handle incorrect id  */
}
</code>```

I hope that helps.

See MDN for more info on prompt()

Body:
I'm trying to make some kind of login page (I don't care about security or some sort. This is a test, and I'm not even that advanced of a coder. And I'm struggling with the coding. I want to make it as:

    If the username was filled in as "Ardent" and the password as "1",
        Say something like "Welcome!"
    If the username or(and) the password are(is) incorrect,
        alert("The username and password is incorrect.");
and make it loop, leading to asking for username and password again.

So, this is what I coded (I could not find out how this can work, so I don't even have the basic structure of it).

for([id == prompt("What is your ID?"), password == prompt("What is your password?")];
     id == "Ardent" || password == "1" ;) {

    prompt("What is your ID?");
    prompt("What is your password?");
    if(id == "Ardent" || password == "1") {
        alert("Welcome back!");
    }
}

Thank you!
Sorry if it is actually a complete mess :(
I'm so bad at coding and I'm just a beginner.

Body:
Javascript 'prompts' return a String or false if empty, so a variable has to be assigned like so...

var id = prompt("What is your ID?");
var password = prompt("What is your password?");
if (id == "Ardent" || password == "1") {
    alert("Welcome back!");
}

As far as I can tell from the code example provided the 'for-loop' is superfluous to requirements.

For completeness, it is best to check that the required String is actually returned from a prompt() before proceeding, so something like this is usually undertaken...

/* declare variables before setting */
var id, password;

/* prompt for id with default string */
id = prompt(
    'What is your ID?',
    'Enter ID here...'
);

/* check if correct value is returned */
if (id === 'Ardent') {
    /* prompt for password with default string */
    password = prompt(
        'What is your password?',
        'Enter PASSWORD here...'
    );

    /* check if correct value is returned */
    if (password === '1') {
        alert('Welcome Back!');
    } else {
        /* handle incorrect password */
    }

} else {
    /* handle incorrect id  */
}

I hope that helps.

See MDN for more info on prompt()


问:
Is it possible to clear/remove TapGestureRecognizer after tapped event in Xamarin Forms?
I tried to apply this Image to be like ImageButton. Then I want to disable it after Tapped/Clicked event. By the way, I got some problems that I cannot Clear/Remove GestureRecognizers in Tapped event.

This is my code:

```<code>Image img = new Image { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.End, Source = ImageSource.FromResource("Ns.ico.png") };

var tapImg = new TapGestureRecognizer();

tapImg.Tapped += (object sender, EventArgs e) =>
{
     img.Source = ImageSource.FromResource("Ns.ico_disable.png");
     img.GestureRecognizers.Clear; //<--- this line is problem
};

img.GestureRecognizers.Add(tapImg);
</code>```

How should I solve this problem but still the same purpose?

答:
Clear is a method call so your code should be img.GestureRecognizers.Clear();

Or you could make a Tapped method and unsubscribe from it when tapped

```<code>tapImg.Tapped += Gesture_Tapped;

void Gesture_Tapped(object sender, EventArgs e)
{
    tapImg.Tapped -= Gesture_Tapped;
}
</code>```

Body:
I tried to apply this Image to be like ImageButton. Then I want to disable it after Tapped/Clicked event. By the way, I got some problems that I cannot Clear/Remove GestureRecognizers in Tapped event.

This is my code:

Image img = new Image { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.End, Source = ImageSource.FromResource("Ns.ico.png") };

var tapImg = new TapGestureRecognizer();

tapImg.Tapped += (object sender, EventArgs e) =>
{
     img.Source = ImageSource.FromResource("Ns.ico_disable.png");
     img.GestureRecognizers.Clear; //<--- this line is problem
};

img.GestureRecognizers.Add(tapImg);

How should I solve this problem but still the same purpose?

Body:
Clear is a method call so your code should be img.GestureRecognizers.Clear();

Or you could make a Tapped method and unsubscribe from it when tapped

tapImg.Tapped += Gesture_Tapped;

void Gesture_Tapped(object sender, EventArgs e)
{
    tapImg.Tapped -= Gesture_Tapped;
}


答:
for this task you can use getattr():

```<code>for i in range(1,13):
    getattr(self, "LineEdit{}".format(i)).setFixedHeight(10)
</code>```

Title: Set properties of multiple QLineEdit using a loop

Body:
for this task you can use getattr():

for i in range(1,13):
    getattr(self, "LineEdit{}".format(i)).setFixedHeight(10)


问:
No provider for NavController! Ionic 3
I'm Using Ionic3 for my university project , I had added setting parts of my app.html and trying to link (click)="home()" but it's not working for me.

I got following error

Error: No provider for NavController!
      at injectionError (http://localhost:8100/build/vendor.js:1527:90)
      at noProviderError (http://localhost:8100/build/vendor.js:1565:12)
      at ReflectiveInjector_.throwOrNull (http://localhost:8100/build/vendor.js:3007:19)
      at ReflectiveInjector.getByKeyDefault (http://localhost:8100/build/vendor.js:3046:25)
      at ReflectiveInjector.getByKey (http://localhost:8100/build/vendor.js:2978:25)
      at ReflectiveInjector.get (http://localhost:8100/build/vendor.js:2847:21)
      at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9847:25)
      at NgModuleRef_.get (http://localhost:8100/build/vendor.js:10935:16)
      at resolveDep (http://localhost:8100/build/vendor.js:11438:45)
      at createClass (http://localhost:8100/build/vendor.js:11302:32)

app.html

```<code><!--------------------------------------Main Navigation--------------------------->

<ion-menu id="myMenu" [content]="content" side="right" persistent="true" [class]="selectedTheme">
  <ion-header>
    <ion-toolbar>
      <ion-grid>

        <ion-row>
          <ion-col col-6>
            <div text-left style="" class="app-listname">
              Project</div>
          </ion-col>
          <ion-col  (click)="home()">
            <div class="tether-setting" style="text-align: right;font-size: 2rem; color:#a57958;">
              <ion-icon ios="ios-settings-outline" md="md-settings"></ion-icon>
            </div>

          </ion-col>
          <ion-col>
            <div class="tether-logout" style="font-size: 2rem; color:#a57958; text-indent: 0rem;  text-align: right;">
              <ion-icon ios="ios-log-out" md="md-log-out"></ion-icon>
            </div>
          </ion-col>
        </ion-row>
      </ion-grid>

    </ion-toolbar>
  </ion-header>

  <ion-content>
    <div class="ion-tm">
      <ion-list>
        <button menuClose ion-item *ngFor="let p of pages" [class.activeHighlight]="checkActive(p)" (click)="openPage(p)">
          <ion-icon [name]="p.icon" item-left></ion-icon>{{p.title}}</button>

      </ion-list>
    </div>
  </ion-content>

</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" [class]="selectedTheme"></ion-nav>
<!--------------------------------------Main Navigation--------------------------->
</code>```

app.component.ts

```<code>   import {Component, ViewChild} from '@angular/core';
import {Nav, Platform,NavController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';

import {HomePage} from '../pages/home/home';

import {SettingsPage} from "../pages/settings/settings";
import {HelpPage} from "../pages/help/help";

import {UserloginslidePage} from "../pages/userloginslide/userloginslide";
import {SettingsProvider} from "../providers/settings/settings";
import {ModalPage} from "../pages/modal/modal";
@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Nav) nav: Nav;
  rootPage: any = UserloginPage;
  selectedTheme: String;  //Themeoption
  activepage: any;
  pages: Array<{ title: string, component: any, icon: string }>;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
    this.settings.getActiveTheme().subscribe(val => this.selectedTheme = val);  //Themeoption

    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

    this.pages = [

      {title: 'Dashboard', component: HomePage, icon: "ios-home-outline"},

      {title: 'Settings', component: SettingsPage, icon: "ios-settings-outline"},
      {title: 'Help', component: HelpPage, icon: "ios-help-circle-outline"},
      {title: '  User loginslide ', component:UserloginslidePage, icon: "ios-contact-outline"},

    ];

    this.activepage = this.pages[0];
  }

  //Themeoption
  openPage(page) {

    this.nav.setRoot(page.component);
    this.activepage = page;

  }
  checkActive(page) {
    return page == this.activepage;
  }

  home(){
    this.navCtrl.push(HomePage);
  }
}
</code>```

答:
Try using getActiveNav()

Like this,

```<code>import {App} from 'ionic-angular';

constructor(public app: App){}

login() {
    this.app.getActiveNav().setRoot(Home);
}
</code>```

Title: No provider for NavController! Ionic 3

Body:
I'm Using Ionic3 for my university project , I had added setting parts of my app.html and trying to link (click)="home()" but it's not working for me.

I got following error

Error: No provider for NavController!
      at injectionError (http://localhost:8100/build/vendor.js:1527:90)
      at noProviderError (http://localhost:8100/build/vendor.js:1565:12)
      at ReflectiveInjector_.throwOrNull (http://localhost:8100/build/vendor.js:3007:19)
      at ReflectiveInjector.getByKeyDefault (http://localhost:8100/build/vendor.js:3046:25)
      at ReflectiveInjector.getByKey (http://localhost:8100/build/vendor.js:2978:25)
      at ReflectiveInjector.get (http://localhost:8100/build/vendor.js:2847:21)
      at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9847:25)
      at NgModuleRef_.get (http://localhost:8100/build/vendor.js:10935:16)
      at resolveDep (http://localhost:8100/build/vendor.js:11438:45)
      at createClass (http://localhost:8100/build/vendor.js:11302:32)

app.html

<ion-menu id="myMenu" [content]="content" side="right" persistent="true" [class]="selectedTheme">
  <ion-header>
    <ion-toolbar>
      <ion-grid>

        <ion-row>
          <ion-col col-6>

              Project

          </ion-col>
          <ion-col  (click)="home()">

              <ion-icon ios="ios-settings-outline" md="md-settings"></ion-icon>

          </ion-col>
          <ion-col>

              <ion-icon ios="ios-log-out" md="md-log-out"></ion-icon>

          </ion-col>
        </ion-row>
      </ion-grid>

    </ion-toolbar>
  </ion-header>

  <ion-content>

      <ion-list>
        <button menuClose ion-item *ngFor="let p of pages" [class.activeHighlight]="checkActive(p)" (click)="openPage(p)">
          <ion-icon [name]="p.icon" item-left></ion-icon>{{p.title}}</button>

      </ion-list>

  </ion-content>

</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" [class]="selectedTheme"></ion-nav>

app.component.ts

   import {Component, ViewChild} from '@angular/core';
import {Nav, Platform,NavController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';

import {HomePage} from '../pages/home/home';

import {SettingsPage} from "../pages/settings/settings";
import {HelpPage} from "../pages/help/help";

import {UserloginslidePage} from "../pages/userloginslide/userloginslide";
import {SettingsProvider} from "../providers/settings/settings";
import {ModalPage} from "../pages/modal/modal";
@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Nav) nav: Nav;
  rootPage: any = UserloginPage;
  selectedTheme: String;  //Themeoption
  activepage: any;
  pages: Array<{ title: string, component: any, icon: string }>;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
    this.settings.getActiveTheme().subscribe(val => this.selectedTheme = val);  //Themeoption

    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

    this.pages = [

      {title: 'Dashboard', component: HomePage, icon: "ios-home-outline"},

      {title: 'Settings', component: SettingsPage, icon: "ios-settings-outline"},
      {title: 'Help', component: HelpPage, icon: "ios-help-circle-outline"},
      {title: '  User loginslide ', component:UserloginslidePage, icon: "ios-contact-outline"},

    ];

    this.activepage = this.pages[0];
  }

  //Themeoption
  openPage(page) {

    this.nav.setRoot(page.component);
    this.activepage = page;

  }
  checkActive(page) {
    return page == this.activepage;
  }

  home(){
    this.navCtrl.push(HomePage);
  }
}

Body:
Try using getActiveNav()

Like this,

import {App} from 'ionic-angular';

constructor(public app: App){}

login() {
    this.app.getActiveNav().setRoot(Home);
}


问:
Could not find class 'android.graphics.drawable.RippleDrawable;
I tried to run it on my phone (SdkVersion 18) but It runs fine in SdkVersion
 20 or late .Can't figure out where is mistake here...</p>

```<code>Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
 FATAL EXCEPTION: main
                                                                   android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                                                                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                       at chaos.tech.suppertest.base.StorageExpandAdapter.getGroupView(StorageExpandAdapter.java:80)
                                                                       at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
                                                                       at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
                                                                       at android.widget.AbsListView.obtainView(AbsListView.java:2181)
                                                                       at android.widget.ListView.makeAndAddView(ListView.java:1880)
                                                                       at android.widget.ListView.fillDown(ListView.java:687)
                                                                       at android.widget.ListView.fillDown(ListView.java:666)
                                                                       at android.widget.ListView.fillFromTop(ListView.java:758)
                                                                       at android.widget.ListView.layoutChildren(ListView.java:1695)
                                                                       at android.widget.AbsListView.onLayout(AbsListView.java:2016)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
                                                                       at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                       at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1389)
                                                                       at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:868)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                                                                       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
                                                                       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                                                                       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
                                                                       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1984)
                                                                       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1738)
                                                                       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)
                                                                       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5508)
                                                                       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
                                                                       at android.view.Choreographer.doCallbacks(Choreographer.java:562)
                                                                       at android.view.Choreographer.doFrame(Choreographer.java:532)
                                                                       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
                                                                       at android.os.Handler.handleCallback(Handler.java:730)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                    at android.os.Looper.loop(Looper.java:
</code>```

答:
Ripple effect works only on sdk 21+ therefore you can put a condition to check if mobile sdk is 21+ or not and accordingly you can add the effect.

```<code>private void setRippleEffect(){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            your_button_id.setBackgroundDrawable(getResources().getDrawable(R.drawable.you_ripple_effect));
        }
    }
</code>```

Body:
I tried to run it on my phone (SdkVersion 18) but It runs fine in SdkVersion
 20 or late .Can't figure out where is mistake here...

Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
 FATAL EXCEPTION: main
                                                                   android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                                                                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                       at chaos.tech.suppertest.base.StorageExpandAdapter.getGroupView(StorageExpandAdapter.java:80)
                                                                       at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
                                                                       at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
                                                                       at android.widget.AbsListView.obtainView(AbsListView.java:2181)
                                                                       at android.widget.ListView.makeAndAddView(ListView.java:1880)
                                                                       at android.widget.ListView.fillDown(ListView.java:687)
                                                                       at android.widget.ListView.fillDown(ListView.java:666)
                                                                       at android.widget.ListView.fillFromTop(ListView.java:758)
                                                                       at android.widget.ListView.layoutChildren(ListView.java:1695)
                                                                       at android.widget.AbsListView.onLayout(AbsListView.java:2016)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
                                                                       at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                       at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1389)
                                                                       at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:868)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                                                                       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
                                                                       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                                                                       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
                                                                       at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
                                                                       at android.view.View.layout(View.java:14471)
                                                                       at android.view.ViewGroup.layout(ViewGroup.java:4562)
                                                                       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1984)
                                                                       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1738)
                                                                       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)
                                                                       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5508)
                                                                       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
                                                                       at android.view.Choreographer.doCallbacks(Choreographer.java:562)
                                                                       at android.view.Choreographer.doFrame(Choreographer.java:532)
                                                                       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
                                                                       at android.os.Handler.handleCallback(Handler.java:730)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                    at android.os.Looper.loop(Looper.java:

Body:
Ripple effect works only on sdk 21+ therefore you can put a condition to check if mobile sdk is 21+ or not and accordingly you can add the effect.

private void setRippleEffect(){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            your_button_id.setBackgroundDrawable(getResources().getDrawable(R.drawable.you_ripple_effect));
        }
    }


问:
Codename One Drag & Drop blackens dialog background
I'm developing an app that uses drag & drop operations. The drag & drop part includes four containers as drop targets and two draggable labels.

The app works as expected in the simulator, but when I install it on my Android phone, the background of the dialog (otherwise white) turns black for a swift moment as soon as the draggable components (labels) are released (then gets back to the original light color).

In the theme builder, I have set the background of the dialog to an almost white color (unselected, selected, pressed, disabled), but that doesn't show any effect.

Is there any turnaround to keep the background color stable? Any help would be appreciated.

Here is the relevant code excerpt:

```<code>        Dialog dialog_W1 = new Dialog();
        dialog_W1.setScrollableY(true);
        dialog_W1.setLayout(new BoxLayout(2));
        dialog_W1.setScrollableY(true);
        dialog_W1.setTitle("Acerte o bichinho");

        Image img_Cat = Image.createImage("/cat.png");
        ScaleImageLabel label_Scaled_Image = new ScaleImageLabel(img_Cat);
        label_Scaled_Image.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
        label_Scaled_Image.setUIID("NewLabel");

        Label label_1 = new Label("ga");
        Label label_2 = new Label("to");

        label_1.setUIID("LabelWord");
        label_2.setUIID("LabelWord");

        label_1.setDraggable(true);
        label_2.setDraggable(true);

        Container c_1 = new Container();
        Container c_2 = new Container();
        Container c_3 = new Container();
        Container c_4 = new Container();

        c_1.setDropTarget(true);
        c_2.setDropTarget(true);
        c_3.setDropTarget(true);
        c_4.setDropTarget(true);

        c_1.setLayout(new BoxLayout(2));
        c_2.setLayout(new BoxLayout(2));
        c_3.setLayout(new BoxLayout(2));
        c_4.setLayout(new BoxLayout(2));

        c_1.setUIID("Container_1");
        c_2.setUIID("Container_1");
        c_3.setUIID("Container_2");
        c_4.setUIID("Container_2");

        c_3.add(label_2);
        c_4.add(label_1);

        GridLayout gl = new GridLayout(2,2);
        Container container_0 = new Container(gl);
        container_0.add(c_1);
        container_0.add(c_2);
        container_0.add(c_3);
        container_0.add(c_4);

        ArrayList <Container> list_Containers = new ArrayList<>();
        list_Containers.add(c_1);
        list_Containers.add(c_2);
        list_Containers.add(c_3);
        list_Containers.add(c_4);

        ArrayList <Label> list_Labels = new ArrayList<>();
        list_Labels.add(label_1);
        list_Labels.add(label_2);

        for (Label label : list_Labels) {
            label.addDragOverListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    for (Container c : list_Containers) {
                        int int_C = c.getComponentCount();
                        if (int_C == 1) {
                            c.setDropTarget(false);
                        } else if (int_C == 0) {
                            c.setDropTarget(true);
                        }
                    }
                }
            });
        }
</code>```

答:
I suggest showing the Dialog as a modless dialog instead of using the show method use showModless() or similar.

Odd things like this can happen because of the EDT nesting inherent in modal dialogs, normally we don't recommend using dialog for anything more than simple notifications. When we use drag and drop from a dialog like component we use InteractionDialog.

Body:
I'm developing an app that uses drag & drop operations. The drag & drop part includes four containers as drop targets and two draggable labels.

The app works as expected in the simulator, but when I install it on my Android phone, the background of the dialog (otherwise white) turns black for a swift moment as soon as the draggable components (labels) are released (then gets back to the original light color).

In the theme builder, I have set the background of the dialog to an almost white color (unselected, selected, pressed, disabled), but that doesn't show any effect.

Is there any turnaround to keep the background color stable? Any help would be appreciated.

Here is the relevant code excerpt:

        Dialog dialog_W1 = new Dialog();
        dialog_W1.setScrollableY(true);
        dialog_W1.setLayout(new BoxLayout(2));
        dialog_W1.setScrollableY(true);
        dialog_W1.setTitle("Acerte o bichinho");

        Image img_Cat = Image.createImage("/cat.png");
        ScaleImageLabel label_Scaled_Image = new ScaleImageLabel(img_Cat);
        label_Scaled_Image.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
        label_Scaled_Image.setUIID("NewLabel");

        Label label_1 = new Label("ga");
        Label label_2 = new Label("to");

        label_1.setUIID("LabelWord");
        label_2.setUIID("LabelWord");

        label_1.setDraggable(true);
        label_2.setDraggable(true);

        Container c_1 = new Container();
        Container c_2 = new Container();
        Container c_3 = new Container();
        Container c_4 = new Container();

        c_1.setDropTarget(true);
        c_2.setDropTarget(true);
        c_3.setDropTarget(true);
        c_4.setDropTarget(true);

        c_1.setLayout(new BoxLayout(2));
        c_2.setLayout(new BoxLayout(2));
        c_3.setLayout(new BoxLayout(2));
        c_4.setLayout(new BoxLayout(2));

        c_1.setUIID("Container_1");
        c_2.setUIID("Container_1");
        c_3.setUIID("Container_2");
        c_4.setUIID("Container_2");

        c_3.add(label_2);
        c_4.add(label_1);

        GridLayout gl = new GridLayout(2,2);
        Container container_0 = new Container(gl);
        container_0.add(c_1);
        container_0.add(c_2);
        container_0.add(c_3);
        container_0.add(c_4);

        ArrayList <Container> list_Containers = new ArrayList<>();
        list_Containers.add(c_1);
        list_Containers.add(c_2);
        list_Containers.add(c_3);
        list_Containers.add(c_4);

        ArrayList  list_Labels = new ArrayList<>();
        list_Labels.add(label_1);
        list_Labels.add(label_2);

        for (Label label : list_Labels) {
            label.addDragOverListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    for (Container c : list_Containers) {
                        int int_C = c.getComponentCount();
                        if (int_C == 1) {
                            c.setDropTarget(false);
                        } else if (int_C == 0) {
                            c.setDropTarget(true);
                        }
                    }
                }
            });
        }