Android运行错误:No Launcher activity found! The launch will only sync the application package on the device!

在Eclipse环境下运行Android应用提示错误:

No Launcher activity found!
The launch will only sync the application package on the device!

此错误一般发生说明在你的manifest.xml中没有为action设置android.intent.action.MAIN指定的activity,也就是没有告诉程序哪个activity作为主activity来启动,就会出现前面错误提示。
正确manifest.xml文件实例:

<activity>
      android:name="mars.mp3player.Mp3ListActivity"
      android:label="@string/app_name" >
      <intent-filter >  
             <action android:name="android.intent.action.MAIN" />  
             <category android:name="android.intent.category.LAUNCHER" />  
      </intent-filter>
</activity>

<activity></activity>内部的intent-filter就是用来指定这个activity为程序入口启动的activity,加入这个intent-filter就可以正常运行了!

但是可悲的是我在加入这段intent-filter之后还是出现错误,原来在创建程序的时候,我并没有创建布局文件,导致layout未指定。具体就在上面代码中提到的android:name="mars.mp3player.Mp3ListActivity"这个Mp3ListActivity文件中的这段代码中:

public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

setContentView(R.layout.main);这句代买没有加上,所以无法找到布局文件,就会提示错误,这里的main上面那个Activity启动需要加载的布局文件;至此,完成运行。

Android运行错误:No Launcher activity found! The launch will only sync the application package on the device!

原文链接:https://beltxman.com/1148.html,若无特殊说明本站内容为 行星带 原创,未经同意禁止转载。

Scroll to top