2

I knew this question may be not interesting , But I want to use string function in another function. Here is my code:

example.java:

public native String sendMessage(String jid, String message);
.
.
.
ImageButton1.setOnClickListener( new OnClickListener() {
    @Override
    public void onClick(View v) {
         final String m_Text = EditText1.getText().toString();
         if (m_Text.length() > 0){
            notifyMessage (m_Text);                            
            String uid = new String ();
            uid = sendMessage(final_jid , m_Text);                            
            alertDialog.dismiss();
        }
    }
});

example.cpp:

JNIEXPORT jstring JNICALL Java_org_qtproject_example_myapplication_MiniXmppService_sendMessage(
        JNIEnv *env, jobject obj, jstring jid, jstring message)
{
std::string sjid;
jstrToStdStr(env, jid, sjid);

if (g_bot)
{
    CMessageSession *session = g_bot->getOutgoingSessionForJid(sjid);

    if (session)
    {
        std::string smessage;
        jstrToStdStr(env, message, smessage);
        g_bot->m_mutexClient.lock();
        jstring res = env->NewStringUTF(session->session->send(smessage).c_str());
        g_bot->m_mutexClient.unlock();
        return res;
    }
}

return env->NewStringUTF("uid-*-*");
}

And I got an error: non-static method sendMessage(String,String) cannot be referenced from a static context

How to fix it?

Farzan Najipour
  • 2,442
  • 7
  • 42
  • 81

0 Answers0