问:
Batch processing data from JPA using spring
Hey I'm new to spring and I'm trying to do a program that processes a bunch of records from a database and does something to them. Basically gets all records that are in a certain state, run a command in the OS (one per each record), change something in those records.

I figured that the ideal tool for that is using the batch service support of spring. I already had the records that I wanted to read mapped to a JPA bean (Schedule) and I had CrudRepository (ScheduleRepository) so I figured it would be pretty easy to wire everything together, though I didn't know how.

I tried following the batch service guide making some adaptations to read the input from JPA. But when I tried to run I got a NullPointerException when spring tries to instantiate JpaPagingItemReader.

I'll try to attach the code that I find most relevant to the question:

```<code>@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
    //@Autowired
    //public ScheduleRepository repository;
    @Autowired
    public JobBuilderFactory jobBuilderFactory;
    @Autowired
    public StepBuilderFactory stepBuilderFactory;
    @Bean
    public Job synchronizeProcess(JobCompletionNotificationListener listener) {
        return jobBuilderFactory.get("synchronizeProcess")
                .incrementer(new RunIdIncrementer())
                .listener(listener)
                .flow(step1())
                .end()
                .build();
    }

    private Step step1() {
        return stepBuilderFactory.get("step1")
                .<Schedule, Schedule> chunk(10)
                .reader(new JpaPagingItemReader<Schedule>())
                .processor(new ScheduleExectutor())
                .writer(new JpaItemWriter<Schedule>())
                .build();
    }
}
</code>```

The application.properties:

```<code>spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:postgresql://localhost:5432/my_db
spring.datasource.username=myuser
spring.datasource.password=mypassword
</code>```

Here's the full log:

```$ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building runner 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) > test-compile @ runner >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ runner ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ runner ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ runner ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/msl09/unsynced/workspace/syncweb_scheduler/runner/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ runner ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) < test-compile @ runner <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) @ runner ---

.   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2017-06-06 12:40:55.492  INFO 21085 --- [           main] b.j.t.syncweb.runner.RunnerApplication   : Starting RunnerApplication on myhost-debian with PID 21085 (/home/msl09/unsynced/workspace/syncweb_scheduler/runner/target/classes started by msl09 in /home/msl09/unsynced/workspace/syncweb_scheduler/runner)
2017-06-06 12:40:55.494  INFO 21085 --- [           main] b.j.t.syncweb.runner.RunnerApplication   : No active profile set, falling back to default profiles: default
2017-06-06 12:40:55.533  INFO 21085 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4d488830: startup date [Tue Jun 06 12:40:55 BRT 2017]; root of context hierarchy
2017-06-06 12:40:55.957  WARN 21085 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2017-06-06 12:40:55.966  WARN 21085 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2017-06-06 12:40:56.326  INFO 21085 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-06-06 12:40:56.340  INFO 21085 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
2017-06-06 12:40:56.385  INFO 21085 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-06-06 12:40:56.386  INFO 21085 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-06-06 12:40:56.387  INFO 21085 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-06-06 12:40:56.431  INFO 21085 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-06-06 12:40:56.501  INFO 21085 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2017-06-06 12:40:56.621  INFO 21085 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2017-06-06 12:40:56.622  INFO 21085 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@c3133ad
2017-06-06 12:40:56.809  INFO 21085 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-06-06 12:40:57.031  WARN 21085 --- [           main] o.s.b.a.batch.BasicBatchConfigurer       : JPA does not support custom isolation levels, so locks may not be taken when launching Jobs
2017-06-06 12:40:57.032  INFO 21085 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: POSTGRES
2017-06-06 12:40:57.151  INFO 21085 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2017-06-06 12:40:57.164  INFO 21085 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql]
2017-06-06 12:40:57.964  INFO 21085 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executed SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql] in 800 ms.
2017-06-06 12:40:58.098  INFO 21085 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-06-06 12:40:58.109  INFO 21085 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: []
2017-06-06 12:40:58.214  INFO 21085 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=synchronizeProcess]] launched with the following parameters: [{run.id=1}]
2017-06-06 12:40:58.238  INFO 21085 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
2017-06-06 12:40:58.251 ERROR 21085 --- [           main] o.s.batch.core.step.AbstractStep         : Encountered an error executing step step1 in job synchronizeProcess

org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:147) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at com.sun.proxy.$Proxy74.run(Unknown Source) [na:na]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:214) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:231) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:123) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:117) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at br.jus.tjse.syncweb.runner.RunnerApplication.main(RunnerApplication.java:10) [classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527) [spring-boot-maven-plugin-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: java.lang.NullPointerException: null
        at org.springframework.batch.item.database.JpaPagingItemReader.doOpen(JpaPagingItemReader.java:177) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:144) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        ... 41 common frames omitted

2017-06-06 12:40:58.264 ERROR 21085 --- [           main] o.s.batch.core.step.AbstractStep         : Exception while closing step execution resources in step step1 in job synchronizeProcess

org.springframework.batch.item.ItemStreamException: Error while closing item reader
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.close(AbstractItemCountingItemStreamItemReader.java:136) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.CompositeItemStream.close(CompositeItemStream.java:85) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.tasklet.TaskletStep.close(TaskletStep.java:305) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:271) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at com.sun.proxy.$Proxy74.run(Unknown Source) [na:na]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:214) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:231) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:123) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:117) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at br.jus.tjse.syncweb.runner.RunnerApplication.main(RunnerApplication.java:10) [classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527) [spring-boot-maven-plugin-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: java.lang.NullPointerException: null
        at org.springframework.batch.item.database.JpaPagingItemReader.doClose(JpaPagingItemReader.java:236) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.close(AbstractItemCountingItemStreamItemReader.java:133) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        ... 41 common frames omitted

2017-06-06 12:40:58.305  INFO 21085 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=synchronizeProcess]] completed with the following parameters: [{run.id=1}] and the following status: [FAILED]
2017-06-06 12:40:58.307  INFO 21085 --- [           main] b.j.t.syncweb.runner.RunnerApplication   : Started RunnerApplication in 3.142 seconds (JVM running for 5.223)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.444 s
[INFO] Finished at: 2017-06-06T12:40:58-03:00
[INFO] Final Memory: 34M/351M
[INFO] ------------------------------------------------------------------------
2017-06-06 12:40:58.478  INFO 21085 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4d488830: startup date [Tue Jun 06 12:40:55 BRT 2017]; root of context hierarchy
2017-06-06 12:40:58.479  INFO 21085 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2017-06-06 12:40:58.480  INFO 21085 --- [       Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
```

What's the correct way to instantiate the JpaPaginItemReader?

答:
@M. Deinum thanks a bunch, using your tip I was able to figure how to map fix that bug. Here is how my configuration class is now:

