Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-336] I met a problem ! who can help me?

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2011-04-15T02:27:27.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
Reporterstruggermen
AssigneeReggie Seagraves
Created2011-04-15T02:27:27.000+0000
Updated2017-03-09T21:13:56.000+0000

Description

Hi,Donald Thorp
In my develop programe,I want to use jni , use javah create .h files

in my c files

include "com_android_jnitest_jnitest.h"

include <string.h>

JNIEXPORT jstring JNICALL Java_com_android_jnitest_jnitest_fpathchange
(JNIEnv *env,jobject obj,jstring filename){

//调用 java 类 tiros_files 中的 getPath() 方法

  jclass cls =(*env)->FindClass(env,"com/android/jnitest/tiros_files");

  // 这里传过来一个 private Context context = null Context 

  jmethodID cls_mid = (*env)->GetMethodID(env,cls,"tr_java_fpathchange","(Ljava/lang/String;)Ljava/lang/String;");

  jstring  str = (*env) ->CallObjectMethod(env, cls , cls_mid ,"java/lang/String;" );

  return str;

}

In my java programe

public class jnitest extends Activity {

public String str = "my love is liping!" ;

public TextView tv = null ;

public Button  bt = null ;

private tiros_files tf = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tv = (TextView)this.findViewById(R.id.t1);
    bt = (Button)this.findViewById(R.id.rb);

    bt.setOnClickListener(btlistener);


   tf = new tiros_files(this);

}

Button.OnClickListener  btlistener =new Button.OnClickListener(){

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

         tv.setText(""+fpathchange(str));

    }

};

static{

    System.loadLibrary("jnitest");

}

/**
 * 
 * @param filename 文件名
 * @return 文件路径
 */
public native String fpathchange(String filename);

}

public class tiros_files {

private Context context = null;

public tiros_files(Context cont){

    this.context = cont;

    Log.v("context", "init ok!");

}

//获取文件路径
public  String tr_java_fpathchange(String filename){

    Log.v("tr_java_fpathchange", "ok!");

    String filepath = null;

    boolean is =filename.contains("$");

    if(is){

        String substr = filename.substring(0, 2);

        if(substr.equals("fs0")){ //手机内部 /data/data/packagename/files/filename

            String pakgename =context.getPackageName();

            filepath =Environment.getDataDirectory()+"/data/"+pakgename+"/files/"+filename;

        }
        else if(substr.equals("fs1")){ //  /sdcard/navidog/files/filename 


            filepath =Environment.getExternalStorageDirectory()+"/navidog/files/"+filename;
        }
        else{

            return "file path format is false";

        }
    }

    return filepath;
}

}

Log cat :

