把log.i放到android的正确位置

时间:2014-06-08 18:06:11

标签: 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 

2 个答案:

答案 0 :(得分:3)

代码中的

Log默认转到logcat

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

单击“Logcat”选项卡以查看设备端日志。

答案 1 :(得分:1)

这些不是错误,而是控制台日志,它显示与应用启动相关的消息。

`Warning: Activity not started, its current task has been brought to the front`

要解决此问题,您必须在模拟器/手机中手动关闭应用程序。

通常会生成此警告,用户不会对代码进行任何更改。重新运行它。

要解决此问题,请在模拟器/手机中手动关闭应用程序或修改某些代码。

更新:

如果您的logcat甚至没有显示一行,那么重启Eclipse