```<code>@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
    @Autowired
    public JobBuilderFactory jobBuilderFactory;
    @Autowired
    public StepBuilderFactory stepBuilderFactory;
    @Autowired
    public EntityManagerFactory entityManagerFactory;

    @Bean
    public Job synchronizeProcess(JobCompletionNotificationListener listener) {
        return jobBuilderFactory.get("synchronizeProcess")
                .incrementer(new RunIdIncrementer())
                .listener(listener)
                .flow(step1())
                .end()
                .build();
    }

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .<Schedule, Schedule> chunk(10)
                .reader(reader())
                .processor(new ScheduleExectutor())
                .writer(writer())
                .build();
    }

    @Bean
    public JpaItemWriter<Schedule> writer() {
        JpaItemWriter<Schedule> jpaItemWriter = new JpaItemWriter<>();
        jpaItemWriter.setEntityManagerFactory(entityManagerFactory);
        return jpaItemWriter;
    }

    @Bean
    public ItemReader<Schedule> reader() {
        JpaPagingItemReader<Schedule> jpaPagingItemReader = new JpaPagingItemReader<Schedule>();
        jpaPagingItemReader.setEntityManagerFactory(entityManagerFactory);
        jpaPagingItemReader.setQueryString("SELECT s FROM Schedule s WHERE s.status = 'WAITING'");
        jpaPagingItemReader.setPageSize(10);
        return jpaPagingItemReader;
    }

}
</code>```

Now hibernate s complaining that Schedule is not mapped but at least that's a different error and I think that's more related to me not knowing how JPQL works.

Body:
Hey I'm new to spring and I'm trying to do a program that processes a bunch of records from a database and does something to them. Basically gets all records that are in a certain state, run a command in the OS (one per each record), change something in those records.

I figured that the ideal tool for that is using the batch service support of spring. I already had the records that I wanted to read mapped to a JPA bean (Schedule) and I had CrudRepository (ScheduleRepository) so I figured it would be pretty easy to wire everything together, though I didn't know how.

I tried following the batch service guide making some adaptations to read the input from JPA. But when I tried to run I got a NullPointerException when spring tries to instantiate JpaPagingItemReader.

I'll try to attach the code that I find most relevant to the question:

@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
    //@Autowired
    //public ScheduleRepository repository;
    @Autowired
    public JobBuilderFactory jobBuilderFactory;
    @Autowired
    public StepBuilderFactory stepBuilderFactory;
    @Bean
    public Job synchronizeProcess(JobCompletionNotificationListener listener) {
        return jobBuilderFactory.get("synchronizeProcess")
                .incrementer(new RunIdIncrementer())
                .listener(listener)
                .flow(step1())
                .end()
                .build();
    }

    private Step step1() {
        return stepBuilderFactory.get("step1")
                .<Schedule, Schedule> chunk(10)
                .reader(new JpaPagingItemReader<Schedule>())
                .processor(new ScheduleExectutor())
                .writer(new JpaItemWriter<Schedule>())
                .build();
    }
}

The application.properties:

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:postgresql://localhost:5432/my_db
spring.datasource.username=myuser
spring.datasource.password=mypassword

Here's the full log:

$ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building runner 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) > test-compile @ runner >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ runner ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ runner ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ runner ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/msl09/unsynced/workspace/syncweb_scheduler/runner/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ runner ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) < test-compile @ runner <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) @ runner ---

.   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2017-06-06 12:40:55.492  INFO 21085 --- [           main] b.j.t.syncweb.runner.RunnerApplication   : Starting RunnerApplication on myhost-debian with PID 21085 (/home/msl09/unsynced/workspace/syncweb_scheduler/runner/target/classes started by msl09 in /home/msl09/unsynced/workspace/syncweb_scheduler/runner)
2017-06-06 12:40:55.494  INFO 21085 --- [           main] b.j.t.syncweb.runner.RunnerApplication   : No active profile set, falling back to default profiles: default
2017-06-06 12:40:55.533  INFO 21085 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4d488830: startup date [Tue Jun 06 12:40:55 BRT 2017]; root of context hierarchy
2017-06-06 12:40:55.957  WARN 21085 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2017-06-06 12:40:55.966  WARN 21085 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2017-06-06 12:40:56.326  INFO 21085 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-06-06 12:40:56.340  INFO 21085 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
2017-06-06 12:40:56.385  INFO 21085 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-06-06 12:40:56.386  INFO 21085 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-06-06 12:40:56.387  INFO 21085 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-06-06 12:40:56.431  INFO 21085 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-06-06 12:40:56.501  INFO 21085 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2017-06-06 12:40:56.621  INFO 21085 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2017-06-06 12:40:56.622  INFO 21085 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@c3133ad
2017-06-06 12:40:56.809  INFO 21085 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-06-06 12:40:57.031  WARN 21085 --- [           main] o.s.b.a.batch.BasicBatchConfigurer       : JPA does not support custom isolation levels, so locks may not be taken when launching Jobs
2017-06-06 12:40:57.032  INFO 21085 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: POSTGRES
2017-06-06 12:40:57.151  INFO 21085 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2017-06-06 12:40:57.164  INFO 21085 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql]
2017-06-06 12:40:57.964  INFO 21085 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executed SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql] in 800 ms.
2017-06-06 12:40:58.098  INFO 21085 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-06-06 12:40:58.109  INFO 21085 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: []
2017-06-06 12:40:58.214  INFO 21085 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=synchronizeProcess]] launched with the following parameters: [{run.id=1}]
2017-06-06 12:40:58.238  INFO 21085 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
2017-06-06 12:40:58.251 ERROR 21085 --- [           main] o.s.batch.core.step.AbstractStep         : Encountered an error executing step step1 in job synchronizeProcess

org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:147) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at com.sun.proxy.$Proxy74.run(Unknown Source) [na:na]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:214) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:231) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:123) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:117) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at br.jus.tjse.syncweb.runner.RunnerApplication.main(RunnerApplication.java:10) [classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527) [spring-boot-maven-plugin-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: java.lang.NullPointerException: null
        at org.springframework.batch.item.database.JpaPagingItemReader.doOpen(JpaPagingItemReader.java:177) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:144) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        ... 41 common frames omitted

2017-06-06 12:40:58.264 ERROR 21085 --- [           main] o.s.batch.core.step.AbstractStep         : Exception while closing step execution resources in step step1 in job synchronizeProcess

