简体   繁体   English

无法修复Android Studio中的包路径错误

[英]Unable to fix package path error in Android Studio

在此处输入图片说明

As you can see in the screenshot above, all the imports of LipeRMI classes are in vain. 如您在上面的屏幕快照中所见,所有LipeRMI类的导入都是徒劳的。 What should be the right path statement to have them imported correctly? 什么是正确导入它们的正确路径声明? I face the same error in MainActivity for: import lipermi.handler.CallHandler; import lipermi.net.Client; 我在MainActivity遇到以下相同错误: import lipermi.handler.CallHandler; import lipermi.net.Client; import lipermi.handler.CallHandler; import lipermi.net.Client;

I know such questions regarding android studio have been asked many times but I just fail to understand how to fix this problem. 我知道有关android studio的此类问题已被问过很多次,但我只是不明白如何解决此问题。 FYI, I dragged the net.sf.lipermi folder into com.example.akash.chatapplication folder. 仅供参考,我将net.sf.lipermi文件夹拖到com.example.akash.chatapplication文件夹中。

Thank you for your time. 感谢您的时间。 :) :)

EDIT - After following Tanis.7x's answer, this is the updated hierarchy as well as the MainActivity code- 编辑 -遵循Tanis.7x的答案后,这是更新的层次结构以及MainActivity代码- 在此处输入图片说明

您应该将src/main/com/example/akash/chatapplication/net移至src/main

By dragging the net.sf.lipermi folder into the com.example.akash.chatapplication folder, you have altered the package for those classes. 通过将net.sf.lipermi文件夹拖到com.example.akash.chatapplication文件夹中,您已经更改了这些类的包。

This won't compile, because the folder path needs to match these classes' package declaration. 这不会编译,因为文件夹路径需要匹配这些类的包声明。 This this case, the package would have to be com.example.akash.chatapplication.net.sf.lipermi , which is clearly not what you want. 在这种情况下,程序包必须是com.example.akash.chatapplication.net.sf.lipermi ,这显然不是您想要的。

If you really need to copy these classes into your project, you should copy them into the src/main folder instead of into your application's package. 如果确实需要将这些类复制到您的项目中,则应将它们复制到src/main文件夹中,而不是复制到应用程序的包中。

The best route is to include these files as a dependency in your build.gradle . 最好的方法是将这些文件作为依赖项包含在build.gradle However, not all libraries offer this option. 但是,并非所有库都提供此选项。 If that library provides a JAR file, you should instead include that JAR in your project's libs folder. 如果该库提供了一个JAR文件,则应该将该JAR包含在项目的libs文件夹中。 Including the raw source in your project should always be a last resort. 在项目中包括原始资源应该永远是最后的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM