使用Java反射时,我对getFields
方法和getDeclaredFields
方法之间的区别感到有些困惑.
我读过,它getDeclaredFields
允许您访问该类的所有字段,并且 getFields
只返回公共字段.如果是这种情况,你为什么不经常使用getDeclaredFields
?
有人可以详细说明这一点,并解释两种方法之间的区别,以及何时/为什么要使用一种方法?
我正在使用Fragments
其中一个创建一个应用程序,我创建了一个非默认构造函数并得到了这个警告:
Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么这不是一个好主意?
你能否建议我如何做到这一点:
public static class MenuFragment extends ListFragment {
public ListView listView1;
Categories category;
//this is my "non-default" constructor
public MenuFragment(Categories category){
this.category = category;
}....
Run Code Online (Sandbox Code Playgroud)
不使用非默认构造函数?
我正在使用日期和时间来标记我正在创建的新文件,但是当我查看文件时,冒号是正斜杠.我正在使用10.7+在Mac上进行开发
这是我正在使用的代码:
File.open("#{time.hour} : 00, #{time.month}-#{time.day}-#{time.year}", "a") do |mFile|
mFile.syswrite("#{pKey} - #{tKey}: \n")
mFile.syswrite("Items closed: #{itemsClosed} | Total items: #{totalItems} | Percent closed: % #{pClosed} \n")
mFile.syswrite("\n")
mFile.close
end
Run Code Online (Sandbox Code Playgroud)
这是输出(假设时间是下午1点):
13 / 00, 11-8-2012
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,我该如何解决?我希望输出为:
13:00, 11-8-2012
Run Code Online (Sandbox Code Playgroud) 我正在使用Net :: HTTP向Ruby发出HTTP请求,我无法弄清楚如何获取所有响应头.
我试过了response.header
,但response.headers
没有任何工作.
我对PowerShell echo
和Write-Host
PowerShell 之间的区别感到困惑.我有两个文件,POC.ps1
&validatePath.ps1
.这些文件在我的本地计算机上,我正在使用远程计算机上运行它们Invoke-Command
.我使用的是PowerShell v3.0.
要执行这两个脚本,我使用命令:
.\POC.ps1 -filename C:\Users -user Blaine
Run Code Online (Sandbox Code Playgroud)
这是两个文件:
POC.ps1:
param($filename, $user)
echo $filename
echo "This"
echo $user
$responseObject = Invoke-Command testcomputer -FilePath .\validatePath.ps1 -ArgumentList($filename, $user) -AsJob
while($responseObject.State -ne "Completed")
{
}
$result = Receive-Job -Id $responseObject.Id -Keep
echo $result
Run Code Online (Sandbox Code Playgroud)
这是事情变得奇怪的地方......
validatePath.ps1:
Param([string] $filename,
[string] $user)
function ValidatePath( $filename, $user, $fileType = "container" )
{
Write-Host "This is the file name: $filename"
Write-Host "This is user: $user" <--- Notice …
Run Code Online (Sandbox Code Playgroud) 我有以下脚本:
if( $timeout -ne $null )
{
& $var$timeout 2>&1 > $logDir\$logName
}
else
{
& $var2>&1 > $logDir\$logName
}
Run Code Online (Sandbox Code Playgroud)
我很好奇是什么2>&1
; 或者,它代表什么.我不知道它叫什么,否则,我会查一查.
我有以下警报方法.
static func notifyUser(_ title: String, message: String) -> Void
{
let alert = UIAlertController(title: title,
message: message,
preferredStyle: UIAlertControllerStyle.alert)
let cancelAction = UIAlertAction(title: "OK",
style: .cancel, handler: nil)
alert.addAction(cancelAction)
self.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,说是有一个额外的参数animated
的presentViewController
方法,但是我把它拿出来的时候,它仍然没有清除错误,然后有人告诉我completion
是一个额外的参数.
我正在尝试在运行Powershell脚本时获取错误的行号.这是我现在正在使用的内容:
$e = $_.Exception
$line = $_.Exception.InvocationInfo.ScriptLineNumber
$msg = $e.Message
Write-Host -ForegroundColor Red "caught exception: $e at $line"
Run Code Online (Sandbox Code Playgroud)
有时候这种方法有效,有时则无效.我想知道我做错了什么,或者我能做些什么来使这项工作更加一致.
我试图在两个活动之间传递一个对象的arraylist,但我的应用程序在第二个活动时崩溃.有人可以帮我解决这个问题......
这是我第一次活动的代码:
Intent i = new Intent();
Bundle b = new Bundle();
b.putParcelableArrayList("songs",(ArrayList<? extends Parcelable>) albumsArray.get(position).getSongs());
Log.v("--", "OK");
i.putExtras(b);
i.setClass(LatestAlbums.this, AlbumDetails.class);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
和第二个活动的代码:
songs=new ArrayList<Songs>();
Bundle b = this.getIntent().getExtras();
if(b!=null)
songs = b.getParcelable("songs");
Log.v("--", songs.size()+"");
Run Code Online (Sandbox Code Playgroud)
我的logcat输出:
04-03 16:37:03.513: E/AndroidRuntime(6576): FATAL EXCEPTION: main
04-03 16:37:03.513: E/AndroidRuntime(6576): java.lang.RuntimeException: Parcel: unable to marshal value com.musicapp.objects.Songs@419489e8
04-03 16:37:03.513: E/AndroidRuntime(6576): at android.os.Parcel.writeValue(Parcel.java:1137)
04-03 16:37:03.513: E/AndroidRuntime(6576): at android.os.Parcel.writeList(Parcel.java:524)
04-03 16:37:03.513: E/AndroidRuntime(6576): at android.os.Parcel.writeValue(Parcel.java:1097)
04-03 16:37:03.513: E/AndroidRuntime(6576): at android.os.Parcel.writeMapInternal(Parcel.java:493)
04-03 16:37:03.513: E/AndroidRuntime(6576): at android.os.Bundle.writeToParcel(Bundle.java:1612)
04-03 16:37:03.513: E/AndroidRuntime(6576): …
Run Code Online (Sandbox Code Playgroud) android arraylist parcelable android-intent android-activity
问题很简单.在应用程序中,我们希望跟踪显示的当前URL.为此,我们使用shouldOverrideUrlLoading
回调来WebViewClient
保存url到每个更新的类字段.这是相关代码:
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
mCurrentUrl = url;
// If we don't return false then any redirect (like redirecting to the mobile
// version of the page) or any link click will open the web browser (like an
// implicit intent).
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
...
}
});
mWebView.loadUrl(mInitialUrl);
Run Code Online (Sandbox Code Playgroud)
但是,至少有一种情况,即回调永远不会被触发,并且mCurrentUrl字段不会更新.
网址:https://m.pandora.net/es-es/products/bracelets/556000
上次更新的URL(在单击产品时永远不会调用shouldOverrideUrlLoading):https://m.pandora.net/es-es/products/bracelets
我尝试过像onPageStarted()这样的回调,但是url也被过滤了,因为它的受保护代码似乎没有可访问的上游. …
android ×3
powershell ×3
ruby ×2
windows ×2
.net ×1
arraylist ×1
httprequest ×1
ios ×1
java ×1
macos ×1
parcelable ×1
reflection ×1
swift ×1
swift3 ×1
webview ×1