2011-01-06 6 views
2

로그 파일을 Textview 및 Textview로 표시하려면 로그 파일 내용이 jni에 의해 호출됩니다.
하지만 Textview는 아무것도 표시하지 않습니다 (검은 색 빈 화면). 단지 "hello/n How Low"라고 지정하면 Textview가 올바르게 표시됩니다.
return (* env) -> NewStringUTF (env, "hello/n How low"); 보여졌다.
return (* env) -> NewStringUTF (env, str); 표시되지 않았습니다. --showlog.c--Textview에 jni가 표시되지 않습니다.

#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); 
} 

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()); 
     setContentView(tv); 
    } 

    public native String stringFromJNI(); 

    public native String unimplementedStringFromJNI(); 

    static { 
     System.loadLibrary("showlog"); 
    } 
} 

--application.java--

그럼 난 그냥 C 코드 (JNI LIB하지), 그것은 작동하려고합니다.
--just 쇼 로그를 보여 텍스트 뷰 않는 방법

#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; 
} 

을 file--?
미리 감사드립니다.

답변

0

반환 값이 올바르지 않습니다 .... 그냥 확인하고 ..... 적절한 값을 반환 .....

+0

고마워, 아마도 null을 반환합니다. 하지만 어떻게 디버깅 할 지 모르겠다. – tknv

관련 문제