android studio Run java的main方法失败
Posted mmsx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android studio Run java的main方法失败相关的知识,希望对你有一定的参考价值。
1、报错信息
A problem occurred configuring project ':app'.
> Could not create task ':app:DimenTool.main()'.
> SourceSet with name 'main' not found.
2、解决办法
在.idea文件夹下的gradle.xml文件中添加<option name="delegatedBuild" value="false" />,然后重新运行就可以了
然后重新点击需要运行的java 的mian方法就行。
3、分享和main测试
分享android studio 一个自动生成不同分辨率的dimens.xml尺寸适配的类,亲测好用。UI适配工具类。
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class DimenTool
public static void gen()
// File file = new File("./app/src/main/res/values/dimens.xml");
File file = new File("./chatLib/src/main/res/values/dimens.xml");
BufferedReader reader = null;
StringBuilder sw480 = new StringBuilder();
StringBuilder sw600 = new StringBuilder();
StringBuilder sw720 = new StringBuilder();
StringBuilder sw800 = new StringBuilder();
StringBuilder sw1080 = new StringBuilder();
try
System.out.println("生成不同分辨率:");
reader = new BufferedReader(new FileReader(file));
String tempString;
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null)
if (tempString.contains("</dimen>"))
//tempString = tempString.replaceAll(" ", "");
String start = tempString.substring(0, tempString.indexOf(">") + 1);
String end = tempString.substring(tempString.lastIndexOf("<") - 2);
int num = Integer.valueOf(tempString.substring(tempString.indexOf(">") + 1, tempString.indexOf("</dimen>") - 2));
sw480.append(start).append((int) Math.round(num * 0.6)).append(end).append("\\n");
sw600.append(start).append((int) Math.round(num * 0.75)).append(end).append("\\n");
sw720.append(start).append((int) Math.round(num * 0.9)).append(end).append("\\n");
sw800.append(tempString).append("\\n");
sw1080.append(start).append((int) Math.round(num * 2.5)).append(end).append("\\n");
else
sw480.append(tempString).append("\\n");
sw600.append(tempString).append("\\n");
sw720.append(tempString).append("\\n");
sw800.append(tempString).append("\\n");
sw1080.append(tempString).append("\\n");
line++;
reader.close();
System.out.println("<!-- sw480 -->");
System.out.println(sw480);
System.out.println("<!-- sw600 -->");
System.out.println(sw600);
System.out.println("<!-- sw720 -->");
System.out.println(sw720);
System.out.println("<!-- sw800 -->");
System.out.println(sw800);
// String sw480file = "./app/src/main/res/values-sw480dp-land";
// String sw600file = "./app/src/main/res/values-sw600dp-land";
// String sw720file = "./app/src/main/res/values-sw720dp-land";
// String sw800file = "./app/src/main/res/values-sw800dp-land";
// String sw1080file = "./app/src/main/res/values-sw1080dp-land";
String sw480file = "./chatLib/src/main/res/values-sw480dp-land";
String sw600file = "./chatLib/src/main/res/values-sw600dp-land";
String sw720file = "./chatLib/src/main/res/values-sw720dp-land";
String sw800file = "./chatLib/src/main/res/values-sw800dp-land";
String sw1080file = "./chatLib/src/main/res/values-sw1080dp-land";
writeFile(sw480file, sw480.toString());
writeFile(sw600file, sw600.toString());
writeFile(sw720file, sw720.toString());
writeFile(sw800file, sw800.toString());
writeFile(sw1080file, sw1080.toString());
catch (IOException e)
e.printStackTrace();
finally
if (reader != null)
try
reader.close();
catch (IOException e1)
e1.printStackTrace();
public static void writeFile(String path, String text)
File valuesDir = new File(path);
File valuesFile = new File(valuesDir, "dimens.xml");
if (!valuesDir.exists())
valuesDir.mkdir();
try
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(valuesFile));
bufferedWriter.write(text);
bufferedWriter.newLine();
bufferedWriter.flush();
bufferedWriter.close();
catch (IOException e)
e.printStackTrace();
public static void main(String[] args)
gen();
以上是关于android studio Run java的main方法失败的主要内容,如果未能解决你的问题,请参考以下文章
android studio Run java的main方法失败
android studio Run java的main方法失败
android studio Run java的main方法失败
Android studio提示Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.(代码片
Android studio提示Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.(代码片