org.springframework.batch.item.ItemStreamException: Error while closing item reader
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.close(AbstractItemCountingItemStreamItemReader.java:136) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.CompositeItemStream.close(CompositeItemStream.java:85) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.tasklet.TaskletStep.close(TaskletStep.java:305) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:271) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at com.sun.proxy.$Proxy74.run(Unknown Source) [na:na]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:214) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:231) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:123) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:117) [spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at br.jus.tjse.syncweb.runner.RunnerApplication.main(RunnerApplication.java:10) [classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527) [spring-boot-maven-plugin-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: java.lang.NullPointerException: null
        at org.springframework.batch.item.database.JpaPagingItemReader.doClose(JpaPagingItemReader.java:236) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.close(AbstractItemCountingItemStreamItemReader.java:133) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
        ... 41 common frames omitted

2017-06-06 12:40:58.305  INFO 21085 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=synchronizeProcess]] completed with the following parameters: [{run.id=1}] and the following status: [FAILED]
2017-06-06 12:40:58.307  INFO 21085 --- [           main] b.j.t.syncweb.runner.RunnerApplication   : Started RunnerApplication in 3.142 seconds (JVM running for 5.223)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.444 s
[INFO] Finished at: 2017-06-06T12:40:58-03:00
[INFO] Final Memory: 34M/351M
[INFO] ------------------------------------------------------------------------
2017-06-06 12:40:58.478  INFO 21085 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4d488830: startup date [Tue Jun 06 12:40:55 BRT 2017]; root of context hierarchy
2017-06-06 12:40:58.479  INFO 21085 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2017-06-06 12:40:58.480  INFO 21085 --- [       Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'

What's the correct way to instantiate the JpaPaginItemReader?

Body:
@M. Deinum thanks a bunch, using your tip I was able to figure how to map fix that bug. Here is how my configuration class is now:

@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
    @Autowired
    public JobBuilderFactory jobBuilderFactory;
    @Autowired
    public StepBuilderFactory stepBuilderFactory;
    @Autowired
    public EntityManagerFactory entityManagerFactory;

    @Bean
    public Job synchronizeProcess(JobCompletionNotificationListener listener) {
        return jobBuilderFactory.get("synchronizeProcess")
                .incrementer(new RunIdIncrementer())
                .listener(listener)
                .flow(step1())
                .end()
                .build();
    }

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .<Schedule, Schedule> chunk(10)
                .reader(reader())
                .processor(new ScheduleExectutor())
                .writer(writer())
                .build();
    }

    @Bean
    public JpaItemWriter<Schedule> writer() {
        JpaItemWriter<Schedule> jpaItemWriter = new JpaItemWriter<>();
        jpaItemWriter.setEntityManagerFactory(entityManagerFactory);
        return jpaItemWriter;
    }

    @Bean
    public ItemReader<Schedule> reader() {
        JpaPagingItemReader<Schedule> jpaPagingItemReader = new JpaPagingItemReader<Schedule>();
        jpaPagingItemReader.setEntityManagerFactory(entityManagerFactory);
        jpaPagingItemReader.setQueryString("SELECT s FROM Schedule s WHERE s.status = 'WAITING'");
        jpaPagingItemReader.setPageSize(10);
        return jpaPagingItemReader;
    }

}

Now hibernate s complaining that Schedule is not mapped but at least that's a different error and I think that's more related to me not knowing how JPQL works.


来源: stackexchange

问:
I need to enable java (tm) plugin which installs applet in the browser.. How is it possible in Web Driver
I need to enable java (tm) plugin which installs applet in the browser.. How is it possible in Web Driver?
I am testing a web app where some functionality has to be verified by enabling java(i.e., by installing applet) and also some functionality by disabling it. If applet works fine, then I need some expected results and if applet is not installed, I need some other results.. so how do i enable/disable applets(i.e.,java tm plugin) before launching browser..??
Please Help..

Currently am using WebDriver...

答:
You can enable any Firefox plugin creating new profile and setting the preference.

For e.g.
to enable java plugin

```<code>profile.setPreference("plugin.state.java", 2);
</code>```

To enable flash plugin

```<code>profile.setPreference("plugin.state.flash", 2);
</code>```

Sample code:

```<code>FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("plugin.state.java", 2);

WebDriver driver = new FirefoxDriver(profile);
</code>```

I presume the "2" activates the plugin.

ContentLicense: CC BY-SA 3.0

Body:
You can enable any Firefox plugin creating new profile and setting the preference.

For e.g.
to enable java plugin

profile.setPreference("plugin.state.java", 2);

To enable flash plugin

profile.setPreference("plugin.state.flash", 2);

Sample code:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("plugin.state.java", 2);

WebDriver driver = new FirefoxDriver(profile);

I presume the "2" activates the plugin.


问:
HTML and CSS - banner and background positioning
I am building a simple landing page where the visitor would see a banner, a background image below it and a couple of buttons located vertically beneath each other.

The problem I am experiencing is that, at the moment, both the banner and the background image are starting from the same position (the top left corner of the web page), thus part of the background is hidden by the banner.

The code I currently have is:

```<code><style>
  body {
    background: url("http://url.to/background") no-repeat center center fixed;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
    padding: 0px;
    margin: 0px;
  }

  #Wrap {
    position: absolute;
  }
</style>

<body>
  <div id="Wrap">
    <img src="http://url.to/banner" />
  </div>
</body>
</code>```

The expected result is to have the banner image take the beginning of the page while fitting into the screen without causing any extra scroll to appear. What is more important is to have the background start after the banner.

A fiddle could be found at the following URL:

https://jsfiddle.net/morL1zka/

Any help or ideas would be appreciated.

答:
you should use     background-position-y for this, and you need to set value which is equal to the height of the banner

body {
  background: url("https://www.w3schools.com/css/img_fjords.jpg") no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  padding: 0px;
  margin: 0px;
  background-position-y: 100px;/*the value must be the same height as the banner */

}

#Wrap {

  position: absolute;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="Wrap">
  <img src="http://url.to/banner" />
</div></code>```

Body:
I am building a simple landing page where the visitor would see a banner, a background image below it and a couple of buttons located vertically beneath each other.

The problem I am experiencing is that, at the moment, both the banner and the background image are starting from the same position (the top left corner of the web page), thus part of the background is hidden by the banner.

The code I currently have is:

The expected result is to have the banner image take the beginning of the page while fitting into the screen without causing any extra scroll to appear. What is more important is to have the background start after the banner.

A fiddle could be found at the following URL:

https://jsfiddle.net/morL1zka/

Any help or ideas would be appreciated.

Body:
you should use     background-position-y for this, and you need to set value which is equal to the height of the banner

body {
  background: url("https://www.w3schools.com/css/img_fjords.jpg") no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  padding: 0px;
  margin: 0px;
  background-position-y: 100px;/*the value must be the same height as the banner */

}

#Wrap {

  position: absolute;
}

<div id="Wrap">
  <img src="http://url.to/banner" />
</div>


问:
PHP: Shorthand Switch
I'm looking for more comfortable/more short version of Switch() statement in case of using multiple functions.

I'll give you one example: imagine 100-200 functions in one class, and you want to call only one of them by setting value to id in that class.

In my particular case, I have the following structure of PHP file:

```<code><?php

  class _main
  {
      function request($id)
      {
          switch($id)
          {
              case 0:
                  $this->writeA();
              break;
              case 1:
                  $this->writeB();
              break;

              ///...
              // then we have 100-200 functions like this in switch.
          }
      }
      function writeA()
      {
          echo('a');
      }
      function writeB()
      {
          echo('b');
      }
  }

  $id   = 1;
  $x    = new _main();
  $x->request($id);

