Last modified: Apr 28, 2026 By Alexander Williams

Fix 'javapackage' Object Is Not Callable

This error happens when you try to call a Java package like a function. It is common when using the jpype library to run Java code from Python. The error message means you are treating a Java package as if it were a callable object, like a method or class. This guide explains why it occurs and how to solve it.

What Does This Error Mean?

Python shows this error when you use parentheses () on something that is not a function or class. A Java package is an object, but it is not callable. You cannot call it like java.lang(). The correct way is to access classes or methods inside the package.

For example, java.lang.String is a class, not a function. You must instantiate it or call its static methods directly.

Common Causes

Calling a package directly is the most common cause. You might write java.lang() instead of java.lang.String. Another cause is mixing Python and Java syntax. In Python, you import modules, but in Java, you use packages. The jpype library creates javapackage objects that represent Java packages. These objects are not callable.

A third cause is using the wrong import statement. If you use from java.lang import * incorrectly, you might get a package object instead of a class.

How to Reproduce the Error

Let’s see a simple example using jpype. First, install the library:

pip install jpype1

Now run this Python code:

import jpype
import jpype.imports

# Start JVM
jpype.startJVM()

# Try to call the Java package directly
result = java.lang()  # This causes the error

You will see this output:

TypeError: 'javapackage' object is not callable

How to Fix the Error

Do not call the package. Access the class inside the package instead. For example, use java.lang.String to get the String class. Then you can call its methods or create instances.

Here is the corrected code:

import jpype
import jpype.imports

# Start JVM
jpype.startJVM()

# Access the String class from java.lang package
String = java.lang.String  # No parentheses here

# Create a new String object
my_string = String("Hello, World!")  # Now you can call the class
print(my_string)

Output:

Hello, World!

Notice that java.lang is a package, but java.lang.String is a class. The class is callable because it has a constructor. The package is not callable.

Another Example with Custom Java Classes

Suppose you have a custom Java package called com.example. You might make this mistake:

import jpype
import jpype.imports

jpype.startJVM()

# Wrong: calling the package
result = com.example()  # Error

Fix it by accessing the class directly:

import jpype
import jpype.imports

jpype.startJVM()

# Correct: access the class inside the package
MyClass = com.example.MyClass
obj = MyClass()

Always check if you are using a package or a class. Packages are containers. Classes are callable.

How to Debug This Error

First, read the error traceback. It shows the exact line where you tried to call the package. Look for a line like java.lang() or com.example(). Remove the parentheses.

Second, print the type of the object. Use print(type(your_object)) to see if it is a javapackage or a class. If it is a javapackage, you need to go deeper into the package hierarchy.

Third, check your import statements. In jpype, you can import Java classes like Python modules. Use from java.lang import String for cleaner code.

Preventing the Error in the Future

Always remember: Java packages are not callable. Only Java classes and methods are callable. Use dot notation to navigate from package to class. For example, java.util.ArrayList is a class, but java.util is a package.

If you are new to jpype, read the official documentation. It explains how Java packages map to Python objects. Also, practice with simple examples before using complex Java libraries.

For more details on handling character encoding issues in Python, check our guide on Python Character Encoding Guide for Beginners. It helps you avoid similar type errors when working with strings.

Conclusion

The TypeError: 'javapackage' object is not callable is a simple mistake. You accidentally call a Java package like a function. The fix is to access the class inside the package instead. Use package.ClassName and then call the class constructor. Always verify the type of your object with print(type()). With practice, you will avoid this error and write clean Python-Java integration code.