问题描述
我要打印的东西在控制台上,这样我就可以调试。但由于某些原因,没有打印在我的Android应用程序。
我该如何调试呢?
公共类HelloWebview延伸活动{
的WebView的WebView;
私有静态最后弦乐LOG_TAG =WebViewDemo;
私有类HelloWebViewClient扩展WebViewClient {
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
view.loadUrl(URL);
返回true;
}
}
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
的WebView =(web视图)findViewById(R.id.webview);
webview.setWebViewClient(新HelloWebViewClient());
webview.getSettings()setJavaScriptEnabled(真)。
webview.setWebChromeClient(新MyWebChromeClient());
webview.loadUrl(http://example.com/);
的System.out.println(我在这里);
}
解决方法:
在仿真器和大多数设备的System.out.println
被使用重定向到LogCat中和印刷 Log.i()
。这很老的或定制的Android版本可能不是真的。
原文:
没有控制台发送到这样的的System.out.println
邮件丢失的消息。以同样的方式出现这种情况,当你运行一个传统的Java应用程序 javaw进程
。
相反,您可以使用的Android 登录
类:
Log.d(MyApp的,我在这里);
然后,您可以在的logcat 查看在Eclipse中,或通过运行以下命令查看日志:
亚行logcat
这是很好的获得在看着作为输出的logcat的习惯,亦是屏幕上显示的任何未捕获的异常的堆栈跟踪。
第一个进入每个日志调用是标识日志消息来源的日志标签。这是有帮助的,你可以过滤日志的输出只显示您的邮件。为了确保你和你的日志标签一致它可能是最好的一次,将其定义为静态最后弦乐
的地方。
Log.d(MyActivity.LOG_TAG,应用程序启动);
有五分之一的字母的方法登录
对应以下级别:
-
E()
- 错误 -
W()
- 警告 -
I()
- 信息 -
D()
- 调试 -
V()
- 详细
借助文件说,下列有关水平的:
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?
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");
}
Correction:
On the emulator and most devices System.out.println
gets redirected to LogCat and printed using Log.i()
. This may not be true on very old or custom Android versions.
Original:
There is no console to send the messages to so the System.out.println
messages get lost. In the same way this happens when you run a "traditional" Java application with javaw
.
Instead, you can use the Android Log
class:
Log.d("MyApp","I am here");
You can then view the log either in the Logcat view in Eclipse, or by running the following command:
adb logcat
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 static final String
somewhere.
Log.d(MyActivity.LOG_TAG,"Application started");
There are five one-letter methods in Log
corresponding to the following levels:
e()
- Errorw()
- Warningi()
- Informationd()
- Debugv()
- Verbose
The documentation says the following about the levels:
这篇关于为什么不"的System.out.println"在Android的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!