小编Gay*_*nda的帖子

Butterknife中的@OnClick方法使用java.lang.BootstrapMethodError使应用程序崩溃

Butterknife用来简化我的代码。我有一个TextViewactivity_main.xml file。我想通过单击此按钮来显示吐司,TextView 但是当我使用库中的@OnClick注释时,Butterknife我的应用程序崩溃了

MainActivity.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.clickme) void clicked() {
        Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_SHORT).show();
    }
Run Code Online (Sandbox Code Playgroud)

activity_main.xml

<TextView
        android:id="@+id/clickme"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="click me"/>
Run Code Online (Sandbox Code Playgroud)

通常,它应该显示一个吐司,但是应用程序崩溃并显示以下堆栈跟踪信息。

2019-01-02 15:26:42.617 3909-3909/com.realestate.app.realestate E/AndroidRuntime: FATAL EXCEPTION: main
**Process: com.realestate.app.realestate, PID: 3909
java.lang.BootstrapMethodError: Exception from call site #1 bootstrap method
    at butterknife.internal.DebouncingOnClickListener.<clinit>(DebouncingOnClickListener.java:12)
    at com.realestate.app.realestate.realestate.MainActivity_ViewBinding.<init>(MainActivity_ViewBinding.java:34)**
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at butterknife.ButterKnife.bind(ButterKnife.java:171)
    at butterknife.ButterKnife.bind(ButterKnife.java:100)
    at com.realestate.app.realestate.realestate.MainActivity.onCreate(MainActivity.java:25)
    at android.app.Activity.performCreate(Activity.java:7136)
    at android.app.Activity.performCreate(Activity.java:7127)
    at …
Run Code Online (Sandbox Code Playgroud)

java android butterknife

6
推荐指数
2
解决办法
1998
查看次数

原因:java.lang.ClassNotFoundException:在路径:DexPathList [[zip文件]中找不到类“ android.support.v4.animation.AnimatorCompatHelper”

尝试在android的回收器视图中删除元素时出现以下错误。

Caused by: java.lang.ClassNotFoundException: Didn't find class 
          "android.support.v4.animation.AnimatorCompatHelper" on path: DexPathList[[zip file
Run Code Online (Sandbox Code Playgroud)

尽管该元素已被删除,但应用程序崩溃了。请告诉我是否需要更改应用程序gradle文件或构建gradle文件。请帮帮我。

完整的异常跟踪:06-11 12:42:07.867 29844-29844 / com.application.aayush.geeta E / AndroidRuntime:致命例外:主进程:com.application.aayush.geeta,PID:29844 java.lang.NoClassDefFoundError:无法解决以下问题:Landroid / support / v4 / animation / AnimatorCompatHelper;在android.support.v7.widget.DefaultItemAnimator.animateRemove(DefaultItemAnimator.java:android.support.v7.widget.DefaultItemAnimator.resetAnimation(DefaultItemAnimator.java:515)上

另外,当我尝试调试时,出现以下错误:

Error:Execution failed for task ':app:lint'.
Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script 
to proceed with errors:
...
android {
    lintOptions {
       abortOnError false
   }
}
...
Run Code Online (Sandbox Code Playgroud)

java android

5
推荐指数
1
解决办法
2372
查看次数

gson.toJson 声明多个名为 XX 的 JSON 字段

我有一个 A 类型的自定义对象和一个包含 B 类型的自定义对象的 ArrayList,我想将它们存储在与 gson 的共享首选项中。对象 A 工作没有问题,但当我尝试存储对象 B 的列表甚至只是 B 的一个实例时,会出现以下错误消息:

\n\n
2019-01-07 13:05:21.610 28295-28295/com.example.aev.quizzle E/AndroidRuntime: FATAL EXCEPTION: main\nProcess: com.example.aev.quizzle, PID: 28295\njava.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aev.quizzle/com.example.aev.quizzle.activities.MapsActivity}: java.lang.IllegalArgumentException: class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations\n    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)\n    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)\n    at android.app.ActivityThread.-wrap12(Unknown Source:0)\n    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)\n    at android.os.Handler.dispatchMessage(Handler.java:108)\n    at android.os.Looper.loop(Looper.java:166)\n    at android.app.ActivityThread.main(ActivityThread.java:7425)\n    at java.lang.reflect.Method.invoke(Native Method)\n    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)\n    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)\n Caused by: java.lang.IllegalArgumentException: class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations\n    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172)\n    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)\n    at com.google.gson.Gson.getAdapter(Gson.java:458)\n    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)\n …
Run Code Online (Sandbox Code Playgroud)

java android gson

5
推荐指数
1
解决办法
7720
查看次数

LinearLayoutManager 不能在 Fragment 中使用

我有一个错误LinearLayoutManager,当我运行这段代码时,它说

error: incompatible types: NotificationFragment cannot be converted to Context
Run Code Online (Sandbox Code Playgroud)

这是我的代码 NotificationFragment.java

public class NotificationFragment extends Fragment {

