小编Myk*_*nko的帖子

Android - Bitmap.CreateBitmap - 空指针异常

有时当我试图创建模糊的位图时,我得到"空指针异常".

发生在这个代码块中(我最近开始捕获异常,所以至少它不会崩溃应用程序):

try
{
    using (Bitmap.Config config = Bitmap.Config.Rgb565) {
        return Bitmap.CreateBitmap (blurredBitmap, width, height, config);
    }
}
catch (Java.Lang.Exception exception)
{
    Util.Log(exception.ToString());
}
Run Code Online (Sandbox Code Playgroud)

有关我传递给"CreateBitmap"方法的参数的更多详细信息,请参阅这些图片:

在此输入图像描述

这是扩展的参数:

在此输入图像描述

完全例外:

exception {Java.Lang.NullPointerException:抛出了类型'Java.Lang.NullPointerException'的异常.在/Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000b]在Android.Runtime.JNIEnv.CallStaticObjectMethod(IntPtr jclass,IntPtr jmethod,Android.Runtime.JValue*parms)[0x00064] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/ src/Runtime/JNIEnv.g.cs:1301位于/ Users/builder/data中的Android.Graphics.Bitmap.CreateBitmap(System.Int32 []颜色,Int32宽度,Int32高度,Android.Graphics.Config配置)[0x00088] /lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-22/src/generated/Android.Graphics.Bitmap.cs:

不确定这可能是Xamarin中的错误还是传递的参数错误.

c# android bitmap xamarin.android xamarin

5
推荐指数
1
解决办法
727
查看次数

计算java中存档中的文件数

我正在尝试计算存档中的文件数.我的代码计算所有实体(包括文件夹)的问题(例如,如果我有复杂的目录但只有一个文件,我无法验证我的存档).我使用方法大小().

import java.nio.file.Path;
import javax.enterprise.context.Dependent;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import ru.cntp.eupp.roster.Notification;
import java.util.ArrayList;
import java.util.zip.ZipFile;
import java.util.List;
import java.util.Enumeration;

/*
 * @author dfaevskii
 */
@Dependent
public class ZipValidator {

     public void validate(Path pathToFile) throws IOException {

         ZipFile zipFile = new ZipFile(pathToFile.toFile());

         if (zipFile.size() != 1 && zipFile.size() != 2) {
             throw new InvalidZipException("The number of files in archive is more than  2");
         } 
     }
 }
Run Code Online (Sandbox Code Playgroud)

java file count

5
推荐指数
2
解决办法
3309
查看次数

量角器:我是否过度使用promise.then()

我正在使用Protractor进行端到端测试.我正在处理的应用程序的一部分首先使用ng-switch语句在注册过程中显示/隐藏问题,一次一个.问题之间有动画给了我最难的时间.例如,尝试加载页面 - >转到下一个问题 - >断言元素存在很难,等等.该脚本将加载页面,单击下一个按钮,然后在屏幕上显示下一张幻灯片之前进行断言.

更糟糕的是,在问题之间大约半秒钟,旧问题和新问题都存在于DOM上.我能想到的最好的非睡眠等待机制是做一个browser.wait(),它首先等待DOM上有两个问题,然后链接另一个browser.wait()等待那里只有一个再次询问DOM,然后从那里开始.(整个操作包含在代码中的registerPage.waitForTransition()中)

browser.wait()s并不总是阻塞足够长的时间,所以我最终编写了如下所示的代码:

it('moves to previous question after clicking previous link', function() {
    var title;

    // Get the current slide title, then click previous, wait for transition,
    // then check the title again to make sure it changed

    registerPage.slideTitle.getText()
        .then(function(text) {
            title = text;
        })
        .then(registerPage.prevLink.click())
        .then(registerPage.waitForTransition())
        .then(function() {
            expect(registerPage.slideTitle.getText()).not.toBe(title);
        });
});
Run Code Online (Sandbox Code Playgroud)

