DotEnv 类路径问题 android

问题描述 投票:0回答:1

我已导入 DotEnv 插件和库,并创建了 Env.java 文件,但创建时出现一些问题,并且 Env.java 文件为空。下面我发布我的代码片段。

Added at the implementation part Added at the plugin The initialization part

这是我的.env 文件

.env

这是错误片段

Process: com.example.awsiotdemo, PID: 14065
                                                                                                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.awsiotdemo/com.example.awsiotdemo.activity.RegisterActivity}: io.github.cdimascio.dotenv.DotenvException: Could not find /.env on the classpath
                                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
                                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
                                                                                                    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
                                                                                                    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
                                                                                                    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
                                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
                                                                                                    at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    at android.os.Looper.loop(Looper.java:294)
                                                                                                    at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
                                                                                                Caused by: io.github.cdimascio.dotenv.DotenvException: Could not find /.env on the classpath
                                                                                                    at io.github.cdimascio.dotenv.internal.ClasspathHelper.loadFileFromClasspath(ClasspathHelper.java:25)
                                                                                                    at io.github.cdimascio.dotenv.internal.DotenvReader.read(DotenvReader.java:57)
                                                                                                    at io.github.cdimascio.dotenv.internal.DotenvParser.lines(DotenvParser.java:94)
                                                                                                    at io.github.cdimascio.dotenv.internal.DotenvParser.parse(DotenvParser.java:62)
                                                                                                    at io.github.cdimascio.dotenv.DotenvBuilder.load(DotenvBuilder.java:76)
                                                                                                    at com.example.awsiotdemo.activity.RegisterActivity.onCreate(RegisterActivity.java:28)
                                                                                                    at android.app.Activity.performCreate(Activity.java:8595)
                                                                                                    at android.app.Activity.performCreate(Activity.java:8573)
                                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
                                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
                                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922) 
                                                                                                    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
                                                                                                    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139) 
                                                                                                    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96) 
                                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) 
                                                                                                    at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                    at android.os.Looper.loopOnce(Looper.java:205) 
                                                                                                    at android.os.Looper.loop(Looper.java:294) 
                                                                                                    at android.app.ActivityThread.main(ActivityThread.java:8177) 
                                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
                                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 
                                                                                                    Suppressed: io.github.cdimascio.dotenv.DotenvException: Could not find ./.env on the file system (working directory: /)
                                                                                                        at io.github.cdimascio.dotenv.internal.DotenvReader.read(DotenvReader.java:62)
                                                                                                        ... 20 more
android android-studio classpath dotenv
1个回答
0
投票

如果对某人有帮助,请发布答案

得到了答案,不知道为什么,但我猜这是事实。 在我的例子中,变量名的大写返回是问题所在。就像这个文件只接受小写、驼峰式大小写和小写带下划线的驼峰式大小写。这确实是一个简单的解决方案,但花了我一天的时间。

.env

© www.soinside.com 2019 - 2024. All rights reserved.