首页 文章 精选 留言 我的

精选列表

搜索[Bug修复],共10000篇文章
优秀的个人博客,低调大师

Kotlin项目类找不到bug:java.lang.ClassNotFoundException: kotlin.reflect.Kotli...

一、今天在创建了一个Kotlin+Spring的项目,结果启动报错 org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at net.AppKt.main(App.kt:26) [classes/:na] Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:409) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] ... 8 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpPutFormContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1250) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:225) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:181) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:176) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:158) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:80) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:250) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:237) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5204) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_161] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 24 common frames omitted Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at com.fasterxml.jackson.module.kotlin.KotlinModule.setupModule(KotlinModule.kt:44) ~[jackson-module-kotlin-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:751) ~[jackson-databind-2.9.5.jar:2.9.5] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:766) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:624) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:608) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:59) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:74) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.filter.HttpPutFormContentFilter.<init>(HttpPutFormContentFilter.java:64) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter.<init>(OrderedHttpPutFormContentFilter.java:29) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.httpPutFormContentFilter(WebMvcAutoConfiguration.java:163) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.CGLIB$httpPutFormContentFilter$1(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238$$FastClassBySpringCGLIB$$9f061c7c.invoke(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.httpPutFormContentFilter(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 25 common frames omitted Caused by: java.lang.ClassNotFoundException: kotlin.reflect.KotlinReflectionInternalError at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161] ... 45 common frames omitted 二、一看到这么多错误日志,很多同学直接懵了,其实有用的就在最后两个Caused By Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at com.fasterxml.jackson.module.kotlin.KotlinModule.setupModule(KotlinModule.kt:44) ~[jackson-module-kotlin-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:751) ~[jackson-databind-2.9.5.jar:2.9.5] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:766) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:624) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:608) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:59) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:74) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.filter.HttpPutFormContentFilter.<init>(HttpPutFormContentFilter.java:64) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter.<init>(OrderedHttpPutFormContentFilter.java:29) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.httpPutFormContentFilter(WebMvcAutoConfiguration.java:163) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.CGLIB$httpPutFormContentFilter$1(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238$$FastClassBySpringCGLIB$$9f061c7c.invoke(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.httpPutFormContentFilter(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 25 common frames omitted Caused by: java.lang.ClassNotFoundException: kotlin.reflect.KotlinReflectionInternalError at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161] ... 45 common frames omitted 三、下面我们来google搜一搜 java.lang.ClassNotFoundException: kotlin.reflect.Kotlin Reflect Internal Error 四、点击第一个看一看 这里写链接内容 这个高分哥们说,他升级了Kotlin版本和Jackson版本后就好了 五、那么我们也来更新一下 1.先来更新Kotlin的版本,1.2.30 2.再来搜搜,看看jackson-module-kotlin:版本更新到哪里了 以前配的是2.8.4,可能太老了 compile "com.fasterxml.jackson.module:jackson-module-kotlin:2.8.4" maven仓库 3.将2.9版本的配上去 六、启动成功了,现在问题解决了 好啦,结束啦!

优秀的个人博客,低调大师

黑客也看《人民的名义》:把手机卡扔马桶有 bug

自从《人民的名义》的导演在接受媒体采访时表示,有点担心这部剧随时会断播时,雷锋网编辑就领会了这层意思:赶紧看,且看且珍惜。 果不其然,这部剧最近有点火。剧情是这样开始的: “一位国家部委的项目处长被人举报受贿千万,当最高人民检察院反贪总局侦查处处长侯亮平前来搜查时,看到的却是一位长相憨厚、衣着朴素的“老农民”在简陋破败的旧房里吃炸酱面。 当这位腐败分子的面具被最终撕开的同时,与之案件牵连甚紧的 H 省京州市副市长丁义珍,却在一位神秘人物的暗中相助下,以反侦察手段逃脱法网,流亡海外。案件线索终定位于由京州光明峰项目引发的一家H省国企大风服装厂的股权争夺,牵连其中的各派政治势力却盘根错节,扑朔迷离。” 在大家为展现的反腐尺度和紧张剧情欢欣鼓舞时,雷锋网编辑却发现了一些“不一样”的信息。尤其是,雷锋网发现,神秘人物将给丁义珍通风报信的手机卡

优秀的个人博客,低调大师

【我的Android进阶之旅】 解决bug: Expected file scheme in URI: content://download...

一、错误描述 今天测试MM用HTC手机测试某个模块的时候crash了,抓log后发现是使用DownloadManager下载apk安装包然后自动安装的时候,抛了异常:java.lang.IllegalArgumentException: Expected file scheme in URI: content://downloads/my_downloads/12 具体crash错误信息如下所示: 11-30 09:24:21.933 28279 28279 E AndroidRuntime: FATAL EXCEPTION: main 11-30 09:24:21.933 28279 28279 E AndroidRuntime: Process: com.xtc.watch, PID: 28279 11-30 09:24:21.933 28279 28279 E AndroidRuntime: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.xtc.watch (has extras) } in com.xtc.watch.service.compatible.VersionCompatibleUpdateService$DownloadCompleteReceiver@33fa7ec 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:934) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.os.Looper.loop(Looper.java:168) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5885) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Expected file scheme in URI: content://downloads/my_downloads/12 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at java.io.File.checkURI(File.java:223) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at java.io.File.<init>(File.java:175) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.xtc.watch.service.compatible.VersionCompatibleUpdateService.a(Unknown Source) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.xtc.watch.service.compatible.VersionCompatibleUpdateService.a(Unknown Source) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.xtc.watch.service.compatible.VersionCompatibleUpdateService$DownloadCompleteReceiver.onReceive(Unknown Source) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:915) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: ... 7 more 11-30 09:24:21.939 1785 3503 E ActivityManager: App crashed! Process: com.xtc.watch 二、错误分析 进入File.java查看代码, /** * Constructs a new File using the path of the specified URI. {@code uri} * needs to be an absolute and hierarchical Unified Resource Identifier with * file scheme and non-empty path component, but with undefined authority, * query or fragment components. * * @param uri * the Unified Resource Identifier that is used to construct this * file. * @throws IllegalArgumentException * if {@code uri} does not comply with the conditions above. * @see #toURI * @see java.net.URI */ public File(URI uri) { // check pre-conditions checkURI(uri); this.path = fixSlashes(uri.getPath()); } checkURI(URI uri)的源代码如下: private static void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException("URI is not absolute: " + uri); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException("URI is not hierarchical: " + uri); } if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } String rawPath = uri.getRawPath(); if (rawPath == null || rawPath.isEmpty()) { throw new IllegalArgumentException("Expected non-empty path in URI: " + uri); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException("Found authority in URI: " + uri); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException("Found query in URI: " + uri); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException("Found fragment in URI: " + uri); } } 原来就是下面这一段代码抛出的异常,如果uri不是以file开头的就抛异常IllegalArgumentException(“Expected file scheme in URI: ” + uri), if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } 而我们的uri 是通过下面代码获取而来的 Uri downloadFileUri = manager.getUriForDownloadedFile(downId); File file = new File(new URI(downloadFileUri.toString())); 得到的uri信息为 content://downloads/my_downloads/12 因此就抛了该异常出来。 getUriForDownloadedFile(long id)源代码如下: /** * Returns the {@link Uri} of the given downloaded file id, if the file is * downloaded successfully. Otherwise, null is returned. *<p> * If the specified downloaded file is in external storage (for example, /sdcard dir), * then it is assumed to be safe for anyone to read and the returned {@link Uri} corresponds * to the filepath on sdcard. * * @param id the id of the downloaded file. * @return the {@link Uri} of the given downloaded file id, if download was successful. null * otherwise. */ public Uri getUriForDownloadedFile(long id) { // to check if the file is in cache, get its destination from the database Query query = new Query().setFilterById(id); Cursor cursor = null; try { cursor = query(query); if (cursor == null) { return null; } if (cursor.moveToFirst()) { int status = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_STATUS)); if (DownloadManager.STATUS_SUCCESSFUL == status) { int indx = cursor.getColumnIndexOrThrow( Downloads.Impl.COLUMN_DESTINATION); int destination = cursor.getInt(indx); // TODO: if we ever add API to DownloadManager to let the caller specify // non-external storage for a downloaded file, then the following code // should also check for that destination. if (destination == Downloads.Impl.DESTINATION_CACHE_PARTITION || destination == Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION || destination == Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING || destination == Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE) { // return private uri return ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI, id); } else { // return public uri String path = cursor.getString( cursor.getColumnIndexOrThrow(COLUMN_LOCAL_FILENAME)); return Uri.fromFile(new File(path)); } } } } finally { if (cursor != null) { cursor.close(); } } // downloaded file not found or its status is not 'successfully completed' return null; } 三、错误解决 将之前查找下载好的apk文件的代码 Uri downloadFileUri = manager.getUriForDownloadedFile(downId); File file = new File(new URI(downloadFileUri.toString())); 改为通过downId来查询DownloadManager下载的数据库的记录,然后查找本地文件的路径,如下所示: Cursor c = manager.query(new DownloadManager.Query().setFilterById(downId)); if(c != null){ c.moveToFirst(); int fileNameIdx = c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME); String fileName = c.getString(fileNameIdx); File file = new File(fileName); LogUtil.d(TAG, "安装文件:" + file.getAbsolutePath()); c.close(); } 安装apk的代码由 //自动安装apk Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType(downloadFileUri, "application/vnd.android.package-archive"); install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(install); 改为 //自动安装apk Intent install = new Intent(Intent.ACTION_VIEW); //install.setDataAndType(downloadFileUri, "application/vnd.android.package-archive"); install.setDataAndType(Uri.parse("file://" + fileName.toString()), "application/vnd.android.package-archive"); install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(install); 这样通过查询本地真实的下载好apk的真实本地路径,然后再进行安装的话就不会报异常了。 参考文章: http://blog.csdn.net/q445697127/article/details/40537945 http://www.xuebuyuan.com/2163407.html http://www.2cto.com/kf/201502/376975.html 作者:欧阳鹏 欢迎转载,与人分享是进步的源泉! 转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/53404379

优秀的个人博客,低调大师

快速部署、排查Bug,向日葵远控CMD/SSH让开发更顺畅

每个程序员大概都懂那种场景——项目部署到服务器后,明明只是想改个配置、重启个进程,结果还得远程打开桌面,连界面加载都要等半天。尤其是服务器性能紧张时,远控桌面卡顿、加载慢、输入延迟,一次简单的操作就能浪费好几分钟。其实很多时候我们并不需要图形界面,只要能敲几行命令,就能高效解决问题。而这正是向日葵的CMD/SSH远程命令行功能最让人惊喜的地方。 在日常的运维或开发场景里,命令行往往比桌面更直接、更高效。向日葵的CMD/SSH功能,就是为这种高频操作而生的“效率神器”。无论是远程管理主机、部署应用,还是紧急排查问题,它都能帮你省下打开桌面的那几步,让每次远控操作更轻更快。 Windows用户:一键远控命令行,操作流畅 如果你是Windows用户,在向日葵设备列表中选中目标主机,点击「CMD」按钮,输入访问密码后,远程主机的命令行窗口就会直接弹出。整个过程几乎没有延迟,也不占用桌面资源。你可以像在本地一样执行任何命令,从系统管理到脚本运行,全程流畅。对于那些只需要执行服务重启、日志查看、环境变量修改等轻量级操作的开发者而言,这简直是生产力的加速键。 macOS/Linux用户:自动SSH模式,跨系统无障碍 而对于macOS或Linux用户,向日葵则会自动切换为「SSH」模式。只需登录系统账号,就能直接进入终端环境,进行所有命令行操作。无需繁琐设置,也不必安装额外的SSH客户端,跨系统的远程调试和管理就能轻松完成。需要注意的是,mac 用户在首次使用前,可以在「系统偏好设置 → 共享」中开启「远程登录」选项,以确保SSH连接顺畅。 安全保障:多重权限与访问控制 当然,安全性永远是远程控制中最重要的一环。向日葵在CMD/SSH连接中同样采用多重防护机制——每次连接都需要输入访问密码,系统账号权限也能精确控制。操作日志、连接记录清晰可追溯,既能保证调试安全,又能在团队协作时轻松实现权限分级。 以前遇到紧急问题,总得连上远控桌面,等界面加载、鼠标响应;现在只需点击CMD或SSH,命令行一开,几行指令下去,问题立刻解决。尤其在多主机环境下,能快速切换、批量操作,效率提升肉眼可见。 有时候,真正的高效不是多开几个窗口,而是少走几步操作。向日葵CMD/SSH功能,就是这样一个让程序员“事半功倍”的小细节——不用桌面,也能掌控全局。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册