?>
</code>```

For some of you it may seem weird, but I don't want to have that much lines of code with case and break. For me, they are just making code more difficult to read.

(by the way, writing it 100 times will not making it fun for me too).

CONCLUSION

What could be the best,fast and comfortable method?

Can I store functions to array and then call them?

And will it affect performance? Will be Swicth() even faster?

Thank you :)

EDIT

Perhaps there is a different way of thinking/coding and not only array/switch thing.

答:
I can't say I would ever recommend this but if you really want that many methods within a single class and a singular function to route the calls through...

```<code><?php

class MyClass
{
    public $id;

    public function callFunction()
    {
        $funcName = 'execute' . $this->id;
        return $this->$funcName();
    }

    private function execute1()
    {
        echo 'execute1() Called.';
    }

    private function execute2()
    {
        echo 'execute2() Called.';
    }
}

$c = new MyClass();
$c->id = 1;
$c->callFunction();
</code>```

Output:

```<code>execute1() Called.
</code>```

I feel like there is most likely another way to approach this with more information utilising Interfaces and Abstract classes, but with the information to go off the above might suffice your requirement.

Edit: Sadly I don't have the time right now to come up with a detailed solution, and I don't really have enough information to go off but perhaps utilising interfaces is your best solution for your requirement. Below is a very quick example.

```<code><?php

interface WritableInterface
{
    public function write($data);
}

class VersionOneWriter implements WritableInterface
{
    public function write($data)
    {
        return $data . '<br/>';
    }
}

class VersionTwoWriter implements WritableInterface
{
    public function write($data)
    {
        return $data . $data . '<br/>';
    }
}

class MyMainClass
{
    public function request(WritableInterface $writer, $data)
    {
        return $writer->write($data);
    }
}

$c  = new MyMainClass();
$w1 = new VersionOneWriter();
$w2 = new VersionTwoWriter();

echo $c->request($w1, 'DataString');
echo $c->request($w2, 'DataString');
</code>```

Essentially when you call your request function you pass along a Writer class which implements the WritableInterface. Anything that implements that interface has to have a write() method.

Now when you pass your data across with your method, since you are also passing a writer along that can handle the data you can safely call ->write($data) within your request() method and the result will be dependent on the class you passed through.

If you ever need another method of writing you can just add create another class that implements your interface

Hopefully that made some sense, it was a bit of a ramble as I have to disappear for a bit. If you have any questions I'll try to check back when I have time.

--

Edit2:
The define() in this instance requires PHP7+ since I'm defining an array, but you could prior to PHP7 you could just use a standard array. $classMap = ['FirstClass', 'SecondClass'];

```<code>interface MyInterface {}
class FirstClass implements MyInterface {}
class SecondClass implements MyInterface {}

$requestParam = 1;

define('CLASS_MAP', array(
    'FirstClass',
    'SecondClass',
));

$classMap = CLASS_MAP[$requestParam]; // SecondClass

$class = new $classMap;
var_dump($class); // Dumps out: object(SecondClass)#1 (0) {}
</code>```

Title: PHP: Shorthand Switch

Body:
I'm looking for more comfortable/more short version of Switch() statement in case of using multiple functions.

I'll give you one example: imagine 100-200 functions in one class, and you want to call only one of them by setting value to id in that class.

In my particular case, I have the following structure of PHP file:

<?php

  class _main
  {
      function request($id)
      {
          switch($id)
          {
              case 0:
                  $this->writeA();
              break;
              case 1:
                  $this->writeB();
              break;

              ///...
              // then we have 100-200 functions like this in switch.
          }
      }
      function writeA()
      {
          echo('a');
      }
      function writeB()
      {
          echo('b');
      }
  }

  $id   = 1;
  $x    = new _main();
  $x->request($id);

?>

For some of you it may seem weird, but I don't want to have that much lines of code with case and break. For me, they are just making code more difficult to read.

(by the way, writing it 100 times will not making it fun for me too).

CONCLUSION

What could be the best,fast and comfortable method?

Can I store functions to array and then call them?

And will it affect performance? Will be Swicth() even faster?

Thank you :)

EDIT

Perhaps there is a different way of thinking/coding and not only array/switch thing.

Body:
I can't say I would ever recommend this but if you really want that many methods within a single class and a singular function to route the calls through...

<?php

class MyClass
{
    public $id;

    public function callFunction()
    {
        $funcName = 'execute' . $this->id;
        return $this->$funcName();
    }

    private function execute1()
    {
        echo 'execute1() Called.';
    }

    private function execute2()
    {
        echo 'execute2() Called.';
    }
}

$c = new MyClass();
$c->id = 1;
$c->callFunction();

Output:

execute1() Called.

I feel like there is most likely another way to approach this with more information utilising Interfaces and Abstract classes, but with the information to go off the above might suffice your requirement.

Edit: Sadly I don't have the time right now to come up with a detailed solution, and I don't really have enough information to go off but perhaps utilising interfaces is your best solution for your requirement. Below is a very quick example.

<?php

interface WritableInterface
{
    public function write($data);
}

class VersionOneWriter implements WritableInterface
{
    public function write($data)
    {
        return $data . '<br/>';
    }
}

class VersionTwoWriter implements WritableInterface
{
    public function write($data)
    {
        return $data . $data . '<br/>';
    }
}

class MyMainClass
{
    public function request(WritableInterface $writer, $data)
    {
        return $writer->write($data);
    }
}

$c  = new MyMainClass();
$w1 = new VersionOneWriter();
$w2 = new VersionTwoWriter();

echo $c->request($w1, 'DataString');
echo $c->request($w2, 'DataString');

Essentially when you call your request function you pass along a Writer class which implements the WritableInterface. Anything that implements that interface has to have a write() method.

Now when you pass your data across with your method, since you are also passing a writer along that can handle the data you can safely call ->write($data) within your request() method and the result will be dependent on the class you passed through.

If you ever need another method of writing you can just add create another class that implements your interface

Hopefully that made some sense, it was a bit of a ramble as I have to disappear for a bit. If you have any questions I'll try to check back when I have time.

--

Edit2:
The define() in this instance requires PHP7+ since I'm defining an array, but you could prior to PHP7 you could just use a standard array. $classMap = ['FirstClass', 'SecondClass'];

interface MyInterface {}
class FirstClass implements MyInterface {}
class SecondClass implements MyInterface {}

$requestParam = 1;

define('CLASS_MAP', array(
    'FirstClass',
    'SecondClass',
));

$classMap = CLASS_MAP[$requestParam]; // SecondClass

$class = new $classMap;
var_dump($class); // Dumps out: object(SecondClass)#1 (0) {}


问:
How can CodeMirror display an 'javascript object' string with object structure
I start use code mirror, and i want to display an object with object structure.

I have a file with this content

```<code>{ property1: 'value', property2: { property3: 'value' }}
</code>```

This is written in one line in .txt file.

Now i want to use code mirror so user can edit this file content.
I get the file content using HTTP call and after that i have this code

```<code>        var editor = CodeMirror(document.getElementById('reportEditor'), {
            mode: { name: "javascript", json: true },
            theme: "default",
            lineNumbers: true,
            readOnly: false,
            value: JSON.stringify(response.data),
        });
