Android Studio运行main方法报错 SourceSet with name ‘main‘ not found
16lz
2021-01-23
Android Studio 运行Java main方法报错
问题描述:
今天在Android Studio上新建了个工程,想运行个Java Main方法做个测试。写了个Main方法运行,结果报错了。
public class Test { public static void main(String[] args) { System.out.println("hello world"); }}
报错信息如下:
A problem occurred configuring project ':Test'.> Could not create task ':Test:Test.main()'. > SourceSet with name 'main' not found. >
意思是找不到 main 方法。
解决办法:
我的原因是在新建工程的时候选择的是 Android Library。然后应该使用gradle编译的,所以导致了找不到这个 main 方法。
解决方法就是新建工程的时候选择 Java or Kotlin Library 。在这个工程中在运行相同的代码就可以成功。
更多相关文章
- 针对4.0版本及以上版本的sharedpreferences不能两工程间通信的解
- 谷歌开发工具android studio启动不了的解决方法
- android adb push 与 adb install的比较(两种安装APK的方法)
- 解决style attribute ‘@android:attr/windowEnterAnimation’ n
- Android 应用程序退出的四种方法
- Android绘图之Paint的使用方法详解
- 导入Android工程提示The project was not built since
- Android Studio查看SQLite数据库方法大全
- 再说Android中实现全屏的方法