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 8602951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:12:38+00:00 2026-06-12T02:12:38+00:00

Java code: package library; import java.nio.ByteBuffer; public class Library { static{System.loadLibrary(TestDLL);} native static void

  • 0

Java code:

package library;

import java.nio.ByteBuffer;

public class Library
{    
    static{System.loadLibrary("TestDLL");}

    native static void GetGLBuffer(ByteBuffer Buffer, int Width, int Height, int Size);

    public static void main(String[] args) {

        ByteBuffer B = ByteBuffer.allocateDirect(5);
        byte[] C = {'H', 'E', 'R', 'E', '\0'};
        B.put(C);
        GetGLBuffer(B, 0, 0, 4);
        System.out.println((char)B.get(0));
    }
}

C++ Code:

JNIEXPORT void JNICALL Java_library_Library_GetGLBuffer(JNIEnv *env, jclass cls, jobject buffer, jint Width, jint Height, jint Size)
{
    unsigned char* Buff = (unsigned char*)env->GetDirectBufferAddress(buffer);
    //*Buff = 'A'; Crashes it.
    //Buff[0] = 'A'; Crashes it.
    //std::cout<<Buff[0]; Prints fine but crashes when this function ends.
}

If I do nothing, it works perfectly fine. Also, if I declare variables within the function above, it crashes.

How do I fix it? Am I doing anything wrong?

It prints out this file: http://pastebin.com/Mz76Bk8G

  • 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-12T02:12:39+00:00Added an answer on June 12, 2026 at 2:12 am

    I just want to say that I solved it. I had to go into my JNI folder, copy the JNI.h and the JNI_MD.h for JDK 7 to my C++ project folder, include it as a file and also use a .def file to export.

    Without doing all of the above steps, it crashed the JVM. Now I’m not sure why but I’m just glad it works. I’m posting this to let others who have the same problem fix it.

    Thanx for the views guys. Was quite difficult to figure out what was wrong. Hope this comment helps others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a sample code package org.example; import java.lang.reflect.Method; class TestRef { public void
I have the following simple Java code: package testj; import java.util.*; public class Query<T>
Consider this code: package Prova; import java.util.ArrayList; public class Prova { private ArrayList<String> people;
Here is the server code package echoserver; import java.net.*; import java.io.*; public class EchoServer
The code is also at https://github.com/timp21337/java-generics-example package a; import java.util.List; public interface Container<T> {
The code- package myusic.app.activity; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter;
I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
Let's look at the following code snippet in Java. package division; import java.math.BigDecimal; final
Is there any good, simple Java Grep Library? I'm not opposed to native code,

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.