</code>```

This works fine, i get the content but code mirror display it in one line.

How can force Code Mirror to display this value like an object structure like

```<code> {
      property1: 'value',
      property2: {
           property3: 'value'
      }
 }
</code>```

I found on this  site  a very good json prettifier

答:
Before setting the string into codemirror's editor, make sure you beautify your it for your preferred format.

eg. https://github.com/beautify-web/js-beautify

Also you can use the beautifier here
http://jsbeautifier.org/

ContentLicense: CC BY-SA 4.0

Body:
I start use code mirror, and i want to display an object with object structure.

I have a file with this content

{ property1: 'value', property2: { property3: 'value' }}

This is written in one line in .txt file.

Now i want to use code mirror so user can edit this file content.
I get the file content using HTTP call and after that i have this code

        var editor = CodeMirror(document.getElementById('reportEditor'), {
            mode: { name: "javascript", json: true },
            theme: "default",
            lineNumbers: true,
            readOnly: false,
            value: JSON.stringify(response.data),
        });

This works fine, i get the content but code mirror display it in one line.

How can force Code Mirror to display this value like an object structure like

 {
      property1: 'value',
      property2: {
           property3: 'value'
      }
 }

I found on this  site  a very good json prettifier


问:
Trying to data pull from multiple excel sheets with Python
I am trying to create a python program that will take data from multiple excel sheets and I am kinda stuck at the moment:

```<code>import xlrd
import xlwt
workbook1 = xlrd.open_workbook('Z:\Public\Safety\SafetyDataPullProject\TestFile.xlsx', on_demand = True)
worksheet = workbook1.sheet_by_index('Sheet1')
sheet.cell(5, 5).value
</code>```

This is my code currently this produces a error

```<code>Traceback (most recent call last):
  File "H:\python things\Datapull2.py", line 4, in <module>
    worksheet = workbook1.sheet_by_index('Sheet1')
  File "C:\Users\gomcrai\AppData\Local\Programs\Python\Python36-32\lib\site-packages\xlrd\book.py", line 432, in sheet_by_index
    return self._sheet_list[sheetx] or self.get_sheet(sheetx)
TypeError: list indices must be integers or slices, not str
</code>```

I just wanna take the information from the cell(s) I've marked and drop them into a newly created excel sheet. If anyone could help me please let me know.

Side note: I know these things would probably be easier in VB but I am practicing python.

答:
Use sheet_by_name not sheet_by_id.

sheet_by_id takes position (integer) as parameter and return sheet at that position.

Body:
I am trying to create a python program that will take data from multiple excel sheets and I am kinda stuck at the moment:

import xlrd
import xlwt
workbook1 = xlrd.open_workbook('Z:\Public\Safety\SafetyDataPullProject\TestFile.xlsx', on_demand = True)
worksheet = workbook1.sheet_by_index('Sheet1')
sheet.cell(5, 5).value

This is my code currently this produces a error

Traceback (most recent call last):
  File "H:\python things\Datapull2.py", line 4, in <module>
    worksheet = workbook1.sheet_by_index('Sheet1')
  File "C:\Users\gomcrai\AppData\Local\Programs\Python\Python36-32\lib\site-packages\xlrd\book.py", line 432, in sheet_by_index
    return self._sheet_list[sheetx] or self.get_sheet(sheetx)
TypeError: list indices must be integers or slices, not str

I just wanna take the information from the cell(s) I've marked and drop them into a newly created excel sheet. If anyone could help me please let me know.

Side note: I know these things would probably be easier in VB but I am practicing python.


问:
Is now the time to start designing for 1280px wide screens instead of 1024px?
Need opinions on this, what do you guys think? A good idea or not so good idea.

I could do a seperate css style but not sure whether to drop 1024 for sure.

答:
This really depends on your website.  What is it about? Who is your audience?  I have designed and implemented websites for a number of different topics.  For example, if you are designing a furniture site, you are probably going to want to keep the resolution down because the audience you are going for can be any age, any browser, and their computer could be older than dinosaurs. </p>

<p>Another example, if its a tech or gameing site than you are probably ok to use a higher rez as that type of audience probably keeps their equipment nearly upto modern resolutions. </p>

ContentLicense: CC BY-SA 2.5

Body:
This really depends on your website.  What is it about? Who is your audience?  I have designed and implemented websites for a number of different topics.  For example, if you are designing a furniture site, you are probably going to want to keep the resolution down because the audience you are going for can be any age, any browser, and their computer could be older than dinosaurs.

Another example, if its a tech or gameing site than you are probably ok to use a higher rez as that type of audience probably keeps their equipment nearly upto modern resolutions.


问:
TabView Crash when Selected
My app is crashing when I try to select the "inspection" tab I have everything linked Im not sure why I'm getting this error. Can someone lend a hand? Below are my InspectionViewController and my Error Code.

InspectionVC:

```<code>//
//  InspectionVC.swift
//  Chat
//
//  Created by Wiiliam Pettit on 6/2/17.
//  Copyright © 2017 MVI. All rights reserved.
//

import UIKit

