我在eclipse上使用java并学习如何为android创建应用程序。我写了一个非常简单的“Hello World”应用程序,只显示文本以确保应用程序运行。为什么Eclipse不推送最新版本的应用程序?
然后我开始添加代码,但设备仍然只显示helloworld,所以我只写了以下内容并尝试运行它,因为这里没有错误。
package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
public static void main(String[] args) {
System.out.println("Hello, World1");
System.out.println("Hello, World2");
}
}
在控制台上,我得到了
[2014-01-07 23:35:09 - HelloWorld] ------------------------------
[2014-01-07 23:35:09 - HelloWorld] Android Launch!
[2014-01-07 23:35:09 - HelloWorld] adb is running normally.
[2014-01-07 23:35:09 - HelloWorld] Performing com.example.helloworld.MainActivity activity launch
[2014-01-07 23:35:13 - HelloWorld] Uploading HelloWorld.apk onto device xxxx-number removed by me-xxxx
[2014-01-07 23:35:13 - HelloWorld] Installing HelloWorld.apk...
[2014-01-07 23:35:15 - HelloWorld] Success!
[2014-01-07 23:35:16 - HelloWorld] Starting activity com.example.helloworld.MainActivity on device xxxx-number removed by me-xxxx
[2014-01-07 23:35:16 - HelloWorld] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]cmp=com.example.helloworld/.MainActivity }
我已清理该项目,并卸载了手动设备的应用程序,并试运行它,但我仍然得到旧的“你好,世界”,而不是“你好,World1”和“你好,World2”。
我在这里做错了什么?道歉,如果它是明显的东西,我不是伟大的Java或Android。
呃因为你不叫这种方法......? – tyczj
等,不会像在C++中一样自动退出主程序? – user3170281
在桌面上,当然。但是你现在在Android上。 –