javalinuxwindowsuser-interfaceplatform-independent

My Java GUI Library working on windows not on Linux


I have a made a Java Library to show Android like Toast messages called JSubs : GitHub

Its working perfectly fine in my Windows 10 Computer.

enter image description here

But whenever I try it on Linux(Kali Linux) the system crashes and also the message does not show properly .

enter image description here

My Driver code :

import com.jaysmito.jsubs.JSubsConstants;
import com.jaysmito.jsubs.SubsFrame;
import com.jaysmito.jsubs.Toast;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception{
        Toast.showToast("Hello World!");
    }
}

I am not much experienced with Linux.

How can I make it computable with Linux too?


Solution

  • There is a problem with accessing uninitialised values of "instance" (probably because of the threads) where in "this" would be more appropriate because that is guaranteed to be set. For example the SubsFrame constructor calls handleFrameSize() yet handleFrameSize uses "instance" -> NullPointerException.

    Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "label" because "com.jaysmito.jsubs.SubsFrame.instance" is null
    

    Swing UI changes should not be run inside different threads. Do all Swing UI operations in the main calling thread (setting up first time) or later on in Event Dispatch thread. This affects all operations inside your new Thread(new Runnable ...) calls, use SwingUtilities.invokeLater(runnable); for the bits that change the UI in those background threads.

    I could run your app on Linux once fixed above and commented out:

     //    if(!this.isAlwaysOnTopSupported()){
     //        throw new Exception("Always on top is not supported!");
     //    }