class InspectionVC: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var picker: UIPickerView!

    var pickerData: [String] = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        // Connect data:
        self.picker.delegate = self
        self.picker.dataSource = self

        // Input data into the Array:
        pickerData = ["5312", "5387", "53C4", "53W5", "53W8", "5349"]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return pickerData.count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return pickerData[row]
    }

    // Catpure the picker view selection
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if(row == 0)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com/Module_Inspect/perform/22243/230")!)
        }
        else if(row == 1)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 2)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 3)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 4)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 5)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
    }

}
</code>```

Error:

```<code>Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<QuickChat.InspectionVC 0x7fe83ad275f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pickerView.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d443b0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010c545141 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010d443a59 -[NSException raise] + 9
    3   Foundation                          0x000000010c05ae8b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
    4   UIKit                               0x000000010e369644 -[UIViewController setValue:forKey:] + 87
    5   UIKit                               0x000000010e5d66b9 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x000000010d3e9e8d -[NSArray makeObjectsPerformSelector:] + 269
    7   UIKit                               0x000000010e5d506f -[UINib instantiateWithOwner:options:] + 1856
    8   UIKit                               0x000000010e36fc73 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x000000010e370589 -[UIViewController loadView] + 177
    10  UIKit                               0x000000010e3708ba -[UIViewController loadViewIfRequired] + 195
    11  UIKit                               0x000000010e37110a -[UIViewController view] + 27
    12  UIKit                               0x000000010e3cd40b -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 476
    13  UIKit                               0x000000010e3cc89c -[UITabBarController transitionFromViewController:toViewController:] + 59
    14  UIKit                               0x000000010e3c89d6 -[UITabBarController _setSelectedViewController:] + 410
    15  UIKit                               0x000000010e3c87a5 -[UITabBarController setSelectedViewController:] + 109
    16  UIKit                               0x000000010e3cc741 -[UITabBarController _tabBarItemClicked:] + 384
    17  UIKit                               0x000000010e1cfd22 -[UIApplication sendAction:to:from:forEvent:] + 83
    18  UIKit                               0x000000010e5e26f7 -[UITabBar _sendAction:withEvent:] + 566
    19  UIKit                               0x000000010e1cfd22 -[UIApplication sendAction:to:from:forEvent:] + 83
    20  UIKit                               0x000000010e35425c -[UIControl sendAction:to:forEvent:] + 67
    21  UIKit                               0x000000010e354577 -[UIControl _sendActionsForEvents:withEvent:] + 450
    22  UIKit                               0x000000010e5e4db5 -[UITabBar _buttonUp:] + 113
    23  UIKit                               0x000000010e1cfd22 -[UIApplication sendAction:to:from:forEvent:] + 83
    24  UIKit                               0x000000010e35425c -[UIControl sendAction:to:forEvent:] + 67
    25  UIKit                               0x000000010e354577 -[UIControl _sendActionsForEvents:withEvent:] + 450
    26  UIKit                               0x000000010e3534b2 -[UIControl touchesEnded:withEvent:] + 618
    27  UIKit                               0x000000010e23d49a -[UIWindow _sendTouchesForEvent:] + 2707
    28  UIKit                               0x000000010e23ebb0 -[UIWindow sendEvent:] + 4114
    29  UIKit                               0x000000010e1eb7b0 -[UIApplication sendEvent:] + 352
    30  UIKit                               0x000000010e9ceadc __dispatchPreprocessedEventFromEventQueue + 2926
    31  UIKit                               0x000000010e9c6a3a __handleEventQueue + 1122
    32  CoreFoundation                      0x000000010d3e9c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    33  CoreFoundation                      0x000000010d3cf0cf __CFRunLoopDoSources0 + 527
    34  CoreFoundation                      0x000000010d3ce5ff __CFRunLoopRun + 911
    35  CoreFoundation                      0x000000010d3ce016 CFRunLoopRunSpecific + 406
    36  GraphicsServices                    0x000000011156ea24 GSEventRunModal + 62
    37  UIKit                               0x000000010e1ce0d4 UIApplicationMain + 159
    38  QuickChat                           0x000000010a83fba7 main + 55
    39  libdyld.dylib                       0x00000001104ae65d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
</code>```

答:
Your Referencing outlet for the picker is set "pickerView" instead of "picker".

Go to storyboard and select the picker view on view controller.

Select "Show the connections inspector" in the utilities
section(right tab of xcode).

Remove referencing outlet connected to
"pickerView".

Add referencing outlet to "picker".

Title: TabView Crash when Selected

Body:
My app is crashing when I try to select the "inspection" tab I have everything linked Im not sure why I'm getting this error. Can someone lend a hand? Below are my InspectionViewController and my Error Code.

InspectionVC:

//
//  InspectionVC.swift
//  Chat
//
//  Created by Wiiliam Pettit on 6/2/17.
//  Copyright © 2017 MVI. All rights reserved.
//

import UIKit

class InspectionVC: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var picker: UIPickerView!

    var pickerData: [String] = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        // Connect data:
        self.picker.delegate = self
        self.picker.dataSource = self

        // Input data into the Array:
        pickerData = ["5312", "5387", "53C4", "53W5", "53W8", "5349"]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return pickerData.count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return pickerData[row]
    }

    // Catpure the picker view selection
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if(row == 0)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com/Module_Inspect/perform/22243/230")!)
        }
        else if(row == 1)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 2)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 3)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 4)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
        else if(row == 5)
        {
            UIApplication.shared.open(URL(string: "http://mvi.crompco.com")!)
        }
    }

}

Error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<QuickChat.InspectionVC 0x7fe83ad275f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pickerView.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d443b0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010c545141 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010d443a59 -[NSException raise] + 9
    3   Foundation                          0x000000010c05ae8b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
    4   UIKit                               0x000000010e369644 -[UIViewController setValue:forKey:] + 87
    5   UIKit                               0x000000010e5d66b9 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x000000010d3e9e8d -[NSArray makeObjectsPerformSelector:] + 269
    7   UIKit                               0x000000010e5d506f -[UINib instantiateWithOwner:options:] + 1856
    8   UIKit                               0x000000010e36fc73 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x000000010e370589 -[UIViewController loadView] + 177
    10  UIKit                               0x000000010e3708ba -[UIViewController loadViewIfRequired] + 195
    11  UIKit                               0x000000010e37110a -[UIViewController view] + 27
    12  UIKit                               0x000000010e3cd40b -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 476
    13  UIKit                               0x000000010e3cc89c -[UITabBarController transitionFromViewController:toViewController:] + 59
    14  UIKit                               0x000000010e3c89d6 -[UITabBarController _setSelectedViewController:] + 410
    15  UIKit                               0x000000010e3c87a5 -[UITabBarController setSelectedViewController:] + 109
    16  UIKit                               0x000000010e3cc741 -[UITabBarController _tabBarItemClicked:] + 384
    17  UIKit                               0x000000010e1cfd22 -[UIApplication sendAction:to:from:forEvent:] + 83
    18  UIKit                               0x000000010e5e26f7 -[UITabBar _sendAction:withEvent:] + 566
    19  UIKit                               0x000000010e1cfd22 -[UIApplication sendAction:to:from:forEvent:] + 83
    20  UIKit                               0x000000010e35425c -[UIControl sendAction:to:forEvent:] + 67
    21  UIKit                               0x000000010e354577 -[UIControl _sendActionsForEvents:withEvent:] + 450
    22  UIKit                               0x000000010e5e4db5 -[UITabBar _buttonUp:] + 113
    23  UIKit                               0x000000010e1cfd22 -[UIApplication sendAction:to:from:forEvent:] + 83
    24  UIKit                               0x000000010e35425c -[UIControl sendAction:to:forEvent:] + 67
    25  UIKit                               0x000000010e354577 -[UIControl _sendActionsForEvents:withEvent:] + 450
    26  UIKit                               0x000000010e3534b2 -[UIControl touchesEnded:withEvent:] + 618
    27  UIKit                               0x000000010e23d49a -[UIWindow _sendTouchesForEvent:] + 2707
    28  UIKit                               0x000000010e23ebb0 -[UIWindow sendEvent:] + 4114
    29  UIKit                               0x000000010e1eb7b0 -[UIApplication sendEvent:] + 352
    30  UIKit                               0x000000010e9ceadc __dispatchPreprocessedEventFromEventQueue + 2926
    31  UIKit                               0x000000010e9c6a3a __handleEventQueue + 1122
    32  CoreFoundation                      0x000000010d3e9c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    33  CoreFoundation                      0x000000010d3cf0cf __CFRunLoopDoSources0 + 527
    34  CoreFoundation                      0x000000010d3ce5ff __CFRunLoopRun + 911
    35  CoreFoundation                      0x000000010d3ce016 CFRunLoopRunSpecific + 406
    36  GraphicsServices                    0x000000011156ea24 GSEventRunModal + 62
    37  UIKit                               0x000000010e1ce0d4 UIApplicationMain + 159
    38  QuickChat                           0x000000010a83fba7 main + 55
    39  libdyld.dylib                       0x00000001104ae65d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)


问:
priority queue vs linked list java
I was solving BFS problem. I used PriorityQueue but I was getting wrong answer, then I used LinkedList, I got right ans. I'm unable to find the difference between them. Here are both the codes. Why both the answers are different?

```<code>Code1:
        LinkedList q=new LinkedList();
        q.add(src);
        dist[src]=0;
        visited[src]=1;
        while(!q.isEmpty()){
            u=(int)(Integer) q.remove(0);
            for (int k = 0; k < n; k++) {
                if(a[u][k]==1 && visited[k]==0)
                {
                    dist[k]=dist[u]+1;
                    q.add(k);
                    visited[k]=1;
                }
            }
        }

