我试图理解Java Collection框架背后的概念,并提出了这个问题 - 为什么在TreeMap中不允许使用null键?
如果我们尝试在TreeMap中添加null键,它会给出NullPointerException.
试图google TreeMap的内部工作,发现像TreeMap这样的东西使用的RedBlack树算法现在很难理解,我正在研究它.
TreeMap是一个基于红黑树的NavigableMap实现.换句话说,它使用红黑树算法对TreeMap对象键进行排序.
请清除我,虽然Map接口的其他两个实现允许null作为键,那么为什么TreeMap不允许将null添加为键?
我想提前解释一下.
我在使用FileProvider共享图像时遇到了Exception.以下是我以前的代码.
{
ArrayList<Uri> files = new ArrayList<Uri>();
files.add(getImageUriFromCache(context,bitmap,fileName));
}
private void startSharingIntent(ArrayList<Uri> files,String caption){
Intent i=new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
i.setType("image/png");
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.putExtra(Intent.EXTRA_SUBJECT, "my app share");
i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
i.putExtra(Intent.EXTRA_TEXT,caption);
i.putExtra(Intent.EXTRA_TITLE,caption);
context.startActivity(Intent.createChooser(i, "Tital"));
}
public Uri getImageUriFromCache(Context inContext, Bitmap inImage , String fileId) throws IOException{
File cachePath = new File(inContext.getFilesDir() , "images/");
cachePath.mkdirs(); // don't forget to make the directory
File newFile = new File(cachePath, "im"+fileId+"_post.png");
newFile.setReadable(true, false);
FileOutputStream stream = new FileOutputStream(newFile); // overwrites this image every time
inImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
stream.close();
Uri …Run Code Online (Sandbox Code Playgroud) android android-intent android-contentprovider android-sharing android-fileprovider
释放相机对象“ java.lang.RuntimeException:释放后调用的方法”时出现异常
以下是我的代码和异常堆栈跟踪。
if (camera != null) {
camera.stopPreview();
camera.release();
camera = null;
}
Run Code Online (Sandbox Code Playgroud)
异常堆栈跟踪-
java.lang.RuntimeException: Method called after release()
Thread[main,5,main] android.hardware.Camera._stopPreview(Native Method)
android.hardware.Camera.stopPreview(Camera.java:626)
com.s5.selfiemonkey1.activity.Preview.surfaceDestroyed(Preview.java:152)
android.view.SurfaceView.updateWindow(SurfaceView.java:601)
android.view.SurfaceView.access$000(SurfaceView.java:88)
android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:680)
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123)
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4872)
android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
android.view.Choreographer.doCallbacks(Choreographer.java:579)
android.view.Choreographer.doFrame(Choreographer.java:548)
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
android.os.Handler.handleCallback(Handler.java:800)
android.os.Handler.dispatchMessage(Handler.java:100)
android.os.Looper.loop(Looper.java:194)
android.app.ActivityThread.main(ActivityThread.java:5371)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:525)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
Run Code Online (Sandbox Code Playgroud)
看起来好像在释放的对象上调用了stopPreview()。
我正在阅读有关Java 8中提供的lambda表达式的两个博客和答案。
我无法弄清楚,单位lambda表达式是否对运行时有好处?
我从不同的来源复制了以下文本,这使我感到非常困惑。
一个答案是说-
“ lambda不会创建新的作用域,它们与封闭的块/环境共享相同的作用域”
在一个博客中-
“使用lambda表达式没有运行时的好处,所以我会谨慎使用它,因为我不介意写一些额外的代码行。”
从另一个博客-
“通过在方法中传递行为,又一个有益的lambda表达式顺序和并行执行支持”
所以对我来说,还有很多困惑。请帮助我清除此问题,以便在深入研究这些内容之前避免记住错误的方法。
我已经运行了以下代码,我可以说以下代码中的lambda表达式只是对匿名内部类及其在主线程上运行的替代。
List<Integer> list = new ArrayList<>();
list.add(12);
list.forEach(V -> {
System.out.println(V);
});
Run Code Online (Sandbox Code Playgroud)
我们是在减少时间复杂度还是空间复杂度?
我的应用程序在Android服务中使用LocationListener来更新频繁的位置.应用程序将一些位置过滤器相关数据存储在共享首选项 要求是尽可能频繁地更新位置.我在侦听器的onLocationChanged中从共享首选项中检索数据.这是我的代码
public class MyLocationListener implements LocationListener {
public void onLocationChanged(final Location loc) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
int filterOne = sharedPreferences.getInt("filter_data",100);
------
------
//code to process location with filter
------
------
}
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,sharedPreference以重复的方式使用.
我已经尝试在onLocationChanged之外放置过滤器变量,但是当重新启动服务时,值会丢失并设置为零.
我只是想知道这是不是很好的做法?我应该使用其他选项吗?
我收到以下错误。
无法删除对象“tablename”,因为它被 FOREIGN KEY 约束引用。
这意味着有我想要截断的表的引用。然后我使用以下查询删除所有表的所有约束。
use mydb
EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
truncate table mytable.
Run Code Online (Sandbox Code Playgroud)
但它不起作用,请帮助。
Sql 服务器具有空间数据类型几何和地理。mysql中有几何类型可用,但我在mysql中没有找到mysql geography。
我要检查位置(纬度,经度)与多边形地理围栏的交集。我已经用 java 完成了这个,但是那个解决方案太慢了。因此,在 sql server 数据库中,我使用 geography 数据类型来存储多边形地理围栏点数据。这给了我更快的结果。
在 mysql 中,我找不到 geograqphy 数据类型。纬度和经度代表角度。
那么如果我使用几何数据类型在 mysql 中存储多边形 geofece 点(纬度,经度)呢?
它会给我与地理相同的结果吗?
android ×3
java ×3
collections ×1
database ×1
geometry ×1
java-8 ×1
lambda ×1
mysql ×1
spatial ×1
sql-server ×1
sqldatatypes ×1