我Butterknife
用来简化我的代码。我有一个TextView
在activity_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) 尝试在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) 我有一个 A 类型的自定义对象和一个包含 B 类型的自定义对象的 ArrayList,我想将它们存储在与 gson 的共享首选项中。对象 A 工作没有问题,但当我尝试存储对象 B 的列表甚至只是 B 的一个实例时,会出现以下错误消息:
\n\n2019-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) 我有一个错误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 作为后端,从 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) 我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天测试,有人可以请你确认一下吗?
我必须处理NullPointerException
正在发生的情况Hashmap
。我应该在条件内使用map.isEmpty()
或(map.size() > 0
)if
吗?
哪一个更好?
我正在将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)
我应该在上面指定的位置创建一个文件夹,还是需要更改位置?
我正在进行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)