相关疑难解决方法(0)

为什么"System.out.println"在Android中不起作用?

我想在控制台中打印一些东西,以便我可以调试它.但由于某种原因,我的Android应用程序中没有任何内容.

我该怎么调试呢?

public class HelloWebview extends Activity {
    WebView webview;    
    private static final String LOG_TAG = "WebViewDemo";
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new HelloWebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setWebChromeClient(new MyWebChromeClient());
        webview.loadUrl("http://example.com/");    
        System.out.println("I am here");
    }
Run Code Online (Sandbox Code Playgroud)

java printing console android system

185
推荐指数
3
解决办法
22万
查看次数

"std :: cout"在Android-ndk中是否可用

在Android-ndk中,我们可以使用"__android_log_write","_ _ android_log_print"等来将消息输出到"LogCat"窗口.如果我使用"std :: cout"输出一些字符串怎么样?例如

std::cout << "some strings" << std::endl;
Run Code Online (Sandbox Code Playgroud)

字符串将在何处发送.

似乎Android没有控制台应用程序,并且可能无法发送上述字符串.我可以将"stdout"重定向到文件,以便将字符串发送到"std :: cout"等同于记录消息吗?

c++ console android-ndk

37
推荐指数
2
解决办法
2万
查看次数

将stdout重定向到Android NDK中的logcat

我无法让我的Nexus S(运行Android 4.0)将本地stdout消息重定向到logcat.我读过我需要这样做:

$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
Run Code Online (Sandbox Code Playgroud)

但是,这似乎不起作用.(它确实打破了JUnit,如这里所提到的,所以它并非没有效果.)

作为参考,这是我的代码:

package com.mayastudios;

import android.util.Log;

public class JniTester {

  public static void test() {
    Log.e("---------", "Start of test");
    System.err.println("This message comes from Java.");    
    void printCMessage();
    Log.e("---------", "End of test");
  }

  private static native int printCMessage();

  static {
    System.loadLibrary("jni_test");
  }
}
Run Code Online (Sandbox Code Playgroud)

和JNI .c文件:

JNIEXPORT void JNICALL
Java_com_mayastudios_JniTester_printCMessage(JNIEnv *env, jclass cls) {
  setvbuf(stdout, NULL, _IONBF, 0);
  printf("This message comes from C (JNI).\n"); …
Run Code Online (Sandbox Code Playgroud)

android android-ndk

33
推荐指数
6
解决办法
3万
查看次数

标签 统计

android ×2

android-ndk ×2

console ×2

c++ ×1

java ×1

printing ×1

system ×1