Android Studio 2.3.3环境下载失败

Android Studio 2.3.3环境,当出现sources for 'Android API 27 Platform' not found的时候,点击download,弹出失败警告框,内容如下:
All packages are not available for download!
The following packages are not available:
-Package id source;android-27
但是这个应该不是API 27的问题,好像下载其它API版本的时候也可能这样。这是什么问题呢?

4个回答

Android Studio已经升级到3.0.估计2,3,3不维护了

可以下载 android 2.2.2 上面都是弄好的 直接安装就可以使用了

Check HTTP Proxy

可能是网的原因,实在不行下载3.0试一试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Android studio 3.1.3 初始化项目 build 失败问题
本机环境:mac 10.12.6 . Android Studio 3.1.3 代理已测试可连结youtube.com ![图片说明](https://img-ask.csdn.net/upload/201807/07/1530931982_394881.png) build.gradle ``` apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.example.hubs.ok" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } buildToolsVersion '28.0.1' compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } ``` 点击编译时一直卡在Download .... ![图片说明](https://img-ask.csdn.net/upload/201807/07/1530932031_62049.png) 命令行里gradlew build 也一直卡在这 ![图片说明](https://img-ask.csdn.net/upload/201807/07/1530932050_488694.png) 本地curl -i 是可以访问链接的 ![图片说明](https://img-ask.csdn.net/upload/201807/07/1530932079_448161.png) 到底是什么原因呢...崩溃了....哪些同学遇到过这个情况?谢谢。
android studio 5.0以下编译不成功
android studio classpath 'com.android.tools.build:gradle:2.0.0' 这能编译成功5.0以上的,以下的都编译不成功 bulid。gradle: compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1" } 如果将.build:gradle:2.0.0 改成1.2.3的话连5.0都编译不成功了 编译失败的原因是导包重复 Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Program Files\Java\jdk1.7\bin\java.exe'' finished with non-zero exit value 2 跪求大牛帮忙解答。。。
Android Studio2.3.3真机调试安装失败
为什么使用avd就能安装成功,真机就不能安装成功? 提示如图 ![图片说明](https://img-ask.csdn.net/upload/201710/08/1507469872_381407.png)
Android Studio 升级到3.5的错误
Android Studio 弹出升级的消息框,手贱点了一下 ,然后升级到了Android Studio3.5,升级完成后打开Android Studio ,提示升级失败,查看错误为: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V at org.sqlite.core.NativeDB._open_utf8(Native Method) at org.sqlite.core.NativeDB._open(NativeDB.java:71) at org.sqlite.core.DB.open(DB.java:174) at org.sqlite.core.CoreConnection.open(CoreConnection.java:220) at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76) at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:25) at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:24) at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45) at org.sqlite.JDBC.createConnection(JDBC.java:114) at org.sqlite.JDBC.connect(JDBC.java:88) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:270) at com.android.tools.deployer.SqlApkFileDatabase.<init>(SqlApkFileDatabase.java:62) at com.android.tools.deployer.SqlApkFileDatabase.<init>(SqlApkFileDatabase.java:50) at com.android.tools.idea.run.DeploymentService.<init>(DeploymentService.java:56) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193) at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.doGetComponentInstance(CachingConstructorInjectionComponentAdapter.java:92) at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.instantiateGuarded(CachingConstructorInjectionComponentAdapter.java:66) at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.getComponentInstance(CachingConstructorInjectionComponentAdapter.java:48) at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter.createAndInitialize(ServiceManagerImpl.java:222) at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter.lambda$getComponentInstance$0(ServiceManagerImpl.java:209) at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter.getComponentInstance(ServiceManagerImpl.java:213) at com.intellij.util.pico.DefaultPicoContainer.getLocalInstance(DefaultPicoContainer.java:246) at com.intellij.util.pico.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:213) at com.intellij.openapi.components.ServiceManager.doGetService(ServiceManager.java:52) at com.intellij.openapi.components.ServiceManager.getService(ServiceManager.java:30) at com.android.tools.idea.run.DeploymentService.getInstance(DeploymentService.java:48) at com.android.tools.idea.deploy.DeployActionsInitializer.updateDeployableProvider(DeployActionsInitializer.java:184) at com.android.tools.idea.deploy.DeployActionsInitializer.access$000(DeployActionsInitializer.java:56) at com.android.tools.idea.deploy.DeployActionsInitializer$1.projectOpened(DeployActionsInitializer.java:123) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:114) at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:393) at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:354) at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:343) at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:320) at com.intellij.util.messages.impl.MessageBusImpl.access$100(MessageBusImpl.java:29) at com.intellij.util.messages.impl.MessageBusImpl$1.invoke(MessageBusImpl.java:192) at com.sun.proxy.$Proxy17.projectOpened(Unknown Source) at com.intellij.openapi.project.impl.ProjectManagerImpl.fireProjectOpened(ProjectManagerImpl.java:780) at com.intellij.openapi.project.impl.ProjectManagerImpl.lambda$null$6(ProjectManagerImpl.java:401) at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransactionAndWait$2(TransactionGuardImpl.java:165) at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88) at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111) at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:435) at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:419) at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:403) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764) at java.awt.EventQueue.access$500(EventQueue.java:98) at java.awt.EventQueue$3.run(EventQueue.java:715) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) at java.awt.EventQueue.dispatchEvent(EventQueue.java:734) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:757) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:706) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:375) at com.intellij.ide.IdeEventQueue.pumpEventsForHierarchy(IdeEventQueue.java:814) at com.intellij.openapi.progress.util.ProgressWindow.startBlocking(ProgressWindow.java:210) at com.intellij.openapi.progress.util.ProgressWindow.startBlocking(ProgressWindow.java:196) at com.intellij.openapi.application.impl.ApplicationImpl.runProcessWithProgressSynchronously(ApplicationImpl.java:609) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressSynchronously(CoreProgressManager.java:454) at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcessWithProgressSynchronously(ProgressManagerImpl.java:109) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressSynchronously(CoreProgressManager.java:251) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressSynchronously(CoreProgressManager.java:205) at com.intellij.openapi.project.impl.ProjectManagerImpl.loadProjectUnderProgress(ProjectManagerImpl.java:450) at com.intellij.openapi.project.impl.ProjectManagerImpl.openProject(ProjectManagerImpl.java:425) at com.intellij.platform.PlatformProjectOpenProcessor.doOpenProject(PlatformProjectOpenProcessor.java:260) at com.intellij.ide.RecentProjectsManagerBase.doOpenProject(RecentProjectsManagerBase.java:512) at com.intellij.ide.RecentProjectsManagerBase.doReopenLastProject(RecentProjectsManagerBase.java:634) at com.intellij.ide.RecentProjectsManagerBase$MyAppLifecycleListener.appStarting(RecentProjectsManagerBase.java:692) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:114) at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:393) at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:354) at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:343) at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:320) at com.intellij.util.messages.impl.MessageBusImpl.access$100(MessageBusImpl.java:29) at com.intellij.util.messages.impl.MessageBusImpl$1.invoke(MessageBusImpl.java:192) at com.sun.proxy.$Proxy63.appStarting(Unknown Source) at com.intellij.idea.IdeaApplication$IdeStarter.lambda$main$1(IdeaApplication.java:388) at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88) at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111) at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:120) at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:121) at com.intellij.idea.IdeaApplication$IdeStarter.main(IdeaApplication.java:386) at com.intellij.idea.IdeaApplication.lambda$run$1(IdeaApplication.java:220) at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:195) at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:220) at com.intellij.idea.IdeaApplication.lambda$initApplication$0(IdeaApplication.java:77) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764) at java.awt.EventQueue.access$500(EventQueue.java:98) at java.awt.EventQueue$3.run(EventQueue.java:715) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) at java.awt.EventQueue.dispatchEvent(EventQueue.java:734) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:349) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 操作系统是Win10 专业版 64位。 以为是我的老版本导致的程序不对,然后把和Android Studio有关的文件都删了,重新安装,安装好了以后可以用了,但是关了AS,再重新打开AS,又开始报上面的错误,有没有遇到这个问题的?如何来解决这个问题? ------------------------------------------------------------》》》》》 很白痴的问题,以及个人的习惯导致的,使用管理员权限打开就好了,AS会在AppData/Local 中创建一个临时的sqlite 数据访问的dll,不是管理员权限访问不了,就导致了这个错误。
android studio编译失败
android studio 版本从2.2更新到3.0后不论是打开之前的项目,还是新建一个项目,编译都会出现同一种错误 Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details 之前百度了很多,试过之后也没解决,求大神解答
Android Studio跑高德地图的demo失败
今天想试一下运行高德地图的demo,把压缩包下载好后解压,用Android Stuidio打开,一开始构建项目没有问题 ![图片说明](https://img-ask.csdn.net/upload/201911/12/1573561170_879420.png)![图片说明](https://img-ask.csdn.net/upload/201911/12/1573561213_955542.png) 但是当我点击build apks时,就出问题了![图片说明](https://img-ask.csdn.net/upload/201911/12/1573561294_33079.png) 说这项工程使用的gradle版本不支持,但是我同学用就没报错,他也不知道什么情况。这个项目使用的android gradle是2.1.3版本的,gradle版本是2.14.1版本的![图片说明](https://img-ask.csdn.net/upload/201911/12/1573561498_185491.png)![图片说明](https://img-ask.csdn.net/upload/201911/12/1573561505_326911.png) 找了一天的bug了,有没有大佬告诉我这是哪里配置有问题吗
android APP连接mysql时,APP闪退
安卓程序连接MySQL一直不成功,本地连接可以。我是用手机调试的,点击接mysql按钮时,APP闪退。在网上找了好多方法都不行。求看看什么问题 错误日志如下: 2019-08-25 08:25:33.377 5570-5570/mark.zhang E/AndroidRuntime: FATAL EXCEPTION: main Process: mark.zhang, PID: 5570 java.lang.IllegalStateException: Could not execute method for android:onClick at android.view.View$DeclaredOnClickListener.onClick(View.java:5692) at android.view.View.performClick(View.java:6663) at android.view.View.performClickInternal(View.java:6635) at android.view.View.access$3100(View.java:794) at android.view.View$PerformClick.run(View.java:26199) at android.os.Handler.handleCallback(Handler.java:907) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.view.View$DeclaredOnClickListener.onClick(View.java:5687) at android.view.View.performClick(View.java:6663)  at android.view.View.performClickInternal(View.java:6635)  at android.view.View.access$3100(View.java:794)  at android.view.View$PerformClick.run(View.java:26199)  at android.os.Handler.handleCallback(Handler.java:907)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:216)  at android.app.ActivityThread.main(ActivityThread.java:7625)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)  Caused by: java.lang.BootstrapMethodError: Exception from call site #39 bootstrap method at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.<clinit>(AbandonedConnectionCleanupThread.java:58) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at java.lang.Class.forName(Class.java:378) at com.mysql.cj.jdbc.NonRegisteringDriver.<clinit>(NonRegisteringDriver.java:99) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at java.lang.Class.forName(Class.java:378) at mark.zhang.Util.openConnection(Util.java:16) at mark.zhang.Main.onConn(Main.java:30) at java.lang.reflect.Method.invoke(Native Method)  at android.view.View$DeclaredOnClickListener.onClick(View.java:5687)  at android.view.View.performClick(View.java:6663)  at android.view.View.performClickInternal(View.java:6635)  at android.view.View.access$3100(View.java:794)  at android.view.View$PerformClick.run(View.java:26199)  at android.os.Handler.handleCallback(Handler.java:907)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:216)  at android.app.ActivityThread.main(ActivityThread.java:7625)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)  Caused by: java.lang.ClassCastException: Bootstrap method returned null at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.<clinit>(AbandonedConnectionCleanupThread.java:58)  at java.lang.Class.classForName(Native Method)  at java.lang.Class.forName(Class.java:453)  at java.lang.Class.forName(Class.java:378)  at com.mysql.cj.jdbc.NonRegisteringDriver.<clinit>(NonRegisteringDriver.java:99)  at java.lang.Class.classForName(Native Method)  at java.lang.Class.forName(Class.java:453)  at java.lang.Class.forName(Class.java:378)  at mark.zhang.Util.openConnection(Util.java:16)  at mark.zhang.Main.onConn(Main.java:30)  at java.lang.reflect.Method.invoke(Native Method)  at android.view.View$DeclaredOnClickListener.onClick(View.java:5687)  at android.view.View.performClick(View.java:6663)  at android.view.View.performClickInternal(View.java:6635)  at android.view.View.access$3100(View.java:794)  at android.view.View$PerformClick.run(View.java:26199)  at android.os.Handler.handleCallback(Handler.java:907)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:216)  at android.app.ActivityThread.main(ActivityThread.java:7625)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)  2019-08-25 08:25:33.398 5570-5570/mark.zhang I/Process: Sending signal. PID: 5570 SIG: 9 源码如下: 这是util.java ``` package mark.zhang; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Util { public static Connection openConnection(String url, String user, String password) { Connection conn = null; try { final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver"; Class.forName(DRIVER_NAME); conn = DriverManager.getConnection(url, user, password); } catch (ClassNotFoundException e) { conn = null; } catch (SQLException e) { conn = null; } return conn; } public static void query(Connection conn, String sql) { if (conn == null) { return; } Statement statement = null; ResultSet result = null; try { statement = conn.createStatement(); result = statement.executeQuery(sql); if (result != null && result.first()) { int idColumnIndex = result.findColumn("id"); int nameColumnIndex = result.findColumn("name"); System.out.println("id\t\t" + "name"); while (!result.isAfterLast()) { System.out.print(result.getString(idColumnIndex) + "\t\t"); System.out.println(result.getString(nameColumnIndex)); result.next(); } } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (result != null) { result.close(); result = null; } if (statement != null) { statement.close(); statement = null; } } catch (SQLException sqle) { } } } public static boolean execSQL(Connection conn, String sql) { boolean execResult = false; if (conn == null) { return execResult; } Statement statement = null; try { statement = conn.createStatement(); if (statement != null) { execResult = statement.execute(sql); } } catch (SQLException e) { execResult = false; } return execResult; } } ``` 这是main.java ``` package mark.zhang; import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread; import java.sql.Connection; import java.sql.SQLException; import androidx.appcompat.app.AppCompatActivity; import android.app.Activity; import android.os.Bundle; import android.view.View; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main extends Activity { private static final String REMOTE_IP = "223.104.64.237"; private static final String URL = "jdbc:mysql://223.104.64.237:3306/mydb?useSSL=false&serverTimezone=GMT&characterEncoding=utf-8&autoReconnect=true"; private static final String USER = "root"; private static final String PASSWORD = "123"; private Connection conn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onConn(View view) { conn = Util.openConnection(URL, USER, PASSWORD); /* final Thread thread = new Thread(new Runnable() { @Override public void run() { // 反复尝试连接,直到连接成功后退出循环 while (!Thread.interrupted()) { try { Thread.sleep(100); // 每隔0.1秒尝试连接 } catch (InterruptedException e) { System.out.println("链接数据库"); } // 2.设置好IP/端口/数据库名/用户名/密码等必要的连接信息 String url="jdbc:mysql://223.104.64.237:3306/mydb?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true"; String user = "root"; String password = "123"; // 3.连接JDBC try { Class.forName("com.mysql.cj.jdbc.Driver"); Connection conn = DriverManager.getConnection(url,user,password); System.out.println("远程连接成功!"); conn.close(); return; } catch (SQLException e) { System.out.println("远程连接失败!"); } catch (ClassNotFoundException e){ } } } }); thread.start();*/ } public void onInsert(View view) { String sql = "insert into mytable values(9, 'hanmeimei')"; Util.execSQL(conn, sql); } public void onDelete(View view) { String sql = "delete from mytable where name='mark'"; Util.execSQL(conn, sql); } public void onUpdate(View view) { String sql = "update mytable set name='李磊' where name='韩美'"; Util.execSQL(conn, sql); } public void onQuery(View view) { System.out.println("All users info:"); Util.query(conn, "select * from mytable"); } @Override protected void onDestroy() { super.onDestroy(); if (conn != null) { try { conn.close(); } catch (SQLException e) { conn = null; } finally { conn = null; } } } } ```
int com_fd = newPort.openPort(uart, 0, (char) longUart);这段代码错在哪里?
package com.example.newland.serialport; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.newland.jni.Convert; import com.newland.jni.SerialPort;//串口类 import com.newland.jni.OnDataReceivedListener;//数据接收监听口 import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.Spinner; import android.widget.ArrayAdapter; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private String strReceiveData="";//串口接收的数据 private Spinner spBaudRate,spUart; private EditText etAck,etSend; private TextView tvUartStatus; private CheckBox chkSendHex,chkAckHex; SerialPort newPort=new SerialPort();//定义一个串口 private int[] sectCom={0,1,2,3}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initComponent();//初始化控件 initSpinnerBaudRate();//初始化下拉框的值 //PC机发送数据是不定时的,故采用响应模式来接收数据 newPort.setCommReceivedMode(true);//设置串口通讯为响应模式 //设置数据接收的监听器 newPort.setOnDataReceivedListener(new OnDataReceivedListener() { public void onDataReceived(String data) { handleReceivedData(data);//处理接受的数据 } }); } /**************************************** * 函数名称:initComponent * 功能描述:初始化界面 * 参数及返回值说明: * ****************************************/ private void initComponent(){ //初始化控件 tvUartStatus=(TextView)findViewById(R.id.tvUartStatus); etAck=(EditText) findViewById(R.id.etAck); etSend=(EditText)findViewById(R.id.etSend); spBaudRate=(Spinner)findViewById(R.id.spBaudRate); spUart=(Spinner)findViewById(R.id.spUart); chkSendHex=(CheckBox)findViewById(R.id.chkSendHex); chkAckHex=(CheckBox)findViewById(R.id.chkAckHex); chkSendHex.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { String str=etSend.getText().toString(); try { if (isChecked) { etSend.setText(Convert.stringToHexString(str)); } else { etSend.setText(Convert.hexStringToString(str)); } }catch (Exception e){ } } }); //增加事件监听,实现字符串与十六进制互转 chkAckHex.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { String str=etAck.getText().toString(); try { if (isChecked) { etAck.setText(Convert.stringToHexString(str)); } else { etAck.setText(Convert.hexStringToString(str)); } }catch (Exception e){ //TODO:handle exception } } }); } /******* * 函数名称:initSpinnerBaudRate * 功能描述:初始化波特率的值 * 参数及返回值说明:* *******/ private void initSpinnerBaudRate(){ //下拉波特率的值 String[] items={"1200","B2400","B4800","9600","19200","38400","57600","115200","230400","921600"}; //第一步:为下拉列表定义一个适配器,这里就用到里前面定义的items。 final ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items); //第二步:为适配器配置下拉列表下拉时的菜单样式。 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //第三步:将适配器添加到下拉列表上 spBaudRate.setAdapter(adapter); //默认选择第6项--57600 spBaudRate.setSelection(6); //下拉串口的值 String[] uarts={"COM0","COM1","COM2","COM3"}; final ArrayAdapter<String>adapterUart=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,uarts); adapterUart.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spUart.setAdapter(adapterUart); spUart.setSelection(2);//默认选择第二项--COM2 } /******* * 函数名称:myClick * 功能描述:按钮监听 * 参数及返回值说明 *******/ public void myClick(View v) { switch(v.getId()) { //打开串口 case R.id.btnOpenUart: long longUart = spUart.getSelectedItemId(); int uart = sectCom[(int) longUart]; longUart = spBaudRate.getSelectedItemId(); int com_fd = newPort.openPort(uart, 0, (char) longUart); if (com_fd > 0) { tvUartStatus.setText("打开成功!..."); } else { tvUartStatus.setText("打开失败!...");} break; //关闭串口 case R.id.btnCloseUart: newPort.closePort(); tvUartStatus.setText("已关闭!..."); break; //发送 case R.id.btnSend: String msg = etSend.getText().toString(); if (chkSendHex.isChecked()) {//以十六进制数发送 newPort.sendCommand(Convert.hexStringToCharArray(msg)); } else {//以字符串发送 newPort.sendCommand(Convert.stringToCharArray(msg)); } break; //清除按钮 case R.id.btnClear: etAck.setText(""); strReceiveData = ""; break; //退出 case R.id.btnQuit: System.exit(0); default: break; } } /************ * 函数名称:handleReceiveData * 功能描述:处理数据 * 参数说明:data,从串口中接收到的数据 ************/ protected void handleReceivedData(final String data){ runOnUiThread(new Runnable() {//通过runOnUiThread在线程中执行UI更新操作 public void run() { strReceiveData = strReceiveData + data; if (chkAckHex.isChecked()) {//十六进制显示 etAck.setText(Convert.dataToHexString(strReceiveData)); }else { etAck.setText(Convert.dataToHexString(strReceiveData));} } }); } @Override protected void onDestroy(){ super.onDestroy(); newPort.onDestroy(); } } E/JIN: WARNING:could not load libuart.so E/zygote: No implementation found for int com.newland.jni.Linuxc.openUart(int, int) (tried Java_com_newland_jni_Linuxc_openUart and Java_com_newland_jni_Linuxc_openUart__II) D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.newland.serialport, PID: 25212 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390) at android.view.View.performClick(View.java:6256) at android.view.View$PerformClick.run(View.java:24701) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) at android.view.View.performClick(View.java:6256)  at android.view.View$PerformClick.run(View.java:24701)  at android.os.Handler.handleCallback(Handler.java:789)  at android.os.Handler.dispatchMessage(Handler.java:98)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)  Caused by: java.lang.UnsatisfiedLinkError: No implementation found for int com.newland.jni.Linuxc.openUart(int, int) (tried Java_com_newland_jni_Linuxc_openUart and Java_com_newland_jni_Linuxc_openUart__II) at com.newland.jni.Linuxc.openUart(Native Method) at com.newland.jni.SerialPort.openPort(SerialPort.java:87) at com.example.newland.serialport.MainActivity.myClick(MainActivity.java:132) at java.lang.reflect.Method.invoke(Native Method)  at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)  at android.view.View.performClick(View.java:6256)  at android.view.View$PerformClick.run(View.java:24701)  at android.os.Handler.handleCallback(Handler.java:789)  at android.os.Handler.dispatchMessage(Handler.java:98)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)  Application terminated.
android studio 与后台交互问题 网络访问的问题
url返回了我需要的值 只有我在控制台点击url的时候 服务器端才会有反应 HttpResponse response = httpClient.execute(httpGet);不执行 代码如下: package com.cy.mynj.com.cy.mynj.login; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.cy.mynj.R; import com.cy.mynj.com.cy.mynj.activities.MainActivity; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; public class LoginActivity extends AppCompatActivity implements View.OnClickListener{ private EditText et_phone; private EditText et_password; private Button btn_login; private TextView tv_login_register; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); initViews(); } private void initViews() { et_phone=(EditText)findViewById(R.id.et_phone); et_password=(EditText)findViewById(R.id.et_password); btn_login=(Button)findViewById(R.id.btn_login); btn_login.setOnClickListener(this); tv_login_register=(TextView)findViewById(R.id.tv_login_register); tv_login_register.setOnClickListener(this); tv=(TextView)findViewById(R.id.tv); } @Override public void onClick(View view) { String phone = et_phone.getText().toString(); String password=et_password.getText().toString(); System.out.println(phone + "," + password); System.out.println("按钮点击的线程的名字为:" + Thread.currentThread().getName()); Mythread mythread= new Mythread(phone,password); mythread.start(); } Handler handler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); tv.setText(Thread.currentThread().getName() + msg.obj); // 在把这个字符串变成一个JSONObejct try { JSONObject obj = new JSONObject(msg.obj.toString()); String value = obj.getString("loginstate"); System.out.println("value-->" + value); if (value.equals("success")) { Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); } else { Toast.makeText(LoginActivity.this, "登录失败",Toast.LENGTH_SHORT ).show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; private class Mythread extends Thread { private String phone; private String password; public Mythread(String phone, String password) { this.phone = phone; this.password = password; } @Override public void run () { // 在线程中请求服务器的资源 // Apache HttpClient // 1.创建HttpClient对象 HttpClient httpClient = new DefaultHttpClient(); Log.d("test", "t0"); // 2.构建请求的URL String url = "http://172.20.10.3:8080/appnews/user?phone=" + phone + "&password=" + password + "&operator=login"; // String url = "http://10.0.2.2:8080/appnews/servlet/StudentServlet"; // 3.创建HttpGet请求的对象 HttpGet httpGet = new HttpGet(url); Log.d("test4", "t4"); // 4.使用创建的httpClient执行这个httpGet请求 try { HttpResponse response = httpClient.execute(httpGet); Log.d("test3", "t3"); // 5.判断服务器端请求和应答是否成功 if (response.getStatusLine().getStatusCode() == 200) { System.out.println("请求和应答成功"); // 服务器端传输的数据的一个android封装的对象 HttpEntity entity = response.getEntity(); String msg = EntityUtils.toString(entity, "UTF-8"); System.out.println("server-->" + msg); // 在android中,子线程不能更新界面组件的值, // 因为界面组件是单线程模型,必须回到主线程更新组件的值。 // tv.setText(msg); // 构建消息对象 Message smsg = new Message(); smsg.obj = msg; handler.sendMessage(smsg); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block Log.d("test5", "t5"); e.printStackTrace(); } } } }
android studio运行报下列错误
1.貌似有问题的代码 package com.example.coolweather; import android.app.Fragment; import android.app.ProgressDialog; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.example.coolweather.db.City; import com.example.coolweather.db.County; import com.example.coolweather.db.Province; import com.example.coolweather.util.HttpUtil; import com.example.coolweather.util.Utility; import org.litepal.crud.DataSupport; import java.io.IOException; import java.util.ArrayList; import java.util.List; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by Airth on 2019/5/10. */ public class ChooseAreaFragment extends Fragment { public static final int LEVEL_PROVINCE=0; public static final int LEVEL_CITY=1; public static final int LEVEL_COUNTY=2; private ProgressDialog progressDialog; private TextView titleText; private Button backButton; private ListView listView; private ArrayAdapter<String> adapter; private List<String> dataList = new ArrayList<>(); private int currentLevel; //当前被选中的级别 private Province selectedProvince;//被选中的省份 private City selectedCity;//被选中的城市 private List<Province> provinceList;//省列表 private List<City> cityList;//市列表 private List<County> countyList ;//县列表 /*获取控件实例id*/ @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Log.d("ChooseAreaFragment","onCreateView"); View view = inflater.inflate(R.layout.choose_area,container,false); titleText = (TextView)view.findViewById(R.id.title_text); //获取标题栏文本id backButton = (Button) view.findViewById(R.id.back_button); //获取标题栏id listView = (ListView)view.findViewById(R.id.list_view); //获取Item列表id //获取ArrayAdapter对象 adapter =new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, dataList); listView.setAdapter(adapter);//设置并初始化适配器 return view;//将视图返回 } /*点击事件集合*/ @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { Log.d("ChooseAreaFragment","onActivityCreated"); super.onActivityCreated(savedInstanceState); //列表任意一栏被点击,则... listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d("ChooseAreaFragment","列表被点了的..."); if (currentLevel == LEVEL_PROVINCE){ //当前选中的级别为省份时 selectedProvince = provinceList.get(position); //当前点击为选中状态 queryCities();//查询市的方法 } else if (currentLevel == LEVEL_CITY){ selectedCity = cityList.get(position); queryCounties(); } } }); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentLevel == LEVEL_COUNTY){ queryCities(); } else if (currentLevel == LEVEL_CITY){ queryProvinces(); } } }); queryProvinces(); } private void queryCities() { titleText.setText(selectedProvince.getProvinceName()); //设置市的标题内容 backButton.setVisibility(View.VISIBLE); //设置返回按钮可见 //查询被选中的省份城市的市区 cityList = DataSupport.where("provinceid=?",String.valueOf(selectedProvince. getId())).find(City.class); Log.d("ChooseAreaFragment","市级"); if (cityList.size()>0){ //如果省列表不为空,则... dataList.clear(); for (City city:cityList){ //遍历每一份省的市级城市 dataList.add(city.getCityName()); //添加到数据列表中 } adapter.notifyDataSetChanged();//通知适配器数据更新了 listView.setSelection(0); currentLevel = LEVEL_CITY; } else{ int provinceCode = selectedProvince.getProvinceCode(); //获取被选取省级代码 String address = "http://guolin.tech/api/china/"+provinceCode;//获取被选取地区的网络地址 Log.d("ChooseAreaFragment","准备在网络中获取地址信息"); queryFromServer(address,"city"); // 在网络中查询 } } /*根据传入的地址和类型从服务器查询省市县数据*/ private void queryFromServer(String adress, final String type) { showProgressDialog(); // 发送一条网络请求 HttpUtil.sendOKHttpRequest(adress, new Callback() { //请求加载失败 @Override public void onFailure(Call call, IOException e) { //通过runOnUiThread方法回到主线程逻辑 getActivity().runOnUiThread(new Runnable() { @Override public void run() { closeProgressDialog(); Toast.makeText(getContext(),"加载失败",Toast.LENGTH_SHORT).show(); } }); } @Override public void onResponse(Call call, Response response) throws IOException { Log.d("ChooseAreaFragment","加载地区信息..."); String responseText = response.body().string(); boolean result = false; if ("province".equals(type)){ result = Utility.handleProvinceResponse(responseText); } else if ("city".equals(type)){ result = Utility.handleCityResponse(responseText,selectedProvince.getId()); } else if ("county".equals(type)){ result = Utility.handleCountyResponse(responseText, selectedCity.getId()); } if (result) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Log.d("ChooseAreaFragment","开启线程更新UI"); closeProgressDialog(); if ("province".equals(type)){ queryProvinces(); } else if ("city".equals(type)){ queryCities(); } else if ("county".equals(type)){ queryCounties(); } } }); } if ("city".equals(type)){ result = Utility.handleProvinceResponse(responseText); } if ("county".equals(type)){ result = Utility.handleProvinceResponse(responseText); } } }); } /*显示进度对话框*/ private void showProgressDialog() { if (progressDialog==null){ progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("正在加载..."); progressDialog.setCanceledOnTouchOutside(false); } progressDialog.show(); } private void queryCounties() { titleText.setText(selectedCity.getCityName()); backButton.setVisibility(View.VISIBLE); countyList = DataSupport.where("cityid = ?", String.valueOf(selectedCity.getId())).find(County.class); if (countyList.size()>0){ dataList.clear(); for (County county:countyList){ dataList.add(county.getCountyName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel=LEVEL_COUNTY; } else { int provinceCode = selectedProvince.getProvinceCode(); int cityCode = selectedCity.getCityCode(); String address = "http://guolin.tech/api/china/"+provinceCode+"/"+cityCode; queryFromServer(address,"county"); } } /*全国所有的省,优先查询数据库,如果没有再去服务器查询*/ private void queryProvinces() { titleText.setText("中国"); Log.d("ChooseAreaFragment","查询省中..."); backButton.setVisibility(View.GONE); provinceList = DataSupport.findAll(Province.class); if (provinceList.size()>0){ dataList.clear(); for (Province province:provinceList){ dataList.add(province.getProvinceName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel = LEVEL_PROVINCE; } else { Log.d("ChooseAreaFragment","服务器查询省中..."); String address = "http://guolin.tech/api/china"; queryFromServer(address,"province"); } } private void closeProgressDialog() { if (progressDialog!=null){ progressDialog.dismiss(); } } } 2.这是报错日志 ![图片说明](https://img-ask.csdn.net/upload/201905/10/1557481080_879893.png)
从安卓模拟器路径用opencv读取图像失败
软件: android studio3.5 1. 我用 Device File Explorer上传了一张jpg图像到sdcard/Pictures文件夹中 2. 我试图用opencv 的imread函数读取这张图,结果显示读到的矩阵是空的,代码如下: String imPath = Environment.getExternalStorageDirectory() + "/Pictures/moose.jpg"; Mat im = Imgcodecs.imread(imPath, Imgcodecs.IMREAD_GRAYSCALE); if(im.empty()) tips += "Empty image... \n"; else { …… } 这是为什么啊? 难道只能通过 Bitmap bitmap = BitmapFactory.decodeResource(MainActivity.this.getResources(),R.drawable.girl); Mat mat = new Mat(); Utils.bitmapToMat(bitmap,mat); 这种方式才能正常读图吗? 我还想再读取一个本地的pb文件呢,就是读不对啊,请求指点
Android Studio创建虚拟机失败解决方法
1.创建虚拟机后,运行时出现错误对话框,错误内容如下: KVM is required to run this AVD. /dev/kvm is not found. Enable VT-x in your BIOS security settings, ensure that your Linux distro has working KVM module. 2.已经进入系统固件设置(BIOS)界面设置了“Intel (R) Virtualization Technology”项还是启动不了虚拟机。 3.然后又确认下载安装了Download Intel x86 Emulator Accelerator (HAXM installer)。 4.接着下载的SDK目录下找到intelhaxm-android.exe这个文件安装定并运行。但在安装是出现以下错误提示 ![图片说明](https://img-ask.csdn.net/upload/201907/26/1564106790_856784.png)![图片说明](https://img-ask.csdn.net/upload/201907/26/1564106826_333220.png)![图片说明](https://img-ask.csdn.net/upload/201907/26/1564106844_653721.png)![图片说明](https://img-ask.csdn.net/upload/201907/26/1564106862_618320.png)![![图片说明](https://img-ask.csdn.net/upload/201907/26/1564106898_813481.png)![图片说明](https://img-ask.csdn.net/upload/201907/26/1564106910_319616.png) 5.之后再打开虚拟机还是提示KVM is required to run this AVD. /dev/kvm is not found. Enable VT-x in your BIOS security settings, ensure that your Linux distro has working KVM module. 6.出现上面这种情况怎么解决,虚拟机的问题
android studio启动genymotion失败
前几天还能正常启动,然后今天就初始化失败了,然后看了网上也不是没有reg.exe文件,请各位大神帮帮忙吧 9:21:03 Genymotion: Loading Genymotion library 9:21:03 Genymotion: Genymotion directory: E:\workSoftware\genymotion2.5.3\Genymotion 9:21:03 Genymotion: Trying to initialize engine 9:21:04 Genymotion: vboxPath: C:\Program Files\Oracle VM VirtualBox\VBoxManage.exe 9:21:04 Genymotion: Launch process: C:\Program Files\Oracle VM VirtualBox\VBoxManage.exe --version 9:21:04 Genymotion: Exception (C:\Program Files\Oracle VM VirtualBox\VBoxManage.exe) 9:21:04 Genymotion: Initialize Engine: failed 然后我又尝试使用android studio自带的模拟器,提示 ![图片说明](https://img-ask.csdn.net/upload/201605/28/1464401067_681354.png) 这又是什么原因啊!!!!
正在学习android的第一行代码的coolweather遇到了点问题
ChooseAreaFragment代码 import android.app.ProgressDialog; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.widget.ButtonBarLayout; import androidx.fragment.app.Fragment; import com.example.coolweather.db.City; import com.example.coolweather.db.County; import com.example.coolweather.db.Province; import com.example.coolweather.util.HttpUtil; import com.example.coolweather.util.Utility; import org.litepal.crud.DataSupport; import java.io.IOException; import java.util.ArrayList; import java.util.List; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; public class ChooseAreaFrament extends Fragment { public static final int LEVEL_PROVINCE = 0; public static final int LEVEL_CITY=1; public static final int LEVEL_COUNTY = 2; private ProgressDialog progressDialog; private TextView titleText; private Button backButton; private ListView listView; private ArrayAdapter<String> adapter; private List<String> dataList = new ArrayList<>(); /** * 省列表 */ private List<Province> provinceList; /** * 市列表 */ private List<City> cityList; /** * 县列表 */ private List<County>countyList; /** * 选中的省份 */ private Province selectedProvince; /** * 选中的城市 */ private City selectedCity; /** * 当前选中的级别 */ private int currentLevel; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.choose_area,container,false); titleText = (TextView) view.findViewById(R.id.title_text); backButton = (Button) view.findViewById(R.id.back_button); listView = (ListView)view.findViewById(R.id.list_view); adapter = new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,dataList); listView.setAdapter(adapter); return view; } @Override public void onActivityCreated(Bundle savedInstanceState){ super.onActivityCreated(savedInstanceState); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(currentLevel == LEVEL_PROVINCE){ selectedProvince = provinceList.get(position); queryCities(); } else if (currentLevel == LEVEL_CITY) { selectedCity = cityList.get(position); queryCounties(); } } }); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentLevel == LEVEL_COUNTY) { queryCities(); } else if (currentLevel == LEVEL_CITY){ queryProvinces(); } } }); queryProvinces(); } /** * 查询全国所有的省,优先数据库查询,如果没有查询到再去服务器上查询 */ private void queryProvinces(){ titleText.setText("中国"); backButton.setVisibility(View.GONE); provinceList = DataSupport.findAll(Province.class); if (provinceList.size() > 0){ dataList.clear(); for (Province province : provinceList){ dataList.add(province.getProvinceName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel = LEVEL_PROVINCE; } else { String address = "http://guolin.tech/api/china"; queryFromServer(address,"province"); } } /** * 查询全国所有的城市,优先数据库查询,如果没有查询到再去服务器上查询 */ private void queryCities(){ titleText.setText(selectedProvince.getProvinceName()); backButton.setVisibility(View.VISIBLE); cityList = DataSupport.where("provinceid = ?",String.valueOf(selectedProvince. getId())).find(City.class); if(cityList.size() > 0){ dataList.clear(); for(City city : cityList){ dataList.add(city.getCityName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel = LEVEL_CITY; }else{ int provinceCode = selectedProvince.getProvinceCode(); String address = "http://guolin.tech/api/china/" + provinceCode; queryFromServer(address,"city"); } } /** * 查询全国所有的县,优先数据库查询,如果没有查询到再去服务器上查询 */ private void queryCounties(){ titleText.setText(selectedCity.getCityName()); backButton.setVisibility(View.VISIBLE); countyList = DataSupport.where("cityid = ?",String.valueOf(selectedCity. getId())).find(County.class); if(countyList.size() > 0 ){ dataList.clear(); for(County county : countyList){ dataList.add(county.getCountyName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel = LEVEL_COUNTY; }else{ int provinceCode = selectedProvince.getProvinceCode(); int cityCode = selectedCity.getCityCode(); String address = "http://guolin.tech/api/china/" + provinceCode + "/" + cityCode; queryFromServer(address,"county"); } } /** * 根据传入的地址和类型从服务器上查询省市县数据 */ private void queryFromServer(String address,final String type){ showProgressDialog(); HttpUtil.sendOkHttpRequest(address, new Callback() { @Override public void onResponse(Call call, Response response) throws IOException { String responseText = response.body().string(); boolean result = false; if("province".equals(type)){ result = Utility.handleProvinceResponse(responseText); } else if ("city".equals(type)){ result = Utility.handleCityResponse(responseText,selectedProvince.getId()); } else if ("county".equals(type)){ result = Utility.handleCountyResponse(responseText,selectedCity.getId()); } if (result){ getActivity().runOnUiThread(new Runnable() { @Override public void run() { closeProgressDialog(); if ("province".equals(type)){ queryProvinces(); } else if ("city".equals(type)){ queryCities(); } else if ("county".equals(type)) queryCounties(); } }); } } @Override public void onFailure(Call call, IOException e) { //通过runOnUiTread()方法回到主线程处理逻辑 getActivity().runOnUiThread(new Runnable() { @Override public void run() { closeProgressDialog(); Toast.makeText(getContext(),"加载失败",Toast.LENGTH_SHORT).show(); } }); } }); } /** * 显示进度对话框 */ private void showProgressDialog(){ if (progressDialog == null){ progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("正在加载..."); progressDialog.setCanceledOnTouchOutside(false); } progressDialog.show(); } /** * 关闭进度对话框 */ private void closeProgressDialog(){ if (progressDialog != null){ progressDialog.dismiss(); } } Utility代码 import android.text.TextUtils; import com.example.coolweather.db.City; import com.example.coolweather.db.County; import com.example.coolweather.db.Province; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class Utility { /** * 解析和处理服务器返回的省级数据 */ public static boolean handleProvinceResponse(String response){ if (!TextUtils.isEmpty(response)){ try { JSONArray allProvinces = new JSONArray(response); for (int i = 0;i<allProvinces.length();i++){ JSONObject provinceObject = allProvinces.getJSONObject(i); Province province = new Province(); province.setProvinceName(provinceObject.getString("name")); province.setProvinceCode(provinceObject.getInt("id")); province.save(); } return true; } catch (JSONException e) { e.printStackTrace(); } } return false; } /** * 解析服务器和处理器返回的市级数据 */ public static boolean handleCityResponse(String response,int provinceId){ if(!TextUtils.isEmpty(response)){ try { JSONArray allCities = new JSONArray(response); for(int i=0;i<allCities.length();i++){ JSONObject cityObject = allCities.getJSONObject(i); City city = new City(); city.setCityName(cityObject.getString("name")); city.setCityCode(cityObject.getInt("id")); city.setProvinceId(provinceId); city.save(); } return true; } catch (JSONException e) { e.printStackTrace(); } } return false; } public static boolean handleCountyResponse(String response, int cityId){ if(TextUtils.isEmpty(response)){ try { JSONArray allCounties = new JSONArray(response); for(int i=0;i<allCounties.length();i++){ JSONObject countyObject = allCounties.getJSONObject(i); County county = new County(); county.setCountyName(countyObject.getString("name")); county.setWeatherId(countyObject.getString("weather_id")); county.setCityId(cityId); county.save(); } return true; } catch (JSONException e) { e.printStackTrace(); } } return false; } 复制代码 } HttpUtil代码 import okhttp3.OkHttpClient; import okhttp3.Request; public class HttpUtil { public static void sendOkHttpRequest(String address,okhttp3.Callback callback) { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url(address).build(); client.newCall(request).enqueue(callback); } 复制代码 } app apply plugin: 'com.android.application' android { compileSdkVersion 29 buildToolsVersion "29.0.2" defaultConfig { applicationId "com.example.coolweather" minSdkVersion 15 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } sourceSets { main { jniLibs.srcDirs = ['libs'] } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'org.litepal.android:core:1.4.1' implementation 'com.squareup.okhttp3:okhttp:3.4.1' implementation 'com.google.code.gson:gson:2.7' implementation 'com.github.bumptech.glide:glide:3.7.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } debug到这里就动不了![图片说明](https://img-ask.csdn.net/upload/201908/14/1565753464_912183.png)
android studio:使用get方式提交数据到服务器,android客户端失败,jsp成功
一个简单的login案例,提交数据到服务器模拟登录,以前用的AS2.2,现在升级到3.2.1就不行了。之前一直用的是API19,没什么问题,现在API28一堆 could not find class 'android.support.v4.....'的错误,没有抛异常, 查了一下说要把AVD的API升级到28,结果还是不行,变成了这样 ``` 2019-03-04 15:44:50.346 1958-1970/system_process E/memtrack: Couldn't load memtrack module 2019-03-04 15:44:52.836 1958-1979/system_process E/memtrack: Couldn't load memtrack module 2019-03-04 15:44:53.258 1707-2033/? E/installd: Failed to delete /data/app/vmdl152882847.tmp: No such file or directory 2019-03-04 15:44:54.883 1702-2407/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 2019-03-04 15:44:55.107 1702-2407/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 2019-03-04 15:44:56.920 1958-2127/system_process E/TaskPersister: File error accessing recents directory (directory doesn't exist?). 2019-03-04 15:45:13.157 1958-1979/system_process E/memtrack: Couldn't load memtrack module ``` 并没有抛异常,点击按钮提交数据毫无反应,代码和之前一毛一样,网上也没有找到什么靠谱的方法,但jsp正常,控制台能打印服务器接收到的数据,请问各位大神是什么原因?
《第一行代码》的酷欧天气,点开省列表以后显示的还是省,而不是城市,这是再点一下省就直接闪退
Logcat如下 FATAL EXCEPTION: main Process: com.coolweather.android, PID: 11807 java.lang.IndexOutOfBoundsException: Index: 6, Size: 0 at java.util.ArrayList.get(ArrayList.java:411) at com.coolweather.android.ChooseAreaFragment$1.onItemClick(ChooseAreaFragment.java:76) at android.widget.AdapterView.performItemClick(AdapterView.java:310) at android.widget.AbsListView.performItemClick(AbsListView.java:1165) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3137) at android.widget.AbsListView$3.run(AbsListView.java:4052) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6290) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 代码如下 package com.coolweather.android; import android.app.ProgressDialog; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.coolweather.android.db.City; import com.coolweather.android.db.County; import com.coolweather.android.db.Province; import com.coolweather.android.util.HttpUtil; import com.coolweather.android.util.Utility; import org.litepal.crud.DataSupport; import java.io.IOException; import java.util.ArrayList; import java.util.List; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by 王耀祖 on 2017/7/20. */ public class ChooseAreaFragment extends Fragment { public static final int LEVEL_PROVINCE = 0; public static final int LEVEL_CITY = 1; public static final int LEVEL_COUNTY = 2; private ProgressDialog progressDialog; private TextView titleText; private Button backButton; private ListView listView; private ArrayAdapter<String> adapter; private List<String> dataList = new ArrayList<>(); private List<Province> provinceList; private List<City> cityList; private List<County> countyList; private Province selectedProvince; private City selectedCity; private int currentLevel; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.choose_area, container, false); titleText = (TextView) view.findViewById(R.id.title_text); backButton = (Button) view.findViewById(R.id.back_button); listView = (ListView) view.findViewById(R.id.list_view); adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, dataList); listView.setAdapter(adapter); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (currentLevel == LEVEL_PROVINCE) { selectedProvince = provinceList.get(position); queryCities(); } else if (currentLevel == LEVEL_CITY) { selectedCity = cityList.get(position); queryCounties(); } } }); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(currentLevel==LEVEL_COUNTY){ queryCities(); } else if(currentLevel==LEVEL_CITY){ queryProvinces(); } } }); queryProvinces(); } private void queryProvinces(){ titleText.setText("中国"); backButton.setVisibility(View.GONE); provinceList= DataSupport.findAll(Province.class); if(provinceList.size()>0){ dataList.clear(); for(Province province:provinceList) dataList.add(province.getProvinceName()); adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel=LEVEL_PROVINCE; } else{ String address="http://guolin.tech/api/china"; queryFromServer(address,"province"); } } private void queryCities(){ titleText.setText(selectedProvince.getProvinceName()); backButton.setVisibility(View.VISIBLE); cityList=DataSupport.where("provinceid = ?",String.valueOf(selectedProvince .getId())).find(City.class); if(cityList.size()>0) { cityList.clear(); for(City city:cityList) dataList.add(city.getCityName()); adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel=LEVEL_CITY; } else{ int provinceCode=selectedProvince.getProvinceCode(); String address="http://guolin.tech/api/china/"+provinceCode; queryFromServer(address,"city"); } } private void queryCounties(){ titleText.setText(selectedCity.getCityName()); backButton.setVisibility(View.VISIBLE); countyList=DataSupport.where("cityid = ?",String.valueOf(selectedCity .getId())).find(County.class); if(countyList.size()>0) { countyList.clear(); for(County county:countyList) dataList.add(county.getCountyName()); adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel=LEVEL_COUNTY; } else{ int provinceCode=selectedProvince.getProvinceCode(); int cityCode=selectedCity.getCityCode(); String address="http://guolin.tech/api/china/"+provinceCode+"/"+cityCode; queryFromServer(address,"county"); } } private void queryFromServer(String address,final String type){ showProgressDialog(); HttpUtil.sendOkHttpRequest(address, new Callback() { @Override public void onFailure(Call call, IOException e) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { closeProgressDialog(); Toast.makeText(getContext(), "加载失败", Toast.LENGTH_SHORT).show(); } }); } @Override public void onResponse(Call call, Response response) throws IOException { String responseText=response.body().string(); boolean result=false; if("province".equals(type)) result= Utility.handleProvinceResponse(responseText); else if("city".equals(type)) result=Utility.handleCityResponse(responseText,selectedProvince.getId()); else if("county".equals(type)) result=Utility.handleCountyResponse(responseText,selectedCity.getId()); if(result){ getActivity().runOnUiThread(new Runnable() { @Override public void run() { closeProgressDialog(); if("province".equals(type)) queryProvinces(); else if("city".equals(type)) queryCities(); else if("county".equals(type)) queryCounties(); } }); } } }); } private void showProgressDialog(){ if(progressDialog==null){ progressDialog=new ProgressDialog(getActivity()); progressDialog.setMessage("正在加载。。。"); progressDialog.setCanceledOnTouchOutside(false); } progressDialog.show(); } private void closeProgressDialog(){ if(progressDialog!=null) progressDialog.dismiss(); } }
为啥这个Toast一直是显示的红色的
package com.example.a23734.myapplication; import cn.bmob.v3.Bmob; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.SaveListener; import android.app.Activity; import android.os.Bundle; import android.widget.Toast; import android.*; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bmob.initialize(this, "11c28913956ce3efb4ae4edffb0bce01"); Person p2 = new Person(); p2.setName("lucky"); p2.setAddress("北京海淀"); p2.save(new SaveListener<String>() { @Override public void done(String objectId,BmobException e) { if(e==null){ toast("添加数据成功,返回objectId为:"+objectId); }else{ toast("创建数据失败:" + e.getMessage()); } } }); } } ![图片说明](https://img-ask.csdn.net/upload/201709/23/1506154554_631759.png)
android ble蓝牙广播问题!!!!!!!!!!!!!!!!!!
使用ble蓝牙开发 在写入数据之后 设备返回的数据证明发送成功了 但是在广播中也会返回数据,我这边接收不到 使用别人的demo 可以接收到数据 这里有demo 哪位大哥帮忙看看代码有没有什么问题。 ``` package com.example.andysong.nuclearradiation.Ble; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCallback; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothProfile; import android.companion.BluetoothDeviceFilter; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import android.widget.Toast; import com.example.andysong.nuclearradiation.Ble.Adapter.MyAdapter; import com.example.andysong.nuclearradiation.Ble.BleTool.MyBluetoothDevice; import com.example.andysong.nuclearradiation.Ble.Entity.BleData; import com.example.andysong.nuclearradiation.R; import com.example.andysong.nuclearradiation.Uitl.Progess.DialProgress; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; public class BleActivityTest extends AppCompatActivity implements View.OnClickListener, MyAdapter.OnScan { private static final String TAG = BleActivityTest.class.getName(); private Button btn_scan; private Button btn_w; private RecyclerView rv_list; private MyAdapter myAdapter; private BluetoothAdapter bAdapter; private BluetoothGatt bluetoothGatt; private Map<String, UUID> uuidMap; //private UUID uNotify = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); //private UUID N_Notify = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb"); private UUID N_Notify = UUID.fromString("00001000-0000-1000-8000-00805f9b34fb"); //private UUID uNotify = UUID.fromString("0000ffe4-0000-1000-8000-00805f9b34fb"); private UUID uNotify = UUID.fromString("00001002-0000-1000-8000-00805f9b34fb"); //private UUID uRead = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); //private UUID uWrite = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); //private UUID N_Write = UUID.fromString("0000ffe5-0000-1000-8000-00805f9b34fb"); private UUID N_Write = UUID.fromString("00001000-0000-1000-8000-00805f9b34fb"); private static final UUID CLIENT_CHARACTERISTIC_CONFIG = UUID.fromString( "00002902-0000-1000-8000-00805f9b34fb"); //private UUID uWrite = UUID.fromString("0000ffe9-0000-1000-8000-00805f9b34fb"); private UUID uWrite = UUID.fromString("00001001-0000-1000-8000-00805f9b34fb"); private String READ = "read"; private String WRITE = "write"; private String NOTICE = "notice"; private Button btn_r; private Button btn_n; private Button btn_c; private DialProgress dialProgress; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ble); initView(); initData(); } private void initView() { btn_scan = findViewById(R.id.btn_scan); btn_w = findViewById(R.id.btn_w); btn_r = findViewById(R.id.btn_r); btn_n = findViewById(R.id.btn_n); btn_c = findViewById(R.id.btn_c); btn_scan.setOnClickListener(this); btn_w.setOnClickListener(this); btn_r.setOnClickListener(this); btn_n.setOnClickListener(this); btn_c.setOnClickListener(this); rv_list = findViewById(R.id.rv_list); rv_list.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL, false)); myAdapter = new MyAdapter(this); myAdapter.setOnScan(this); rv_list.setAdapter(myAdapter); dialProgress = findViewById(R.id.dialprog); } private void initData() { bAdapter = BluetoothAdapter.getDefaultAdapter(); uuidMap = new HashMap<>(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_scan: scan(); break; case R.id.btn_w: writeData(); break; case R.id.btn_r: readData(); break; case R.id.btn_n: notifyData(); break; case R.id.btn_c: closeNotifyData(); break; } } /*关闭广播通知*/ private void closeNotifyData() { BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Notify).getCharacteristic(uNotify); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); bluetoothGatt.writeDescriptor(descriptor); } /*打开广播通知*/ private void notifyData() { BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Notify).getCharacteristic(uNotify); boolean b = bluetoothGatt.setCharacteristicNotification(characteristic, true); int originalWriteType = characteristic.getWriteType(); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); boolean b1 = bluetoothGatt.writeDescriptor(descriptor); characteristic.setWriteType(originalWriteType); } /*read 读取数据 返回的数据需要在监听事件接收*/ private void readData() { if (bluetoothGatt == null) { return; } BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("00001000-0000-1000-8000-00805f9b34fb")). getCharacteristic(UUID.fromString("00001001-0000-1000-8000-00805f9b34fb")); bluetoothGatt.readCharacteristic(characteristic); } /*扫描设备*/ private void scan() { if (!bAdapter.isEnabled()) { Toast.makeText(this, "请打开蓝牙", Toast.LENGTH_SHORT).show(); return; } bAdapter.startLeScan(scanCallback); btn_scan.setText("扫描中"); btn_scan.setEnabled(false); } /*扫描到新的设备*/ private BluetoothAdapter.LeScanCallback scanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { MyBluetoothDevice bluetoothDevice = new MyBluetoothDevice(device, rssi); addDevice(bluetoothDevice); // Log.e(TAG, "onLeScan: " + device.getAddress() + device.getName()); if (device.getAddress().equals("F6:6D:83:80:D6:8D")) { conn(bluetoothDevice); } //F6:6D:83:80:D6:8D } }; /*添加扫描的新设备*/ private void addDevice(MyBluetoothDevice bluetoothDevice) { List<MyBluetoothDevice> devices = myAdapter.getDevices(); for (MyBluetoothDevice device : devices) { if (device.getDevice().getAddress().equals(bluetoothDevice.getDevice().getAddress())) { return; } } myAdapter.upDate(bluetoothDevice); } /*item点击链接的方法*/ @Override public void conn(MyBluetoothDevice device) { bluetoothGatt = device.getDevice().connectGatt(this, false, mBluetoothGattCallback); } /*写数据 数据不会直接返回 需要在监听事件中回调*/ public void writeData() { if (bluetoothGatt == null) { return; } // bluetoothGatt.readRemoteRssi(); BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Write).getCharacteristic(uWrite); //characteristic.setValue("E5015101003420"); characteristic.setValue("EF52FFFAFFFF"); //characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); bluetoothGatt.writeCharacteristic(characteristic); } /*链接状态—ready—write-*/ BluetoothGattCallback mBluetoothGattCallback = new BluetoothGattCallback() { //链接状态更改时 @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED) { gatt.discoverServices(); //查询支持的服务 bluetoothGatt = gatt; BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { btn_scan.setVisibility(View.GONE); btn_w.setVisibility(View.VISIBLE); btn_r.setVisibility(View.VISIBLE); btn_n.setVisibility(View.VISIBLE); btn_c.setVisibility(View.VISIBLE); } }); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { Log.e(TAG, "onConnectionStateChange: 断开"); BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { btn_scan.setEnabled(true); } }); } btn_scan.setText("扫描"); } //读取数据 @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicRead(gatt, characteristic, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "读取成功"); printALL(characteristic.getValue()); } else { Log.e(TAG, "读取失败"); } } //写出数据返回状态 @Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicWrite(gatt, characteristic, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onCharacteristicWrite发送成功"); printALL(characteristic.getValue()); } else { Log.e(TAG, "onCharacteristicWrite发送失败"); } } /*一般情况是 给设备发送指令使用应该*/ @Override public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { super.onDescriptorRead(gatt, descriptor, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onDescriptorRead读取成功"); printALL(descriptor.getValue()); } else { Log.e(TAG, "onDescriptorRead读取失败"); } } /*一般情况是 给设备发送指令使用应该*/ @Override public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { super.onDescriptorWrite(gatt, descriptor, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onDescriptorWrite发送成功"); printALL(descriptor.getValue()); } else { Log.e(TAG, "onDescriptorWrite发送失败"); } } /*接收通知 广播后 接收到的数据在这里*/ @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { //super.onCharacteristicChanged(gatt, characteristic); //bluetoothGatt = gatt; byte[] value = characteristic.getValue(); try { String s=new String(value,"UTF-8"); Log.e(TAG, "onCharacteristicChanged: "+s); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } printNotify(value); } //返回信号强度的 @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { super.onReadRemoteRssi(gatt, rssi, status); bluetoothGatt = gatt; Log.e(TAG, "onReadRemoteRssi: " + rssi); } //返回支持的服务滴 @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { super.onServicesDiscovered(gatt, status); bluetoothGatt = gatt; read(gatt); } }; public void read(BluetoothGatt gatt) { List<BluetoothGattService> services = gatt.getServices(); for (BluetoothGattService service : services) { Log.e(TAG, "服务: " + service.getUuid() + "-----"); List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic characteristic : characteristics) { if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) > 0) { uuidMap.put(READ, characteristic.getUuid()); Log.e(TAG, "读写属性: " + characteristic.getUuid()); for (BluetoothGattDescriptor bluetoothGattDescriptor:characteristic.getDescriptors()){ Log.e(TAG, "蓝牙描述符+++: " + bluetoothGattDescriptor.getUuid()); } } if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) { uuidMap.put(WRITE, characteristic.getUuid()); Log.e(TAG, "写属性: " + characteristic.getUuid()); } if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { uuidMap.put(NOTICE, characteristic.getUuid()); Log.e(TAG, "通知属性: " + characteristic.getUuid()); for (BluetoothGattDescriptor bluetoothGattDescriptor : characteristic.getDescriptors()) { Log.e(TAG, "蓝牙描述符: " + bluetoothGattDescriptor.getUuid()); } } } } Set<String> strings = uuidMap.keySet(); for (String key : strings) { UUID uuid = uuidMap.get(key); Log.e(TAG, "list: " + uuid.toString()); } } private void printALL(byte[] b) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; i++) { sb.append(Integer.toHexString(b[i]) + " "); } Log.e(TAG, "printALL--------: " + sb.toString()); } private void printALL2(final byte[] b) { Log.e(TAG, "printALL2--------: " + byteToString(b)); BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { dialProgress.setValue2(Double.parseDouble(formatString(byteToString(b)).getData())); } }); } private void printNotify(final byte[] b) { Log.e(TAG, "printNotify--------: " + byteToString(b)); BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { dialProgress.setValue2(Double.parseDouble(formatString(byteToString(b)).getData())); } }); } /*显示给客户*/ private String byteToString(byte[] b) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; i++) { String s = String.valueOf(b[i]).replace("-", ""); String s1 = Integer.toHexString(Integer.valueOf(s)); if (i == 0 || i == 1) { char c = asciiToChar(Integer.valueOf(s)); sb.append(c + " "); continue; } else if (s1.length() == 1) { sb.append("0" + s1 + " "); continue; } sb.append(s1 + " "); } return sb.toString(); } /*ascii 转 字符*/ private char asciiToChar(int a) { return (char) a; } /*代码用来计算的数据*/ private BleData formatString(String v) { String value = v.replace(" ", ""); String command = value.substring(0, 2); String date = value.substring(2, 8); String company = value.substring(8, 10); String d = value.substring(10, 18); StringBuffer data = new StringBuffer(); boolean flag = true; for (int i = 0; i < d.length(); i++) { if (i == 0) { continue; } if (i % 2 != 0) { if (flag) { data.append(Integer.valueOf(d.substring(0, i + 1)) + "."); flag = false; } else { data.append(Integer.valueOf(d.substring(i - 1, i + 1))); } } } String crc = value.substring(18, value.length()); return new BleData(command, date, company, data.toString(), crc); } }; ```
运行报FATAL EXCEPTION: main。
编写郭霖第一行代码和风天气 1.错误日志信息 ![图片说明](https://img-ask.csdn.net/upload/201905/11/1557552409_155464.png) 2.碎片布局后台代码 package com.example.coolweather; import android.app.Fragment; import android.app.ProgressDialog; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.example.coolweather.db.City; import com.example.coolweather.db.County; import com.example.coolweather.db.Province; import com.example.coolweather.util.HttpUtil; import com.example.coolweather.util.Utility; import org.litepal.crud.DataSupport; import java.io.IOException; import java.util.ArrayList; import java.util.List; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by Airth on 2019/5/10. */ public class ChooseAreaFragment extends Fragment { public static final int LEVEL_PROVINCE=0; public static final int LEVEL_CITY=1; public static final int LEVEL_COUNTY=2; private ProgressDialog progressDialog; private TextView titleText; private Button backButton; private ListView listView; private ArrayAdapter<String> adapter; private List<String> dataList = new ArrayList<>(); private int currentLevel; //当前被选中的级别 private Province selectedProvince;//被选中的省份 private City selectedCity;//被选中的城市 private List<Province> provinceList;//省列表 private List<City> cityList;//市列表 private List<County> countyList ;//县列表 /*获取控件实例id*/ @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Log.d("ChooseAreaFragment","onCreateView"); View view = inflater.inflate(R.layout.choose_area,container,false); titleText = (TextView)view.findViewById(R.id.title_text); //获取标题栏文本id backButton = (Button) view.findViewById(R.id.back_button); //获取标题栏id listView = (ListView)view.findViewById(R.id.list_view); //获取Item列表id //获取ArrayAdapter对象 adapter =new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, dataList); listView.setAdapter(adapter);//设置并初始化适配器 return view;//将视图返回 } /*点击事件集合*/ @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { Log.d("ChooseAreaFragment","onActivityCreated"); super.onActivityCreated(savedInstanceState); //列表任意一栏被点击,则... listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d("ChooseAreaFragment","列表被点了的..."); if (currentLevel == LEVEL_PROVINCE){ //当前选中的级别为省份时 selectedProvince = provinceList.get(position); //当前点击为选中状态 queryCities();//查询市的方法 } else if (currentLevel == LEVEL_CITY){ selectedCity = cityList.get(position); queryCounties(); } } }); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentLevel == LEVEL_COUNTY){ queryCities(); } else if (currentLevel == LEVEL_CITY){ queryProvinces(); } } }); queryProvinces(); } private void queryCities() { titleText.setText(selectedProvince.getProvinceName()); //设置市的标题内容 backButton.setVisibility(View.VISIBLE); //设置返回按钮可见 //查询被选中的省份城市的市区 cityList = DataSupport.where("provinceid=?",String.valueOf(selectedProvince. getId())).find(City.class); Log.d("ChooseAreaFragment","市级"); if (cityList.size()>0){ //如果省列表不为空,则... dataList.clear(); for (City city:cityList){ //遍历每一份省的市级城市 dataList.add(city.getCityName()); //添加到数据列表中 } adapter.notifyDataSetChanged();//通知适配器数据更新了 listView.setSelection(0); currentLevel = LEVEL_CITY; } else{ int provinceCode = selectedProvince.getProvinceCode(); //获取被选取省级代码 String address = "http://guolin.tech/api/china/"+provinceCode;//获取被选取地区的网络地址 Log.d("ChooseAreaFragment","准备在网络中获取地址信息"); queryFromServer(address,"city"); // 在网络中查询 } } /*根据传入的地址和类型从服务器查询省市县数据*/ private void queryFromServer(String adress, final String type) { showProgressDialog(); // 发送一条网络请求 HttpUtil.sendOKHttpRequest(adress, new Callback() { //请求加载失败 @Override public void onFailure(Call call, IOException e) { //通过runOnUiThread方法回到主线程逻辑 getActivity().runOnUiThread(new Runnable() { @Override public void run() { closeProgressDialog(); Toast.makeText(getContext(),"加载失败",Toast.LENGTH_SHORT).show(); } }); } @Override public void onResponse(Call call, Response response) throws IOException { Log.d("ChooseAreaFragment","加载地区信息..."); String responseText = response.body().string(); boolean result = false; if ("province".equals(type)){ result = Utility.handleProvinceResponse(responseText); } else if ("city".equals(type)){ result = Utility.handleCityResponse(responseText,selectedProvince.getId()); } else if ("county".equals(type)){ result = Utility.handleCountyResponse(responseText, selectedCity.getId()); } if (result) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Log.d("ChooseAreaFragment","开启线程更新UI"); closeProgressDialog(); if ("province".equals(type)){ queryProvinces(); } else if ("city".equals(type)){ queryCities(); } else if ("county".equals(type)){ queryCounties(); } } }); } if ("city".equals(type)){ result = Utility.handleProvinceResponse(responseText); } if ("county".equals(type)){ result = Utility.handleProvinceResponse(responseText); } } }); } /*显示进度对话框*/ private void showProgressDialog() { if (progressDialog==null){ progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("正在加载..."); progressDialog.setCanceledOnTouchOutside(false); } progressDialog.show(); } private void queryCounties() { titleText.setText(selectedCity.getCityName()); backButton.setVisibility(View.VISIBLE); countyList = DataSupport.where("cityid = ?", String.valueOf(selectedCity.getId())).find(County.class); if (countyList.size()>0){ dataList.clear(); for (County county:countyList){ dataList.add(county.getCountyName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel=LEVEL_COUNTY; } else { int provinceCode = selectedProvince.getProvinceCode(); int cityCode = selectedCity.getCityCode(); String address = "http://guolin.tech/api/china/"+provinceCode+"/"+cityCode; queryFromServer(address,"county"); } } /*全国所有的省,优先查询数据库,如果没有再去服务器查询*/ private void queryProvinces() { titleText.setText("中国"); Log.d("ChooseAreaFragment","查询省中..."); backButton.setVisibility(View.GONE); provinceList = DataSupport.findAll(Province.class); if (provinceList.size()>0){ dataList.clear(); for (Province province:provinceList){ dataList.add(province.getProvinceName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel = LEVEL_PROVINCE; } else { Log.d("ChooseAreaFragment","服务器查询省中..."); String address = "http://guolin.tech/api/china"; queryFromServer(address,"province"); } } private void closeProgressDialog() { if (progressDialog!=null){ progressDialog.dismiss(); } } }
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时想着能进去就不错了,管他哪个岗呢,就同意了面试...
开源一个功能完整的SpringBoot项目框架
福利来了,给大家带来一个福利。 最近想了解一下有关Spring Boot的开源项目,看了很多开源的框架,大多是一些demo或者是一个未成形的项目,基本功能都不完整,尤其是用户权限和菜单方面几乎没有完整的。 想到我之前做的框架,里面通用模块有:用户模块,权限模块,菜单模块,功能模块也齐全了,每一个功能都是完整的。 打算把这个框架分享出来,供大家使用和学习。 为什么用框架? 框架可以学习整体...
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
Spring Boot2 系列教程(十七)SpringBoot 整合 Swagger2
前后端分离后,维护接口文档基本上是必不可少的工作。 一个理想的状态是设计好后,接口文档发给前端和后端,大伙按照既定的规则各自开发,开发好了对接上了就可以上线了。当然这是一种非常理想的状态,实际开发中却很少遇到这样的情况,接口总是在不断的变化之中,有变化就要去维护,做过的小伙伴都知道这件事有多么头大!还好,有一些工具可以减轻我们的工作量,Swagger2 就是其中之一,至于其他类似功能但是却收费的软...
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
天天学JAVA-JAVA基础(6)
如果觉得我写的还行,请关注我的博客并且点个赞哟。本文主要介绍JAVA 中最常使用字符串常量String相关知识。 1.String简介 2.创建字符串对象两种方式的区别 3.String常用的方法 4.String的不可变性 5.一道阿里面试题,你会做吗? 1.String简介 1.1String源码 首先看一段String源码,String主要实现了Serializable、Compar...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
2020 网络课 智慧树自动刷课代码,自动跳转,自动答题并关闭弹窗,自动1.5倍速静音
刷课一时爽,一直刷课一直爽! 终于让我找到了这个黑客代码了,教程开始: 只限谷歌浏览器和火狐浏览器使用,如果第一次失败,请重新试一下次 将下面代码复制后,进入浏览器按F12键,先点击console 然后Ctrl+v复制代码 最后按回车键即可 var ti = $("body"); var video = $(".catalogue_ul1 li[id*=video-]"); var i = 1;...
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
一 说明 如果是初学者,建议去网上寻找安装Mysql的文章安装,以及使用navicat连接数据库,以后的示例基本是使用mysql数据库管理系统; 二 准备前提 需要建立一张学生表,列分别是id,名称,年龄,学生信息;本示例中文章篇幅原因SQL注释略; 建表语句: CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // dosho
致 Python 初学者
文章目录1. 前言2. 明确学习目标,不急于求成,不好高骛远3. 在开始学习 Python 之前,你需要做一些准备2.1 Python 的各种发行版2.2 安装 Python2.3 选择一款趁手的开发工具3. 习惯使用IDLE,这是学习python最好的方式4. 严格遵从编码规范5. 代码的运行、调试5. 模块管理5.1 同时安装了py2/py35.2 使用Anaconda,或者通过IDE来安装模
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
羞,Java 字符串拼接竟然有这么多姿势
二哥,我今年大二,看你分享的《阿里巴巴 Java 开发手册》上有一段内容说:“循环体内,拼接字符串最好使用 StringBuilder 的 append 方法,而不是 + 号操作符。”到底为什么啊,我平常一直就用的‘+’号操作符啊!二哥有空的时候能否写一篇文章分析一下呢? 就在昨天,一位叫小菜的读者微信我说了上面这段话。 我当时看到这条微信的第一感觉是:小菜你也太菜了吧,这都不知道为啥啊!我估...
写1行代码影响1000000000人,这是个什么项目?
不带钱不带卡,只带手机出门就能畅行无阻,这已是生活的常态。益普索发布的《2019第一季度第三方移动支付用户研究》报告显示,移动支付在手机网民中的渗透率高达95.1%,截至今年1月,支付宝全球用户数已经突破10亿。你或许每天都会打开支付宝,付款购物、领取权益、享受服务……但你或许不知道的是,在这个方便、快捷、智能化的APP背后,有一群年轻的技术人,用智慧和创新让它每天都变得更“聪明”一点。 ...
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
一点一滴记录 Java 8 stream 的使用
日常用到,一点一滴记录,不断丰富,知识积累,塑造自身价值。欢迎收藏 String 转 List String str = 1,2,3,4; List&lt;Long&gt; lists = Arrays.stream(str.split(",")).map(s -&gt; Long.parseLong(s.trim())).collect(Collectors.toList()); Lis...
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
相关热词 c#处理浮点数 c# 生成字母数字随机数 c# 动态曲线 控件 c# oracle 开发 c#选择字体大小的控件 c# usb 批量传输 c#10进制转8进制 c#转base64 c# 科学计算 c#下拉列表获取串口
立即提问