Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7730139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:08:55+00:00 2026-06-01T06:08:55+00:00

UPDATE: I have somewhat resolved the issue. Just in case if anyone runs in

  • 0

UPDATE:

I have somewhat resolved the issue. Just in case if anyone runs in the same problem, here is the simplest solution: Looking at the MTApplcation source code, I have discovered that the initialize() method can be overloaded, taking a String parameter for the name of the class to instantiate. So if I create a separate class that extends MTApplication and pass it’s name there, everything works correctly.

END OF UPDATE

I have a situation in Scala while trying to use a java library (MT4j, which is based on Processing). The library wants to instantiate the main class of the app (the caller-class):

  Class<?> c = Thread.currentThread().getContextClassLoader().loadClass(name);
  applet = (PApplet) c.newInstance();

So as to refer it later in it’s works.

However, it fails because, I guess, the main Scala class is not a class, but an object and due to library structure, it is necessary to call a static method initialize() of the main library class MTApplication. In Java static fields are located in classes, but in Scala – in objects. So it is impossible to instantiate an object and the library fails. In contrast to MT4j, Processing itself makes no calls to static methods on startup and successfully passes that phase.

If I just create a companion class, everything works fine except that the companion class does not get its fields initialized because the static initialize() method is called in companion object, the class instance just gets dead-born and the library becomes unusable.

At least that is how I understand this problem.

I get this error:

Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalAccessException: Class processing.core.PApplet can not access a member of class main.Main$ with modifiers "private"
    at processing.core.PApplet.runSketch(PApplet.java:9103)
    at processing.core.PApplet.main(PApplet.java:9292)
    at org.mt4j.MTApplication.initialize(MTApplication.java:311)
    at org.mt4j.MTApplication.initialize(MTApplication.java:263)
    at org.mt4j.MTApplication.initialize(MTApplication.java:254)
    at main.Main$.main(Main.scala:26)
    at main.Main.main(Main.scala)

It is hard for me to explain also because I do not fully understand what is going on here. But anyone who has these libs can reproduce the situation in a couple of minutes, trying to launch the main class.

The abstract startUp() method which should be implemented to start the app, makes everything look even more sad. It initializes the object, but what the library tries to work with is an instance of the companion class which does not get initialized because in Scala the method belongs to the object.

My code:

object Main extends MTApplication {

    def main(args: Array[String]) {
        MTApplication.initialize()
        new Main().startUp()
    }

    //this method is abstarct so it MUST be implemented,
    override def startUp(){ 
    }

}

class Main extends MTApplication {

    override def startUp(){
       //startup here
    }
}

I am sorry if my explanations are vague, I just do not get it all completely. Probably to understand it is easier to repeat the experiment with MT4j library with Processing source code instead of the pre-linked ‘core.jar’ there to see what is happening inside. Doeas anyone have ideas on any workaround here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:08:56+00:00Added an answer on June 1, 2026 at 6:08 am

    Problem solved. Here is the solution:

    object Main {
    
        var current: MainC = _
    
        def main(args: Array[String]) {
            MTApplication.initialize("org.mttablescreen.main.MainC")
        }
    
    }
    
    class MainC extends MTApplication {
    
        //cons
        Main.current = this
    
        //cons ends
    
        override def startUp(){
            prepare
        }
    
        def prepare () {...}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been debugging a strange case for some days now, and have somewhat
UPDATE I have updated my code in response to @MichaelRushton comments. I am now
UPDATE - I have fixed some mistakes in the code below and the images
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.
I have scenario, I have two update panels on the page (both have update
I have an UPDATE statement that's intended to update a status field for a
I have an update program that is completely independent of my main application. I
I have and Update Panel with a Grid inside of it. The grid's data
I have the update frequency of my ClickOnce application set to weekly. What is
UPDATE: I should have mentioned in the original post that I want to learn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.