Click here to Skip to main content
15,914,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have written a maven project with netbeans. When I run the program in Netbeans everything works. After building the project and running the Jar file with: java -jar filename.jar the program starts, but when I now execute one following function, I'll get a
java.lang.NoSuchMethodError:
exception. All the other functions are working.

What I have tried:

The Exception:

Extra Bytebuffer:
ByteBuffer length =217
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;
	at humer.kamera.PhraseUvcDescriptor.phraseUvcData(PhraseUvcDescriptor.java:116)
	at humer.kamera.CameraSearch.listDevice(CameraSearch.java:143)
	at humer.kamera.CameraSearch.autoSearchTheCamera(CameraSearch.java:85)
	at humer.kamera.Kam.AutoSearchTheCamerasActionPerformed(Kam.java:385)
	at humer.kamera.Kam.access$100(Kam.java:45)
	at humer.kamera.Kam$2.actionPerformed(Kam.java:281)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)


The Exception comes from this ByteBuffer:

public PhraseUvcDescriptor (ByteBuffer data) {
        this.uvcData = ByteBuffer.allocate(data.limit());
        this.uvcData = data.duplicate();
    }


And when I set the Position of the ByteBuffer:

        positionAbsolute += descSize;
        uvcData.position(positionAbsolute);

}


I'll get the Exception:

uvcData.position(positionAbsolute);
= Line 116

I don't know, why the ByteBuffer isn't working in the Jar file, because in Netbeans everything works.

Thanks,

Peter

Project Link on GitHub: GitHub - Peter-St/Linux_Jna_Kamera: Camera stream over Jna.[^]
Posted
Updated 12-Mar-19 1:45am
Comments
Richard MacCutchan 9-Mar-19 11:20am    
So which is the actual line that gives the error, and what is the method that is being complained about?
Peter____ 9-Mar-19 11:32am    
uvcData.position(positionAbsolute); gives the Error

uvcData is the ByteBuffer.

This method is in the file: PhraseUvcDescriptor.java (Link)
Peter____ 9-Mar-19 11:33am    
This is the whole method:

public int phraseUvcData() {
        try {
        ArrayList<byte []> frameData = new ArrayList<>();
        int formatcnt = 0;
        byte[] formatData = null;
        int positionAbsolute = 0;
        int posStart, posEnd;
        do  {
            
            int pos = uvcData.position();
            byte descSize = uvcData.get(pos);
            byte descType = uvcData.get(pos +1);
            byte descSubType = uvcData.get(pos + 2);
            
            
            if (descSubType == VS_format_uncompressed) {
                formatData = new byte [descSize];
                uvcData.get(formatData, 0 ,descSize);
                frameData = new ArrayList<>();
                printData(formatData);

            }
            else if (descSubType == VS_frame_uncompressed) {
                byte [] uncompressedFrameData = new byte [descSize];
                uvcData.get(uncompressedFrameData, 0 ,descSize);
                frameData.add(uncompressedFrameData);
                if (uvcData.get(pos + descSize + 2) != VS_frame_uncompressed) {
                    FormatIndex formatUncomprIndex = new FormatIndex(formatData, frameData);
                    formatUncomprIndex.init();
                    formatIndex.add(formatUncomprIndex);
                }
            }
            if (descSubType == VS_format_mjpeg) {
                formatData = new byte [descSize];
                uvcData.get(formatData, 0 ,descSize);
                frameData = new ArrayList<>();
                printData(formatData);
            }
            else if (descSubType == VS_frame_mjpeg) {
                byte [] mjpegFrameData = new byte [descSize];
                uvcData.get(mjpegFrameData, 0 ,descSize);
                frameData.add(mjpegFrameData);
                if (uvcData.get(pos + descSize + 2) != VS_frame_mjpeg) {
                    FormatIndex formatUncomprIndex = new FormatIndex(formatData, frameData);
                    formatUncomprIndex.init();
                    formatIndex.add(formatUncomprIndex);
                } 
            }
            positionAbsolute += descSize;
            uvcData.position(positionAbsolute);
        } while (uvcData.limit() > positionAbsolute);
        System.out.println("UvcDescriptor finished.");
        return 0;
        
        } catch ( Exception e ) {e.printStackTrace(); }
        
        return -1;
    }
Richard MacCutchan 9-Mar-19 12:38pm    
Where is the method (uvcData.position) that gives the error?
Peter____ 9-Mar-19 12:47pm    
on the bottom of the method (end of the while loop).
uvcData = Bytebuffer
and with the position methode implemented in Java Bytebuffer I have to set the position in The Byte buffer, because I have to read out at least 5 byte arrays with different length. The length of the ByteBuffer is about 200 Hex Values.

On solution could be, to use a byte array instead of the bytebuffer. I think this could be a bug.

1 solution

It usually happens when using jar files compiled with different versions of jdk

e.g. included file.jar compiled in 1.7 then jdk 9 is use to compile myapp.jar which imported class from file.jar


Changing Java JRE version to
java-11-openjdk-amd64
solved the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900