运行不了main方法

运行不了main方法

请问老师,我这个直接运行main报这个错是什么原因?http://img1.sycdn.imooc.com//climg/5dbc433f095ec4d221600386.jpg

正在回答

登陆购买课程后可参与讨论,去登陆

3回答

提示main方法没有找到,你可以把main()方法贴出来方便老师帮你找下原因

http://img1.sycdn.imooc.com//climg/5dbf8c11094b2c2107350400.jpg

好帮手慕雪 2019-11-03 18:13:19

http://img1.sycdn.imooc.com//climg/5dbea6520969a72906830648.jpg

1)首先,这两块的大版本要一致。怀疑你中间更新过版本,此时的版本与项目中的版本不一致,所以导致无法运行。你可以测试是不是AS的问题,直接运行主activity看能不能正常运行,如果不能则建议重新建一个工程,注意不是module而是poject哦。以后就用新的poject。

2)另外你是怎么运行的,是点左侧的绿色三角吗?AS工具也有bug,第一次点它可能运行不了,你第二次点就可以运行了。

http://img1.sycdn.imooc.com//climg/5dbea69b0982f75a06750392.jpg


  • 提问者 霁雪寒霄 #1
    老师按照您的方法我新建了一个Project,右键运行后又出现了这样的错误: 19:58:20: Executing task 'UdpServer.main()'... Executing tasks: [UdpServer.main()] in project D:\Android\Socket_Project FAILURE: Build failed with an exception. * Where: Initialization script 'C:\Users\GQ\AppData\Local\Temp\UdpServer_main__.gradle' line: 20 * What went wrong: A problem occurred configuring project ':app'. > Could not create task ':app:UdpServer.main()'. > SourceSet with name 'main' not found. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 0s 19:58:20: Task execution finished 'UdpServer.main()'.
    2019-11-03 20:14:41
好帮手慕雪 2019-11-03 10:58:06

你把bulid.gradle文件中的testInstrumentationRunner 'androidx.test.ext.junit.runners.AndroidJUnit4'
引用改为 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"  再试一下呢。

  • 提问者 霁雪寒霄 #1
    依旧报同样的错。build.gradle里面代码如下: android { compileSdkVersion 28 buildToolsVersion "29.0.1" defaultConfig { applicationId "com.imooc.socket" minSdkVersion 14 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }
    2019-11-03 12:23:59
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
Android数据通信开发与应用2018版
  • 参与学习           人
  • 提交作业       147    份
  • 解答问题       687    个

本专题介绍了Android开发核心组件:广播、服务及全局应用。教会你如何使用AIDL、Thread、Socket、蓝牙解决进程线程间通信问题。利用Glide等实现异步加载及NDK原生代码开发。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码