01-11 06:03:49.617: INFO/DEBUG(547): Build fingerprint: 'generic/sdk/generic/:1.5/CUPCAKE/150240:eng/test-keys'
01-11 06:03:49.626: INFO/DEBUG(547): pid: 6093, tid: 6093 >>> com.android.jnitest <<<
01-11 06:03:49.626: INFO/DEBUG(547): signal 11 (SIGSEGV), fault addr 000000ee
01-11 06:03:49.638: INFO/DEBUG(547): r0 000000e4 r1 41049a98 r2 00000000 r3 43744ab8
01-11 06:03:49.638: INFO/DEBUG(547): r4 41684dda r5 41049aa8 r6 bedbc5e0 r7 ad00e540
01-11 06:03:49.648: INFO/DEBUG(547): r8 000053f8 r9 00000000 10 41049a84 fp 00000000
01-11 06:03:49.648: INFO/DEBUG(547): ip 00000006 sp bedbc5a0 lr ad01236c pc ad013084 cpsr 00000010
01-11 06:03:49.748: INFO/DEBUG(547): #00 pc 00013084 /system/lib/libdvm.so
01-11 06:03:49.757: INFO/DEBUG(547): #01 pc 00017b1c /system/lib/libdvm.so
01-11 06:03:49.766: INFO/DEBUG(547): #02 pc 00017560 /system/lib/libdvm.so
01-11 06:03:49.779: INFO/DEBUG(547): #03 pc 00052268 /system/lib/libdvm.so
01-11 06:03:49.787: INFO/DEBUG(547): #04 pc 000596ee /system/lib/libdvm.so
01-11 06:03:49.796: INFO/DEBUG(547): #05 pc 00013118 /system/lib/libdvm.so
01-11 06:03:49.808: INFO/DEBUG(547): #06 pc 00017b1c /system/lib/libdvm.so
01-11 06:03:49.818: INFO/DEBUG(547): #07 pc 00017560 /system/lib/libdvm.so
01-11 06:03:49.827: INFO/DEBUG(547): #08 pc 000520ec /system/lib/libdvm.so
01-11 06:03:49.836: INFO/DEBUG(547): #09 pc 0003f0f8 /system/lib/libdvm.so
01-11 06:03:49.836: INFO/DEBUG(547): #10 pc 00031ac2 /system/lib/libdvm.so
01-11 06:03:49.848: INFO/DEBUG(547): #11 pc 00028280 /system/lib/libandroid_runtime.so
01-11 06:03:49.857: INFO/DEBUG(547): #12 pc 00028d7e /system/lib/libandroid_runtime.so
01-11 06:03:49.867: INFO/DEBUG(547): #13 pc 00008bf2 /system/bin/app_process
01-11 06:03:49.867: INFO/DEBUG(547): #14 pc 0001fd22 /system/lib/libc.so
01-11 06:03:49.876: INFO/DEBUG(547): #15 pc 0000bcb2 /system/lib/libc.so
01-11 06:03:49.888: INFO/DEBUG(547): #16 pc b000157e /system/bin/linker
01-11 06:03:49.907: INFO/DEBUG(547): stack:
01-11 06:03:49.918: INFO/DEBUG(547): bedbc560 00000000
01-11 06:03:49.918: INFO/DEBUG(547): bedbc564 ad058c5b /system/lib/libdvm.so
01-11 06:03:49.918: INFO/DEBUG(547): bedbc568 00000002
01-11 06:03:49.918: INFO/DEBUG(547): bedbc56c 4000ca60
01-11 06:03:49.918: INFO/DEBUG(547): bedbc570 ad083e10
01-11 06:03:49.927: INFO/DEBUG(547): bedbc574 00000000
01-11 06:03:49.927: INFO/DEBUG(547): bedbc578 00000000
01-11 06:03:49.938: INFO/DEBUG(547): bedbc57c 00000000
01-11 06:03:49.938: INFO/DEBUG(547): bedbc580 afe0d920 /system/lib/libc.so
01-11 06:03:49.948: INFO/DEBUG(547): bedbc584 bedbc5e0 [stack]
01-11 06:03:49.948: INFO/DEBUG(547): bedbc588 ad00e540 /system/lib/libdvm.so
01-11 06:03:49.948: INFO/DEBUG(547): bedbc58c 41684bbe
01-11 06:03:49.948: INFO/DEBUG(547): bedbc590 41049a7c
01-11 06:03:49.948: INFO/DEBUG(547): bedbc594 bedbc5e0 [stack]
01-11 06:03:49.948: INFO/DEBUG(547): bedbc598 df002777
01-11 06:03:49.948: INFO/DEBUG(547): bedbc59c e3a070ad
01-11 06:03:49.967: INFO/DEBUG(547): #00 bedbc5a0 43731360
01-11 06:03:49.967: INFO/DEBUG(547): bedbc5a4 41048200
01-11 06:03:49.977: INFO/DEBUG(547): bedbc5a8 bedbc5e0 [stack]
01-11 06:03:49.987: INFO/DEBUG(547): bedbc5ac ad017ac4 /system/lib/libdvm.so
01-11 06:03:49.987: INFO/DEBUG(547): bedbc5b0 00000328
01-11 06:03:49.997: INFO/DEBUG(547): bedbc5b4 bedbc668 [stack]
01-11 06:03:49.997: INFO/DEBUG(547): bedbc5b8 0000bc60 [heap]
01-11 06:03:49.997: INFO/DEBUG(547): bedbc5bc 41049f04
01-11 06:03:49.997: INFO/DEBUG(547): bedbc5c0 00000000
01-11 06:03:49.997: INFO/DEBUG(547): bedbc5c4 ad017b20 /system/lib/libdvm.so
01-11 06:03:49.997: INFO/DEBUG(547): #01 bedbc5c8 400307a0
01-11 06:03:49.997: INFO/DEBUG(547): bedbc5cc 00000001
01-11 06:03:50.006: INFO/DEBUG(547): bedbc5d0 0000bc60 [heap]
01-11 06:03:50.006: INFO/DEBUG(547): bedbc5d4 ad017564 /system/lib/libdvm.so
01-11 06:03:50.487: DEBUG/dalvikvm(617): GC freed 9285 objects / 524376 bytes in 356ms
01-11 06:03:51.357: INFO/ActivityManager(577): Process com.android.jnitest (pid 6093) has died.
01-11 06:03:51.376: INFO/WindowManager(577): WIN DEATH: Window{43716278 com.android.jnitest/com.android.jnitest.jnitest paused=false}
01-11 06:03:51.598: WARN/InputManagerService(577): Got RemoteException sending setActive(false) notification to pid 6093 uid 10034
01-11 06:03:51.637: DEBUG/Zygote(549): Process 6093 terminated by signal (11)
01-11 06:19:23.288: DEBUG/dalvikvm(617): GC freed 9272 objects / 524192 bytes in 132ms

Comments

  1. Thomas Huelbert 2011-04-15

    housecleaning old bugs

  2. Lee Morris 2017-03-09

    Closing ticket as invalid.

JSON Source