我在Xamarin Android中开发应用程序并且有一个非常奇怪的问题:断点和异常已经停止正常工作.当我设置断点时,它永远不会被击中.我在我的项目中设置了断点,但没有一个被击中.这也发生在Visual Studio和Xamarin Studio中.
我还有第二个也更烦人的问题,每次有异常时,它都会在Xamarin Studio中抛出完全无用的"java.lang.reflect.InvocationTargetException"异常,并在Visual Studio中抛出"异常",没有关于异常的更多细节.这只发生在一个特定项目中,其他项目工作正常.我在各种论坛和博客中寻找解决方案,但没有一个有效.我是Xamarin Android开发的新手,希望你能帮助我.
当我尝试删除压缩目录中的文件时,出现这个奇怪的错误:
ZipArchive::close(): Renaming temporary file failed: Permission denied in /MyDirectory/myphpscript.php
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$compressedDirectoryPath = '/Users/Shared/SampleZip.zip';
$zip = new ZipArchive();
if ($zip->open($compressedDirectoryPath) === true) {
if ($zip->deleteName('SampleZip/samplefile.txt') === true) {
echo 'File deleted';
}
}
$zip->close(); // the error is pointing here
?>
Run Code Online (Sandbox Code Playgroud)
执行echo成功并打印File deleted。我运行的是 Mac,压缩目录的权限适用read & write于所有用户。可能是什么问题?
我正在XamarinAndroid中开发一款应用.我有一个启动画面,我在其中序列化一个类并将其传递给MainActivity使用Intent.当我尝试反序列化它时,MainActivity我收到一条错误消息:
"SerializationException unable to find constructor to use for types"
Run Code Online (Sandbox Code Playgroud)
序列化:
void LoadData() {
Currency currency = new Currency(this);
intent = new Intent(this, typeof(MainActivity));
intent.PutExtra("currency", Newtonsoft.Json.JsonConvert.SerializeObject(currency));
StartActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
反序列化:
cur = Newtonsoft.Json.JsonConvert.DeserializeObject<Currency> (Intent.GetStringExtra("currency")); // I get the error here
Run Code Online (Sandbox Code Playgroud)
类构造函数:
public Currency(Context context) {
thiscontext = context;
}
Run Code Online (Sandbox Code Playgroud)
在将参数添加Context context到构造函数后,我开始遇到此问题.是什么导致了这个?我该如何解决?是否可以序列化/反序列化具有参数的类?
我想在屏幕旋转期间保留复杂的java对象,所以我使对象Parcelable并实现了必要的方法:
然后在Fragment的onSaveInstanceState中我保存了Parcelable:
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable("myObject", myObject);
}
Run Code Online (Sandbox Code Playgroud)
并在Fragment的onCreate中得到了我的对象:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyObject myObject = savedInstanceState.getParcelable("myObject");
}
Run Code Online (Sandbox Code Playgroud)
这非常有效.
然后我做了一个测试:
当我运行应用程序时,我得到了完全相同的结果!我得到了一个包含所有适当值的对象.
这为何有效?Parcelable是否自动创建"Parcelable对象"?
我的目标是隐藏操作栏中的一个菜单项,并在单击菜单项后显示另一个菜单项.在我的申请中,我正在使用Toolbar.我已经找了很多其他问题而没找到我需要的东西.任何帮助将不胜感激.我尝试下面的代码,但点击后这会崩溃应用程序.
public boolean onOptionsItemSelected(MenuItem item) {
final SwipeRefreshLayout mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
switch (item.getItemId()) {
case R.id.action_next:
//code
MenuItem secondItem = (MenuItem) findViewById(R.id.action_next);
secondItem.setVisible(false);
return true;
case R.id.action_previous:
//code
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Run Code Online (Sandbox Code Playgroud)