2

Update: I downloaded authors source code, same issue happeded..... pom.xml file> https://gist.github.com/jianheMark/09c8e250f43d436ba51d27971c4ea5a2 Follow tutorial. But when I run it, then there is NullPointerException Error. I using Intellj.

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "cause" is null

All three classes in same package. I already checked on internet. I even comment out other xml files.

package javaconfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfig{

    @Bean(initMethod = "customInit")
    public Customer customer(){
        return new Customer();
    }
}


public class Customer {
    public Customer() {
        System.out.println("Default Constructor.......");
    }
    public void customInit() {
        System.out.println("Customer Init......");
    }
}



package javaconfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class JavaConfigMain {
    public  static void main(String[] args){
       
        new AnnotationConfigApplicationContext(AppConfig.class);
    }
}

I follow this tutorial: https://www.youtube.com/watch?v=0awHx-346Is&list=PLGTrAf5-F1YIUo_AWConTTY_VWGJnveT8&index=15

Full Error Code:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "cause" is null
    at org.springframework.cglib.core.CodeGenerationException.<init>(CodeGenerationException.java:25)
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:587)
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363)
    at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108)
    at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
    at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134)
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319)
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:572)
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:419)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:447)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:268)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:325)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:147)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:93)
    at javaconfig.JavaConfigMain.main(JavaConfigMain.java:12)
jian
  • 4,119
  • 1
  • 17
  • 32

1 Answers1

0

This is an error that occurs when the package name starts with 'java', so it can be resolved by deleting 'java' from the package name.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 04 '22 at 18:30
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31455456) – Prasanth Rajendran Apr 06 '22 at 17:55