Posts List

java.net.BindException Address already in use bind 错误

运行Java项目时,遇到了这个报错 该错误是端口号被占用,查看你项目的端口号 application.properties —> server.port=8088 然后控制栏输入 netstat -ano 然后去任务管理器处,找到 pid=3216 的进程,kill它。 重新运行你的项目,完成。

栈和队列基础题

1,设计一个有getMin功能的栈 题目:实现一个特殊的栈,在实现栈的基本功能的基础上,再实现返回栈中的最小值 要求: 1,pop、push、getMin操作的时间复杂度都是O(1) 2,设计的栈类型可以使用现成的栈的结构 public class Stack1 { private Stack<Integer> stackMin; private Stack<Integer> stackData; public Stack1(){ stackMin=new Stack<>(); stackData=new Stack<>(); } public int getMin(){ if(stackMin.isEmpty()){ throw new RuntimeException("stack is null"); } return stackMin.peek(); } //方案一 //节省空间,pop步骤多 public void push(int newNum){ if(stackMin.isEmpty()){ stackMin.push(newNum); }else{ if(getMin()<=newNum){ stackMin.push(newNum); } } stackData.push(newNum); } public int pop(){ if(stackData.isEmpty()){ throw new RuntimeException("stack is null"); } int value=stackData.pop(); if(value==getMin()){ stackMin.pop(); } return value; } //-------------------------- //方案2 //比方案1多费空间,但省时间 public void push2(int newNum){ if(stackMin.

Java 反射与 open-sdk 来使用 Android hide 方法

一直有个问题,就是清除非本APP 连接的wifi保存的密码,很想像Android系统那样可以直接在WIFI设置那里直接取消保存,于是做了以下尝试。 是在sdk 19以上哦,19以下(包括)是可以直接清除的。 清除wifi密码比较通常的用法是: WifiManager mWifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE); mWifiManager.removeNetwork(config.networkId); mWifiManager.saveConfiguration(); 这样可以清除掉本来是你这个APP连接的WIFI,意思是这个WIFI是别人连接上的你是不能清除掉的。 目前也没有看到其他三方App能够做到这样。 于是开始寻找其他方法。 然后看到了 WifiManager 的这个方法 froget(看起来好像很有希望哦): 说的是替代 removeNetwork 和 saveConfiguration 方法,可是这是hide的,我们显式是调用不了的。 那先试试反射吧。 首先去拿到WifiManager: Class<?> clazz = null; try { clazz = Class.forName("android.net.wifi.WifiManager"); } catch (ClassNotFoundException e) { e.printStackTrace(); KLog.e(e); } 然后构造forget方法: Class<?> actionListener = null; try { actionListener = Class.forName("android.net.wifi.WifiManager$ActionListener"); } catch (ClassNotFoundException e) { e.printStackTrace(); KLog.e(e); } KLog.e("actionListener:" + actionListener); Method method = null; try { method = clazz.