为了确保在执行下一个命令之前正确完成每个等待.现在这完美无缺.之前发生的事情是,测试将在95%的时间内成功,但在转换实际上已完成100%之前,偶尔会触发断言或下一次点击操作等.这种情况不再发生了,但我觉得这几乎是在承诺上过度使用.then().但与此同时,迫使一切顺序发生是有道理的,因为这与网站的交互实际上是如何运作的.加载页面,然后等待下一个按钮滑入,然后进行选择,然后单击下一个按钮,然后等待下一张幻灯片等.

我是在一个完全糟糕的练习风格中这样做的,还是在一个动画效率很高的应用上使用Protractor时这是否可以接受使用承诺?

javascript testing promise protractor

5
推荐指数
1
解决办法
456
查看次数

自定义 CacheInterceptor 被默认 Spring 的 CacheInterceptor 覆盖

我已经实现了一个CacheInterceptor允许通过通配符逐出缓存的自定义:

public class CustomCacheInterceptor extends CacheInterceptor {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomCacheInterceptor.class);

    @Override
    protected void doEvict(Cache cache, Object key) {
        try {
            // evict cache
        } catch (RuntimeException ex) {
            getErrorHandler().handleCacheEvictError(ex, cache, key);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我正在努力让它工作:

@Configuration
public class CustomProxyCachingConfiguration extends ProxyCachingConfiguration {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomProxyCachingConfiguration.class);

    @Bean
    public CacheInterceptor cacheInterceptor() {
        LOGGER.info("Creating custom cache interceptor");

        CacheInterceptor interceptor = new CustomCacheInterceptor();
        interceptor.setCacheOperationSources(cacheOperationSource());
        if (this.cacheResolver != null) {
            interceptor.setCacheResolver(this.cacheResolver);
        } else if (this.cacheManager …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot spring-cache

5
推荐指数
1
解决办法
748
查看次数

ASM Java替换方法调用指令

背景

我想在一些耗时的方法上做一些工具,比如 org/json/JSONObject.toString()使用ASM Java框架.

原始调用方法

public class JSONUsage {
    public void callToString() {
        JSONObject jsonObject = new JSONObject();
        String a = jsonObject.toString();//original call
        System.out.println(a);
    }
}
Run Code Online (Sandbox Code Playgroud)

仪表后

public class JSONUsage {
    public void callToString() {
        JSONObject jsonObject = new JSONObject();
        // **important!**
        //pass the instance as an param, replace the call to a static method
        String a = JSONReplacement.jsonToString(jsonObject);
        System.out.println(a);
    }
}

public class JSONReplacement {

    public static String jsonToString(JSONObject jsonObject) {
        //do the time caculation
        long before …
Run Code Online (Sandbox Code Playgroud)

java bytecode-manipulation java-bytecode-asm

3
推荐指数
1
解决办法
2511
查看次数

似乎无法在CloudKit中删除订阅?`-deleteSubscriptionWithID`总是返回true

我希望有一位经验丰富的CloudKit大师,但根据我的谷歌搜索查询,我不确定你是否存在.我认为这可能是Apple的一个错误,但我无法确定:

我可以保存订阅我的CKDatabase罚款,没有任何问题.

[publicDatabase saveSubscription:subscription completionHandler:^(CKSubscription *subscription, NSError *error) {
    if (error)
    {
        //No big deal, don't do anything.
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setObject:[subscription subscriptionID] forKey:@"SUBSCRIPTION"];
    }
}];
Run Code Online (Sandbox Code Playgroud)

每当我更改记录中的字段时,我都会收到推送通知,一切都很愉快.

我的问题是删除此订阅.

我试过调用 正如你在上面的代码片段中看到的那样,我保存了订阅ID(还通过调用确认它是正确的订阅ID)-deleteSubscriptionWithID:completionHandler:
-fetchAllSubscriptionsWithCompletionHandler:

我在那条消息中传递了subscriptionID,如下所示:

[publicDatabase deleteSubscriptionWithID:[[NSUserDefaults standardUserDefaults] objectForKey:@"SUBSCRIPTION"] completionHandler:^(NSString * _Nullable subscriptionID, NSError * _Nullable error) {
    if( error ) {
        NSLog(@"ERROR: %@", [error description] );
    }
    else
    {
        NSLog(@"SUCCESS: %@", subscriptionID);
    }
}];
Run Code Online (Sandbox Code Playgroud)

但它不会删除我的订阅: 在此输入图像描述

无论我作为subscriptionID传递什么,都没有错误,我在"删除"时看到"SUCCESS".

在此输入图像描述 在此输入图像描述

...是的.显然这是行不通的.

如果我通过Cloudkit Dashboard手动删除订阅,我的-fetch调用会正确地注意到并返回一个空数组: 在此输入图像描述

所以在这一点上,我确定我要么在代码中错误地删除订阅,要么它已经坏了,并且(不太可能)没有人在SO或任何其他论坛上找到我能找到的?

我也试过用 CKModifySubscriptionsOperation

   CKModifySubscriptionsOperation *deleteSub = …
Run Code Online (Sandbox Code Playgroud)

apple-push-notifications ios cloudkit

3
推荐指数
1
解决办法
975
查看次数

mvc 5 验证过去的日期

我在这里看到了问题,但无法解决问题。

我希望当用户在表单中插入日期时,只有过去的日期才是相关的。

例子:

用户无法插入 2016 年 2 月 3 日之后的日期。

我的型号:

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
[Display(Name = "Date")]
[Required(ErrorMessage = "Date is mandatory")]
public DateTime created_date { get; set; }
Run Code Online (Sandbox Code Playgroud)

我的看法:

<div class="form-group" >
    @Html.LabelFor(model => model.created_date, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10" >
        @Html.EditorFor(model => model.created_date, new { htmlAttributes = new { @class = "form-control" } })
        @Html.ValidationMessageFor(model => model.created_date, "", new { @class = "text-danger" })
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

谢谢。

html c# asp.net asp.net-mvc asp.net-mvc-5

3
推荐指数
1
解决办法
8014
查看次数

摇篮。如何从另一个模块复制资源

我有 2 个模块:AB. 模块B包含/src/main/resources/file.xml,但模块A在运行时也依赖于这个 file.xml。是否可以在构建期间将资源从模块复制B到模块A?我已经maven-resources-plugin在 Maven 中用于这个目标,但我找不到与 Gradle 类似的东西。

java gradle build.gradle

3
推荐指数
1
解决办法
3102
查看次数

如何将布尔结果发送到ajax调用

我想在 ajax 调用中发送布尔结果。

Ajax 调用

function myMethod() {
		 
    $.ajax({
        type : "GET",
	url : myurl
	dataType : "json",
	contentType: "application/json",
	crossDomain: true,
	success : function(data) {
            alert("success :"+data);
			
	},
	error : function(data) {
   	    alert("Fialed to get the data");
	}
    });
	
}
Run Code Online (Sandbox Code Playgroud)

我想从中发送布尔结果的控制器方法。

@RequestMapping(value = "/myMethod", method = RequestMethod.GET)
@ResponseBody
public boolean myMethod(empId) {
    flag = false;
		
    try {
    	if (empId != null)
            newName = Employee.getName(empId);
        else
            newName = Employee.getName();
    } catch (Exception e1) {
        flag = true;
        System.out.println("flag :" + …
Run Code Online (Sandbox Code Playgroud)

ajax

2
推荐指数
1
解决办法
4802
查看次数

按位运算符和循环

我试图理解按位和移位运算符.我写了一个简单的代码来向我展示一个短类型的位.

class Shift {
    public static void main (String args[]) {
        short b = 16384;

        for (int t = 32768; t > 0; t = t / 2) {
            if ((b&t) != 0) System.out.print("1 ");
            else System.out.print ("0 ");
        }
        System.out.println();
        b = (short)(b + 2);
        for (long t = 2147483648L; t > 0; t = t / 2) {
            if ((b&t) != 0) System.out.print ("1 ");
            else System.out.print ("0 ");
        }
        System.out.println();
    }
}
Run Code Online (Sandbox Code Playgroud)

输出是:

C:\>java Shift
0 1 …
Run Code Online (Sandbox Code Playgroud)

java bitwise-operators

0
推荐指数
1
解决办法
837
查看次数