I want to show log file by Textview and Textview log file content is called by jni.
But Textview nothing show(blank black screen),When give just "hello /n How low",was shown by Textview correct. return (*env)->NewStringUTF(env, "hello /n How low"); was shown. return (*env)->NewStringUTF(env, str); was not shown.--application.java--
package com.showlog;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class showlog extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText( stringFromJNI(开发者_如何学Go) );
setContentView(tv);
}
public native String stringFromJNI();
public native String unimplementedStringFromJNI();
static {
System.loadLibrary("showlog");
}
}
--showlog.c--
#include <string.h>
#include <stdio.h>
#include <jni.h>
#define MAX 119 // MAX of one line length of log file
#define Log_file "./Log_file.log" // log file path
jstring
Java_com_showlog_stringFromJNI(JNIEnv* env, jobject thiz)
{
char line[120]; // one line length of Log_file
char str[2000]; // Log_file length
FILE *fin;
fin=fopen(Log_file, "r");
while( ! feof(fin)){
fgets(line, MAX, fin);
strcat(str, line);
}
fclose(fin);
return (*env)->NewStringUTF(env, str);
}
Then I try just c code(not be jni lib),It works.
--just show log file--#include <string.h>
#include <stdio.h>
#define MAX 119 // MAX of one line length of log file
#define Log_file "./Log_file.log" // log file path
main()
{
char line[120]; // one line length of Log_file
char str[2000]; // Log_file length
FILE *fin;
fin=fopen(Log_file, "r");
while( ! feof(fin)){
fgets(line, MAX, fin);
strcat(str, line);
}
fclose(fin);
printf("%s", str);
return 0;
}
How does Textview show it ?
Thanks in advance.Return value is not proper....just check it.....and return proper value.....
精彩评论