我正在尝试在旧的 Mac OS 上运行 Docker。
我收到此错误:
在机器启动时设置仅主机网络时出错:VirtualBox 配置了多个具有相同 IP“192.168.99.1”的仅主机适配器。请删除一个
我无法让它工作并在同一目录中创建一个简单的文件.
我使用的是Mac,文本编辑器是Sublime Text,php版本是5.5.30.
这是我正在执行的代码:
<?php
$file = fopen( 'data/data.txt' , 'w' );
if( $file ) {
echo 'The file is open';
fclose( $file );
}else{
echo 'The file could not be open.';
}
?>
Run Code Online (Sandbox Code Playgroud)
这是浏览器中生成的错误:
警告:fopen(data/data.txt):无法打开流:第17行/Library/WebServer/Documents/php_class/class_examples/open_and_close.php中的权限被拒绝
我在网上搜索了错误的答案,这是我解决问题的解决方案:
打开终端,转到脚本所在的目录,然后输入以下命令
sudo chmod 777 open_and_close.php
Run Code Online (Sandbox Code Playgroud)
现在我做了所有这些,我仍然得到同样的错误.关于我做错的任何建议?
谢谢.
从类似的问题我使用此代码来调试打开文件的失败
echo'<pre>';
error_reporting(E_ALL);
ini_set('display_errors', true);
echo 'phpversion: ', phpversion(), "\n";
echo 'uname: ', php_uname("s r"), "\n"; // name/release of the operating system
//echo 'sapi: ', php_sapi(), "\n";
echo $file, file_exists($file) ? ' exists' : ' does not exist', "\n";
echo $file, is_readable($file) ? ' is readable' : ' is NOT readable', "\n";
echo $file, is_writable($file) ? ' is writable' : ' is NOT readable', "\n";
$fp = @fopen($file, 'x');
if (! $fp) {
echo 'last error: ';
var_dump(error_get_last());
}
echo …
Run Code Online (Sandbox Code Playgroud) 我遇到了一些Java代码:
public class LocationProvider {
public interface LocationCallback {
public void handleNewLocation(Location location);
}
// class constructor
public LocationProvider(Context context, LocationCallback callback){
...
}
}
Run Code Online (Sandbox Code Playgroud)
在Java中,我第一次遇到一个带有"type"参数的构造函数或方法,它是一个接口.是否可以创建接口对象?你可以像常规物品一样使用它们吗?
在C++中,我知道创建抽象类的对象是不可能的.
我想设置一个JButton,使它的图标对齐到它的左边,而文本居中.
我已经找到了如何让他们中的一个离开,另一个,或两者在同一设置,但我找不到我要找的东西.
当然,我总是可以重新定义油漆方法,但我正在寻找一种更精简的方法.
我想将ArrayList中的数据转换为JSON,然后将其发送到我的网络服务器.列表mTeamDataList
是类型ArrayList<TeamData>
.
这TeamData
堂课是:
public class TeamData
{
String mFullName;
String mShortName;
String mLeague;
//constructor, getters and setters are here
}
Run Code Online (Sandbox Code Playgroud)
我有一个addTeamsToDB()
方法负责将数组中的数据写入Web服务器.这是我到目前为止:
public static void addTeamsToDB()
{
if(mTeamDataList.size() == 0)
return;
HttpURLConnection urlConnection = null;
String addTeamURL = "http://api.somewebsite.com/add_team.php";
try
{
Gson gson = new Gson();
URL urlObj = new URL(addTeamURL);
urlConnection = (HttpURLConnection) urlObj.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.connect();
//I believe converting to json goes here
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
}
catch (IOException e) …
Run Code Online (Sandbox Code Playgroud) 我的印象是可以实例化一个接口:
interface TestA {
String toString();
}
public class Test {
public static void main(String[] args) {
System.out.println(new TestA() {
public String toString() {
return "test";
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
这打印"test"
.为什么?该类未实现该接口.
它还创建了一个使用它的实例,new TestA()
但我读取的接口无法实例化.
有人可以解释为什么它打印成功?