Code 2:
    PriorityQueue<Integer> q= new PriorityQueue<>();
        q.add(src);
        dist[src]=0;
        visited[src]=1;
        while(!q.isEmpty()){
            u=q.remove();
            for (int k = 0; k < n; k++) {
                if(a[u][k]==1 && visited[k]==0)
                {
                    dist[k]=dist[u]+1;
                    q.add(k);
                    visited[k]=1;
                }
            }
        }
</code>```

Also when I used Adjacency List instead of Adjacency matrix, Priority Queue implementation gave right ans.

答:
PriortiyQueue as well as Linkedlist implement the Queue Interface and perform operations same the way as a Queue (FIFO).
The difference between PriorityQueue and Linkedlist is at the time of insertion PriorityQueue will be sorted as well as ordered as per the natural order but we can add a Commparator also in order to define the particular order of sorting for a record, while as LinkedList will be just ordered.
So while you are trying to add elements in PriorityQueue, they will get sorted on the basis of their natural order or as per the comparator function.

```<code>import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

public class QueueInJava {

public static void main(String[] args) {
    Queue<String> queue = new LinkedList<>();
    queue.add("Ishfaq");
    queue.add("Ramzan");
    queue.add("Nagoo");
    queue.add("Bangalore");

    System.out.println("Linked List Queue is:" + queue);
    System.out.println("Linked List Queue Peek is :" + queue.peek());

    queue.poll();
    System.out.println("Linked List Queue after remove is:" + queue);

    Queue<Integer> queuenew = new PriorityQueue<>();

    queuenew.add(2);
    queuenew.add(3);
    queuenew.add(1);
    queuenew.add(0);
    queuenew.add(4);

    System.out.println("Priority Queue is:" + queuenew);
    System.out.println("Priority Queue Peek is :" + queuenew.peek());

    int ieleFirst=queuenew.remove();
    System.out.println("Priority Queue Element Removed is:" + ieleFirst);
    int ieleSecond=queuenew.remove();
    System.out.println("Priority Queue Element Removed is:" + ieleSecond);
    System.out.println("Priority Queue after remove is:" + queuenew);
  }

}
</code>```

Output:

```<code>Linked List Queue is: [Ishfaq, Ramzan, Nagoo, Bangalore]

Linked List Queue Peek is: Ishfaq

Linked List Queue after remove() is: [Ramzan, Nagoo, Bangalore]

Priority Queue is: [0, 1, 2, 3, 4]

Priority Queue Peek is: 0

Priority Queue Element Removed is: 0

Priority Queue Element Removed is: 1

Priority Queue after remove() is: [2, 3, 4]
</code>```

Title: priority queue vs linked list java

Body:
I was solving BFS problem. I used PriorityQueue but I was getting wrong answer, then I used LinkedList, I got right ans. I'm unable to find the difference between them. Here are both the codes. Why both the answers are different?

Code1:
        LinkedList q=new LinkedList();
        q.add(src);
        dist[src]=0;
        visited[src]=1;
        while(!q.isEmpty()){
            u=(int)(Integer) q.remove(0);
            for (int k = 0; k < n; k++) {
                if(a[u][k]==1 && visited[k]==0)
                {
                    dist[k]=dist[u]+1;
                    q.add(k);
                    visited[k]=1;
                }
            }
        }

Code 2:
    PriorityQueue<Integer> q= new PriorityQueue<>();
        q.add(src);
        dist[src]=0;
        visited[src]=1;
        while(!q.isEmpty()){
            u=q.remove();
            for (int k = 0; k < n; k++) {
                if(a[u][k]==1 && visited[k]==0)
                {
                    dist[k]=dist[u]+1;
                    q.add(k);
                    visited[k]=1;
                }
            }
        }

Also when I used Adjacency List instead of Adjacency matrix, Priority Queue implementation gave right ans.

Body:
PriortiyQueue as well as Linkedlist implement the Queue Interface and perform operations same the way as a Queue (FIFO).
The difference between PriorityQueue and Linkedlist is at the time of insertion PriorityQueue will be sorted as well as ordered as per the natural order but we can add a Commparator also in order to define the particular order of sorting for a record, while as LinkedList will be just ordered.
So while you are trying to add elements in PriorityQueue, they will get sorted on the basis of their natural order or as per the comparator function.

import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

public class QueueInJava {

public static void main(String[] args) {
    Queue<String> queue = new LinkedList<>();
    queue.add("Ishfaq");
    queue.add("Ramzan");
    queue.add("Nagoo");
    queue.add("Bangalore");

    System.out.println("Linked List Queue is:" + queue);
    System.out.println("Linked List Queue Peek is :" + queue.peek());

    queue.poll();
    System.out.println("Linked List Queue after remove is:" + queue);

    Queue<Integer> queuenew = new PriorityQueue<>();

    queuenew.add(2);
    queuenew.add(3);
    queuenew.add(1);
    queuenew.add(0);
    queuenew.add(4);

    System.out.println("Priority Queue is:" + queuenew);
    System.out.println("Priority Queue Peek is :" + queuenew.peek());

    int ieleFirst=queuenew.remove();
    System.out.println("Priority Queue Element Removed is:" + ieleFirst);
    int ieleSecond=queuenew.remove();
    System.out.println("Priority Queue Element Removed is:" + ieleSecond);
    System.out.println("Priority Queue after remove is:" + queuenew);
  }

}

Output:

Linked List Queue is: [Ishfaq, Ramzan, Nagoo, Bangalore]

Linked List Queue Peek is: Ishfaq

Linked List Queue after remove() is: [Ramzan, Nagoo, Bangalore]

Priority Queue is: [0, 1, 2, 3, 4]

Priority Queue Peek is: 0

Priority Queue Element Removed is: 0

Priority Queue Element Removed is: 1

Priority Queue after remove() is: [2, 3, 4]


问:
Akka serialization-bindings too limited?
Is is possible to further qualify the serialization-bindings?
The runtime type seems too limited.

e.g. I've got

```<code>trait PersistentExecutorProtocol[Payload] extends Serializable {
  sealed trait Event extends Serializable
  case class ToDo(value: Payload) extends Event
  case class Done(value: Long) extends Event
}
object AProtocolInstance extends PersistentExecutorProtocol[MyPayload]
object BProtocolInstance extends PersistentExecutorProtocol[OtherPayload]
</code>```

I'm now unable to serialize ToDo[MyPayload] with a different serializer than ToDo[OtherPayload] (even in different Actors!), because their runtime class name is equal (PersistentExecutorProtocol$ToDo).

Am I missing something? -Introducing an AProtocolClass or making PersistentExecutorProtocol an abstract class doesn't help.

答:
This isn't specific Akka but is a result of how concepts in Scala (path dependent types) does not map 1:1 with what the JVM can do. The Scala compiler needs to encode such concepts in a way that the JVM can understand and this can cause loss of information (just like with type erasure for example).

Selecting a serializer based on an object happens at runtime and at that point the information available before the compiler has done its job is lost and only the JVM specific information is still available.

You could maybe figure out some way around this with ClassTags etc. but the least risk of future grief is probably to declare Todo abstract and have the concrete subtypes inside of the concrete protocol instances which will allow you to bind different serialisers to the types.

You can se one way of doing that here: https://gist.github.com/johanandren/87fec0b627996a3f850513b81e0a8d66

Body:
Is is possible to further qualify the serialization-bindings?
The runtime type seems too limited.

e.g. I've got

trait PersistentExecutorProtocol[Payload] extends Serializable {
  sealed trait Event extends Serializable
  case class ToDo(value: Payload) extends Event
  case class Done(value: Long) extends Event
}
object AProtocolInstance extends PersistentExecutorProtocol[MyPayload]
object BProtocolInstance extends PersistentExecutorProtocol[OtherPayload]

I'm now unable to serialize ToDo[MyPayload] with a different serializer than ToDo[OtherPayload] (even in different Actors!), because their runtime class name is equal (PersistentExecutorProtocol$ToDo).

Am I missing something? -Introducing an AProtocolClass or making PersistentExecutorProtocol an abstract class doesn't help.


问:
Move view with keyboard using Swift
I have an app that has a text field on the lower half of the view.
This means that when I go to type in the text field the keyboard covers the textfield.

How would I go about moving the view upwards while typing so I can see what i'm typing and then moving it back down to its original place when the keyboard disappears?

I've looked everywhere but all the solutions appear to be in Obj-C which I can't quite convert just yet.

Any help would be greatly appreciated.

答:
if you are like me who has tried all the above solutions and still your problem is not solved, I have a got a great solution for you that works like a charm. First I want clarify few things about some of solutions mentioned above.

In my case IQkeyboardmanager  was working only when there is no auto layout applied on the elements, if it is applied then IQkeyboard manager will not work the
way we think.

Same thing with upward movement of  self.view.

i have wriiten a objective c header with a swift support for pushing UITexfield upward when user clicks on it, solving the problem of keyboard covering the UITextfield : https://github.com/coolvasanth/smart_keyboard.

One who has An intermediate or higher level in iOS app development can easily understand the repository and implement it. All the best

Title: Move view with keyboard using Swift


问:
A PHP Error was encountered Severity: Notice Message: Undefined variable: result

A PHP Error was encountered Severity: Notice

Message: Undefined variable: result

Filename: user/messages.php

Line Number: 87

Backtrace:

File: E:\xampp\htdocs\ci\application\views\user\messages.php Line: 87
  Function: _error_handler

File: E:\xampp\htdocs\ci\application\controllers\users\Dashboard.php
  Line: 12 Function: view

File: E:\xampp\htdocs\ci\index.php Line: 315 Function: require_once

here is my code
Controller

```<code>      <?php defined('BASEPATH') OR exit('No direct script access allowed');
        class Bills extends CI_Controller{
       function __construct(){
      parent::__construct();
     }

     public function bill(){
     $id = $this->session->userdata('email');
     $this->load->database();
     $this->load->helper(array('form', 'url', 'html'));
     $this->load->model('fuser/Bill');
     $data['result'] = $this->Bill->bills();
     $this->load->view('user/messages',$data);
      }
      }
      ?>

**Model**

      <?php
     class Bill extends CI_Model
     {
      function __construct()
      {
         // Call the Model constructor
         parent::__construct();
      }
      //we will use the select function
      public function bills($id)
      {
         //data is retrive from this query

     $query = $this->db->get('invoices');
       return $query->result();
      }

      }
     ?>

**View**
      <div class="billing_tabs_text_part">
                <?php foreach($result as $row){?>
                  <p><?php echo $row['book_id']; }?></p>
                </div>
</code>```

答:
You need to find where the problem is exactly

try to var_dump the results and see if you're actually getting any results and that result is not a null or false;

so before this line:
$data['result'] = $this->Bill->bills();

try to

```<code>var_dump($this->Bill->bills());
die();
</code>```

if you're getting results try the other way using dummy content instead of $this->Bill->bills(); use :

$data['result'] = [0 => 1, 1 =>2]; and var_dump from the view

see if you're getting results, and in line where you have

```<code>  return $query->result();
</code>```

make it like this:

```<code>  return $query->result() ? : [];
</code>```

Body:
A PHP Error was encountered Severity: Notice

Message: Undefined variable: result

Filename: user/messages.php

Line Number: 87

Backtrace:

File: E:\xampp\htdocs\ci\application\views\user\messages.php Line: 87
  Function: _error_handler

File: E:\xampp\htdocs\ci\application\controllers\users\Dashboard.php
  Line: 12 Function: view

File: E:\xampp\htdocs\ci\index.php Line: 315 Function: require_once

here is my code
Controller

      <?php defined('BASEPATH') OR exit('No direct script access allowed');
        class Bills extends CI_Controller{
       function __construct(){
      parent::__construct();
     }

     public function bill(){
     $id = $this->session->userdata('email');
     $this->load->database();
     $this->load->helper(array('form', 'url', 'html'));
     $this->load->model('fuser/Bill');
     $data['result'] = $this->Bill->bills();
     $this->load->view('user/messages',$data);
      }
      }
      ?>

**Model**

      <?php
     class Bill extends CI_Model
     {
      function __construct()
      {
         // Call the Model constructor
         parent::__construct();
      }
      //we will use the select function
      public function bills($id)
      {
         //data is retrive from this query

     $query = $this->db->get('invoices');
       return $query->result();
      }

      }
     ?>

**View**

                <?php foreach($result as $row){?>

<?php echo $row['book_id']; }?>

Body:
You need to find where the problem is exactly

try to var_dump the results and see if you're actually getting any results and that result is not a null or false;

so before this line:
$data['result'] = $this->Bill->bills();

try to

var_dump($this->Bill->bills());
die();

if you're getting results try the other way using dummy content instead of $this->Bill->bills(); use :

$data['result'] = [0 => 1, 1 =>2]; and var_dump from the view

see if you're getting results, and in line where you have

  return $query->result();

make it like this:

  return $query->result() ? : [];