Search code examples
javaakkaakka-actor

Error - build method compilation Error at ReceiveBuilder, type scala.Product cannot be resolved


I am new to Akka-Actor.

Trying to run simple akka-actor program to understand akka-actor.

I am not able to resolve two compilation errors.

The method build() from the type AbstractPFBuilder<Object,BoxedUnit> refers to the missing type PartialFunction

AND

The type scala.Product cannot be resolved. It is indirectly referenced from required .class files. 

Compilation error at Props props() method.

The below one is actual code.

AkkaActor Program:

package com.abcplusd.akka;

import akka.actor.AbstractLoggingActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.japi.pf.ReceiveBuilder;

    public class AkkaStarted {

      static class Counter extends AbstractLoggingActor {
        static class Message {}
        private int count = 0;

        {
          receive(ReceiveBuilder
              .match(Message.class, this::onMessage)
              .build()
              );
        }

        private void onMessage(Message message) {
          count ++;
          System.out.println("Increased Counter: " + count);
        }
        public static Props props() {
          return Props.create(Counter.class);
        }

       }
      public static void main (String[] args) {
        ActorSystem system = ActorSystem.create("Sample1");
        final ActorRef counter =  system.actorOf(Counter.props(), "Counter");
        counter.tell(new Counter.Message(), ActorRef.noSender());
        System.out.println("Enter to Terminate");
      }

    }

AkkaActor version 2.4.9.

Below my pom.xml settings.

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <akka.version>2.4.9</akka.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.typesafe.akka</groupId>
      <artifactId>akka-actor_2.11</artifactId>
      <version>${akka.version}</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>2.12.4</version>
    </dependency>
  </dependencies>

Solution

  • Solved the compilation issues by changing scala-lang version.

    <dependency>
       <groupId>org.scala-lang</groupId>
       <artifactId>scala-library</artifactId>
       <version>2.11.8</version>
    </dependency>