为什么没有“System.out.println”在Android中工作? [英] Why doesn't "System.out.println" work in 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;
}
}
/ **在首次创建活动时调用。 * /
@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);
}
/ strong> 原始: 请使用 每个记录调用的第一个条目是标记源的日志标记的日志消息。这是有帮助的,因为您可以过滤日志的输出以仅显示您的消息。要确保您与日志标记一致,最好将其定义为 文档说明了关于级别的以下内容: 除非在开发期间,否则不应将Verbose编译到应用程序中。调试日志在编译时在运行时被剥离。错误,警告和信息日志始终保留。 I want to print something in console, so that I can debug it. But for some reason, nothing prints in my Android application. How do I debug then?
Correction:
On the emulator and most devices Original:
There is no console to send the messages to so the Instead, you can use the Android You can then view the log either in the Logcat view in Eclipse, or by running the following command: It's good to get in to the habit of looking at logcat output as that is also where the Stack Traces of any uncaught Exceptions are displayed. The first Entry to every logging call is the log tag which identifies the source of the log message. This is helpful as you can filter the output of the log to show just your messages. To make sure that you're consistent with your log tag it's probably best to define it once as a There are five one-letter methods in The documentation says the following about the levels: Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.
这篇关于为什么没有“System.out.println”在Android中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
在模拟器和大多数设备上 System.out.println
被重定向到LogCat并使用 Log.i ()
。这可能不是真的在很老的或自定义Android版本。
没有控制台发送消息,因此系统。 out.println
消息丢失。同样,当你使用 javaw
运行一个传统的Java应用程序时也会发生这种情况。
static final String
某处。
Log.d(MyActivity.LOG_TAG,Application started);
Log
对应于以下级别:
e()
- 错误
w()
- 警告
i $ c> - 信息
d()
- 调试
wtf()
- 可怕的失败
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");
}
System.out.println
gets redirected to LogCat and printed using Log.i()
. This may not be true on very old or custom Android versions. System.out.println
messages get lost. In the same way this happens when you run a "traditional" Java application with javaw
.Log
class:Log.d("MyApp","I am here");
adb logcat
static final String
somewhere.Log.d(MyActivity.LOG_TAG,"Application started");
Log
corresponding to the following levels:
e()
- Errorw()
- Warningi()
- Informationd()
- Debugv()
- Verbosewtf()
- What a Terrible Failure