    private RecyclerView recyclerView;
    private NotificationAdapter adapter;
    private ArrayList<NotificationModel> notificationModelArrayList;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_notification,container,false);

        addData();

        recyclerView = (RecyclerView)   getView().findViewById(R.id.recycler_view);

        adapter = new NotificationAdapter(notificationModelArrayList);

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(NotificationFragment.this);

        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setAdapter(adapter);
    }

    void addData(){
        notificationModelArrayList = new ArrayList<>();
        notificationModelArrayList.add(new NotificationModel("Event 1", "1 January 2019", "Surabaya"));
        notificationModelArrayList.add(new NotificationModel("Event 2", "1 January 2019", …
Run Code Online (Sandbox Code Playgroud)

java android-studio

4
推荐指数
1
解决办法
5696
查看次数

找不到非具体 Map 类型的反序列化器 [map type; 类 com.google.common.collect.ImmutableMap

我使用 java 作为后端,从 UI 发送的请求JSON格式如下所示。

{"name":"Music"}
Run Code Online (Sandbox Code Playgroud)

下面是java代码。

@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE},produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
    public Category insertCategory(@RequestBody Category category) {
        // TODO Auto-generated method stub
        System.out.println("entity:" +category.getName());
        CategoryServiceImpl impl = new CategoryServiceImpl();
        Category res = impl.insertCategory(category);
        return res;
    }
Run Code Online (Sandbox Code Playgroud)

返回到 UI 的响应应该是json这样,我使用了生产方式,MediaType.APPLICATION_JSON_VALUE如您所见。

请求正文还将json数据绑定到 Category 模型对象,但这是我收到反序列化错误的地方(错误日志如下所示)。

类别模型如下所示。

public class Category extends Entity {
    private ImmutableMap<String,Category> childCategories;

    public ImmutableMap<String, Category> getChildCategories() {
        return childCategories;
    }
    public void setCategories(Map<String,Category> categories) {
        ImmutableMap.Builder<String, Category> builder = …
Run Code Online (Sandbox Code Playgroud)

java rest json

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

播放结算库v1.0过期订阅

Play Billing Library v1.0用于我的一个Android应用程序订阅.

if (billingResponse == BillingClient.BillingResponse.OK) {
    Purchase.PurchasesResult result = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);
    if (result.getPurchasesList().size() > 0) {
        if (result.getPurchasesList().get(0).getSku().equals(constant.sku_subscription_weekly)) {
            premium= 2;
        }
Run Code Online (Sandbox Code Playgroud)

我正在上面得到sku并在启动画面上根据它提供好处.我怀疑如果会员资格到期将会发生什么?它还会返回sku吗?我试图测试使用测试者帐户,如果我们取消它不会返回sku,但我不确定真正的购买,没有任何方法在7天以下测试真实购买我不想等待7天测试,有人可以请你确认一下吗?

java android in-app-purchase in-app-billing google-play

2
推荐指数
1
解决办法
165
查看次数

如果在if条件下使用,则hashmap的isEmpty()和size()之间有什么区别?

我必须处理NullPointerException正在发生的情况Hashmap。我应该在条件内使用map.isEmpty()或(map.size() > 0if吗?

哪一个更好?

java

1
推荐指数
2
解决办法
233
查看次数

将java项目转换为maven时pom文件出错

我正在将java项目转换为maven.

我添加了这些依赖项

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Tippreports</groupId>
    <artifactId>Tippreports</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.8.0</version>
                        <type>maven-plugin</type>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-server</artifactId>
                        <version>3.141.5</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.testng</groupId>
                        <artifactId>testng</artifactId>
                        <version>6.14.3</version>
                        <scope>test</scope>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M1</version>
                        <type>maven-plugin</type>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

添加依赖项后,我无法以Maven安装或构建的方式运行

错误是

Error resolving version for plugin 'org.apache.maven.plugins:null' 
from the repositories [local (C:\Users\rck\.m2\repository),
central (http://repo.maven.apache.org/maven2)]:
Plugin not found in any plugin repository
Run Code Online (Sandbox Code Playgroud)

我应该在上面指定的位置创建一个文件夹,还是需要更改位置?

java maven

0
推荐指数
1
解决办法
177
查看次数

我可以在JAVA中使用"默认"变量吗?

我正在进行IntelliJ上的Spring项目.

我正在使用gson进行json解析,但是我在创建解析类时遇到了麻烦.

在youtube api中,与searchlist相关的json键值有一个称为"默认"变量的问题.

import java.util.Map;

public class Thumbnails {
    *// Map<String, String> default;*
    Map<String, String> medium;
    Map<String, String> high;

}
Run Code Online (Sandbox Code Playgroud)

除"默认"变量外,当前类与上述类相同.

我想知道是否可以使用"default"作为变量值,或者是否可以在执行gson.fromJson ()方法时将json键值解析为其他变量值.

PS附加JSON响应.

 "thumbnails": {
     "default": {
         "url": "https://i.ytimg.com/vi/video-id/default.jpg",
         "width": 120,
         "height": 90
     },
     "medium": {
         "url": "https://i.ytimg.com/vi/video-id/mqdefault.jpg",
         "width": 320,
         "height": 180
     },
     "high": {
         "url": "https://i.ytimg.com/vi/video-id/hqdefault.jpg",
         "width": 480,
         "height": 360
     }
 },
Run Code Online (Sandbox Code Playgroud)

java json gson

0
推荐指数
1
解决办法
81
查看次数