我必须保存Ury的ArrayList,所以我使用代码
public static void saveUriList(ArrayList<Uri> myUriList) {
if (storageAvailable()) {
try {
FileOutputStream uriListSaved = new FileOutputStream(
baseDir + File.separator + filename);
ObjectOutputStream uriList = new ObjectOutputStream(
uriListSaved);
uriList.writeObject(myUriList);
uriList.close();
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
此代码结构适用于实现可序列化的自定义对象,但Uri对象返回此异常
10-18 21:06:40.169: W/System.err(11957): java.io.WriteAbortedException: Read an exception; java.io.NotSerializableException: android.net.Uri$StringUri
10-18 21:06:40.169: W/System.err(11957): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:933)
10-18 21:06:40.169: W/System.err(11957): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
10-18 21:06:40.169: W/System.err(11957): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
10-18 21:06:40.169: W/System.err(11957): at java.util.ArrayList.readObject(ArrayList.java:665)
10-18 21:06:40.169: W/System.err(11957): at java.lang.reflect.Method.invokeNative(Native Method)
10-18 21:06:40.169: W/System.err(11957): at java.lang.reflect.Method.invoke(Method.java:507) …Run Code Online (Sandbox Code Playgroud) 我可以在一个程序中测试类类型,在该程序中我正在使用instanceof或获取标识类 appartenency 的字段。所以选择是在
if(myObjec instanceof Something){
}
Run Code Online (Sandbox Code Playgroud)
和
if(myObjec.geClassType().equals("Something")){
}
Run Code Online (Sandbox Code Playgroud)
在效率方面什么是最好的?
geClassType()是存在于我正在工作的程序对象中的方法(不是标准的 java 方法),并且是一种返回带有类名称的字符串的方法。名称在创建对象时作为字段传递
编辑
我在我的代码的第二个示例中获得的字段并没有准确地标识类而是一个类别,并且还用于不同的例程,但我也可以将它用于此目的,因为我为每个类别使用了一个特定的对象。所以我已经报告了这一点,getClassType以使我的问题更清楚。
我必须在C中移植一些Java方法,有一个Java背景但我在C编程中是一个总的菜鸟
在java中
float[][] traspose(float Xy[][]) {
float result[][]=new float[5000][3000];
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
result[i][j] = Xy[j][i];
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
我的C移植尝试
float traspose(int m, int n, float Xy[m][n]) {
int i,j;
float result[5000][3000];
for(i = 0; i < m; i++) {
for(j = 0; j < n; j++) {
result[i][j] = Xy[j][i];
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,并获得不兼容的类型错误.
我的2个问题
1)我应该如何修复我的代码?谷歌搜索我已经看到一些关于在C中返回矩阵的问题,但不是很清楚,并且在大多数情况下建议使用一种不暗示使用返回的方法.
2)我已经看到,C中的这种操作通常是在没有返回类型方法的情况下编写的,例如,对常量进行操作的void方法或者直接在main中编写代码.为什么?
编辑
按照我的建议,我试图编码
float **transpose(int …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Joda库,因为使用Java本机方法计算周期非常麻烦,而且我的所有尝试都给出了不准确的结果
我看过这个样本
int n = Days.daysBetween(start.toLocalDate(), end.toLocalDate()).getDays();
Run Code Online (Sandbox Code Playgroud)
由于我所有的班级都管理GregorianCalendar,因此我需要一种计算支持GregorianCalendar的天数的方法,例如
public int countDays(GregorianCalendar start, GregorianCalendar end){
//convert to joda start and end
...
return Days.daysBetween(start.toLocalDate(), end.toLocalDate()).getDays();
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如何将GregorianCalendar对象转换和重新转换为Joda管理的对象而又没有副作用?
当我使用 gradle 构建项目时,我看不到任何关于已弃用方法的警告,只显示错误。
我如何设置 build.gradle 以显示所有弃用警告(不阻止构建完成)?
我的makefile:
SHELL := /bin/bash
.PHONY: all
all:
pip install runcython
makecython++ stitch_wrapper.pyx "" "stitch_rects.cpp ./hungarian/hungarian.cpp"
hungarian: hungarian/hungarian.so
hungarian/hungarian.so:
cd hungarian && \
TF_INC=$$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())') && \
if [ `uname` == Darwin ];\
then g++ -std=c++11 -shared hungarian.cc -o hungarian.so -fPIC -I $$TF_INC -undefined dynamic_lookup;\
else g++ -std=c++11 -shared hungarian.cc -o hungarian.so -fPIC -I $$TF_INC; fi
Run Code Online (Sandbox Code Playgroud)
我已经安装了
-cython
-runcython
-python-dev
-python3-dev
-cffi
Run Code Online (Sandbox Code Playgroud)
不幸的是,我继续得到错误:
pkg-config: command not found
.cpp:4:20: fatal error: Python.h: No such file or directory …Run Code Online (Sandbox Code Playgroud) 我有
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", dateStart.getTime());
intent.putExtra("allDay", false);
intent.putExtra("rrule", "FREQ=DAILY");
intent.putExtra("endTime", dateEnd.getTime());
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
编译一个事件,我想一次运行该事件.
设定频率的线是
intent.putExtra("rrule", "FREQ=DAILY");
Run Code Online (Sandbox Code Playgroud)
此外,如果我删除此行,默认情况下,如果我不手动更改它,Android日历将设置为DAILY.
我已经找到了所有支持的属性的列表,我找到了MONTLY,YEARLY等但我找不到"一次"的正确支持语法
你可以帮帮我吗?
我使用intent过滤器来获取用户使用文件选择器选择的文件的路径,遗憾的是我有问题获取绝对路径,
onActivityResult的路径始终使用各种额外数据启动,这些数据会导致我的应用程序出错
例如
/content/:/myabsolutepath
Run Code Online (Sandbox Code Playgroud)
要么
file:///myabsolutepath
Run Code Online (Sandbox Code Playgroud)
额外的属性取决于文件类型,手机上的文件管理器等.
我只需要获得表单中的绝对路径
/myabsolutepath
Run Code Online (Sandbox Code Playgroud)
这里有我的代码
private void openFile() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("file/*");
startActivityForResult(i, FILE_REQ_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent i) {
//String with the path;
path = i.getDataString();
super.onActivityResult(requestCode, resultCode, i);
}
Run Code Online (Sandbox Code Playgroud) 我的高度始终为0.我想在Android中使用GPS获取海拔高度.
我的代码是:
public void onLocationChanged(Location location) {
double lat = (double) (location.getLatitude());
double lng = (double) (location.getLongitude());
double alt = (double) (location.getAltitude());
latitudine = (int) (lat * 1e6);
longitudine = (int) (lng * 1e6);
altitudine = (int) (alt * 1e6);
}
Run Code Online (Sandbox Code Playgroud) 对于屏幕较小的特定设备,默认情况下警报消息太大,我想将其设置为自定义dp
我的警报是这样的
OnClickListener addNewItemListener = new OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(
MyActivity.this);
LinearLayout myLayout= new LinearLayout(MyActivity.this);
myLayout.setOrientation(LinearLayout.VERTICAL);
alert.setTitle(R.string.add_title);
alert.setMessage(R.string.add_message);
final TextView t1 = new TextView(MyActivity.this);
t1.setText("Name");
final EditText input1 = new EditText(MyActivity.this);
myLayout.addView(t1);
myLayout.addView(input1);
alert.setView(myLayout);
alert.setPositiveButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
alert.setNegativeButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
try {
....
} catch (RuntimeException e) {
Alerts.DatiErrati(MyActivity.this);
}
}
});
alert.show();
} …Run Code Online (Sandbox Code Playgroud) android ×6
java ×3
altitude ×1
c ×1
cython ×1
filechooser ×1
gradle ×1
jodatime ×1
matrix ×1
parcelable ×1
porting ×1
python ×1
python-c-api ×1
ubuntu ×1