BA中的错误手札

adb

adb: command not found的时候,安装adb

try...catch

try 语句提供一种机制,用于捕捉在块的执行期间发生的各种异常。在try语句中定义的变量就是只能在try语句中使用
用得好:用户友好性
用得不好:隐藏Bug,未解决根本问题!

Google API in Android-Developer

Google API在Android Studio

implement和import之间

import的是包,
implements的是接口
别弄错了!

Android项目包的命名习惯

com.example.app.activity Activity 类
com.example.app.widget 自定义的小UI
com.example.app.db 数据库相关操作
com.example.app.bean 实体
com.example.app.engine 存放业务层,因为service冲突
com.example.app.service 服务
com.example.app.util 工具类
com.example.app.constant 常量包类
com.example.app.adapter 适配器类
com.example.app.receiver 广播接收器
com.example.app.listener 监听器
com.example.app.模块名称.api 第三方模块包

自动生成Setter/Getter

Code -> generate -> 选择你要的 -> 确定


BA中的错误手札_第1张图片
generate选项

new一个对象 vs 类名.getInstance()

new一个新对象包括两步:
-> 加载类
-> 实例化

类名.getInstance()
-> 就是实例化,不一定要新建对象(比如我只想调用某类中的int类型的方法,那我就用int i=类名.getInstance().方法名())

final

final是java中的一个关键字,可以用来修饰变量、方法、类和域。
-> final变量:一旦赋值就不能改变,也称为常量。
-> final类:这个类不能被继承

Activity.findViewById( ) vs View.findViewById( ) vs findViewByTag( )

转载自这里

Tag在监听事件里面的使用

转载自这里

Serializable - Wrong 2nd argument!

程序有建立一个实体类Plant.class,这里报错,说对象无法序列化!

BA中的错误手札_第2张图片
ERROR

解决方法:
在Plant这个类中继承Serializable接口 Class Plant implements Serializable 即可解决

你可能感兴趣的:(BA中的错误手札)