小编Jim*_*ins的帖子

什么是调暗屏幕的正确方法?

到目前为止,我在搜索中看到了两种方法,这两种方法都遇到了麻烦.

方法1)

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100);
Run Code Online (Sandbox Code Playgroud)

方法2)

IHardwareService hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware"));
hardware.setScreenBacklight(.5);
Run Code Online (Sandbox Code Playgroud)

以下哪种方法是正确的?还是我应该使用另一个?

谢谢

android

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

Android和GSON抛出No-Args构造函数未找到异常

我的Android应用程序中存在GSON问题.

JSON输入

[
    {"id":"1202","parent_id":"0","agrpcount":"0","disp_order":"1","code":"PROD-NEW","name":"New Products","active":"1"},
    {"id":"1119","parent_id":"0","agrpcount":"0","disp_order":"2","code":"PROD-VID","name":"\\\"How To\\\" Videos","active":"1"},
    {"id":"1685","parent_id":"0","agrpcount":"0","disp_order":"3","code":"SUPP-RESOUR","name":"Support Resources","active":"1"},
    {"id":"49","parent_id":"0","agrpcount":"0","disp_order":"109","code":"EQ","name":"Equipment for Sign Making","active":"1"},
    {"id":"22","parent_id":"0","agrpcount":"0","disp_order":"110","code":"application-tape","name":"Application Tapes","active":"1"}
]
Run Code Online (Sandbox Code Playgroud)

每个数组项的容器类

public class Category {
    public int id;
    public int parent_id;
    public int agrpcount;
    public int disp_order;
    public String code;
    public String name;
    public int active;
}
Run Code Online (Sandbox Code Playgroud)

要加载类别数组的类

public static List<Category> getCategories(){
    Category[] cats;

    Gson gson = new Gson();

    cats = gson.fromJson(strJSON, Category[].class);

    List<Category> CatsList = Arrays.asList(cats);
    return CatsList;
}
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我在日志中得到以下内容

02-28 15:15:42.471: ERROR/AndroidRuntime(777): Caused by: java.lang.RuntimeException: No-args constructor for class com.signwarehouse.catalog.SWService$Category does …
Run Code Online (Sandbox Code Playgroud)

java android json gson

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

标签 统计

android ×2

gson ×1

java ×1

json ×1