java - Android 上放置 log.i 的正确位置

标签 java android

我正在尝试学习和测试日志文件。下面是我的代码。如何解决这个问题?

   public class MainActivity extends ActionBarActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            final String hello=getResources().getString(R.string.hello_world);
            final String STRING_TAG = "Testing: ";
            Log.i(STRING_TAG," String1 " + hello);


            if (savedInstanceState == null) {
                getSupportFragmentManager().beginTransaction()
                        .add(R.id.container, new PlaceholderFragment())
                        .commit();
            }
        }


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {

            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }

        /**
         * A placeholder fragment containing a simple view.
         */
        public static class PlaceholderFragment extends Fragment {

            public PlaceholderFragment() {
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                View rootView = inflater.inflate(R.layout.fragment_main, container, false);
                return rootView;
            }
        }

    }

我收到以下错误。

[2014-06-09 00:09:48 - test1] Android Launch!
[2014-06-09 00:09:48 - test1] adb is running normally.
[2014-06-09 00:09:48 - test1] Performing com.example.test1.MainActivity activity launch
[2014-06-09 00:09:48 - test1] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 't1'
[2014-06-09 00:09:52 - test1] Application already deployed. No need to reinstall.
[2014-06-09 00:09:52 - test1] Starting activity com.example.test1.MainActivity on device emulator-5554
[2014-06-09 00:09:55 - test1] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.test1/.MainActivity }
[2014-06-09 00:09:55 - test1] ActivityManager: Warning: Activity not started, its current task has been brought to the front
[2014-06-09 00:11:45 - test1] Dx 

最佳答案

Log 代码中默认转到 logcat

您发布的输出不是 logcat,而是 IDE 控制台(并且没有错误 - 只是启动应用程序时看到的常见消息)

点击“Logcat”选项卡可查看设备端日志。

关于java - Android 上放置 log.i 的正确位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24109215/

相关文章:

java - 关于 XML 布局和自定义 android 类

android - 如何重启安卓模拟器并保留系统数据

java - 创建现有对象的 Java 数组

java - getSupportFragmentManager 错误

android - FLAG_KEEP_SCREEN_ON 反向工作

java - 我想要通用类的 "Class<T>"和 "Class variable"

android - 有什么办法可以抓取我的 native android 应用程序

java - 为什么这段代码会跳过文件的第一行?

java - 如何更改 freemarker 中的 DOCTYPE?

java - JSON 字符串到 Java 字符串