package com.example.bs.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Maintenance extends AppCompatActivity {
private static final String PRODUCT_URL = "http://192.XXXXXXX/MyApi/api.php";
RecyclerView recyclerView;
ProductAdapter adapter;
List<Product> productList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maintenance);
productList = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
loadProducts ();
}
private void loadProducts () {
StringRequest stringRequest = new StringRequest(Request.Method.GET, PRODUCT_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray products =new JSONArray(response);
for (int i = 0; i<products.length(); i++){
JSONObject productObject = products.getJSONObject(i);
int maintenance_id = productObject.getInt("maintenance_id");
String type = productObject.getString("type");
String property = productObject.getString("property");
String more_info = productObject.getString("more_info");
Double date = productObject.getDouble("date");
Product product = new Product(maintenance_id, type, property, more_info, date);
productList.add(product);
}
adapter = new ProductAdapter(Maintenance.this, productList);
recyclerView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Maintenance.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
Volley.newRequestQueue(this).add(stringRequest);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.benchalmers.myapplication.Maintenance">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
logcat
02-06 12:11:42.195 4155-4155/? I/zygote: Not late-enabling -Xcheck:jni (already on)
02-06 12:11:42.409 4155-4155/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
02-06 12:11:43.494 4155-4155/com.example.bs.myapplication I/InstantRun: starting instant run server: is main process
02-06 12:11:43.665 4155-4155/com.example.bs.myapplication D/AndroidRuntime: Shutting down VM
02-06 12:11:43.671 4155-4155/com.example.bs.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bs.myapplication, PID: 4155
java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/com.example.bs.myapplication-EpCz2N67lH5I_Aiqfiskfg==/split_lib_dependencies_apk.apk)
at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:81)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:67)
at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753)
at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)
at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)
at android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621)
at android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.bs.myapplication.Maintenance.onCreate(Maintenance.java:34)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
适配器类
package com.example.benchalmers.myapplication;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ProductViewHolder> {
private Context mCtx;
private List<Product> productList;
public ProductAdapter(Context mCtx, List<Product> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.list_layout, null);
return new ProductViewHolder(view);
}
@Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
Product product = productList.get(position);
holder.textViewType.setText(product.getType());
holder.textViewProperty.setText(product.getProperty());
holder.textViewMoreInfo.setText(String.valueOf(product.getMoreInfo()));
holder.textViewDate.setText(String.valueOf(product.getDate()));
//holder.imageView.setImageDrawable(mCtx.getResources().getDrawable(product.getImage()));
}
@Override
public int getItemCount() {
return productList.size();
}
class ProductViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
TextView textViewType, textViewProperty, textViewMoreInfo, textViewDate;
public ProductViewHolder(View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.imageView);
textViewType = itemView.findViewById(R.id.textViewType);
textViewProperty = itemView.findViewById(R.id.textViewProperty);
textViewMoreInfo = itemView.findViewById(R.id.textViewMoreInfo);
textViewDate = itemView.findViewById(R.id.textViewDate);
}
}
}
您应该迁移到26.0.0或更高版本的支持v7库。
这是appcompat库中的问题,在此提及
https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0
ResourcesCompat.getFont()引发异常
您应该在所有与Android相关的依赖项中使用相同的版本,这是一个最佳实践
您可以使用以下方法检查appcompat依赖项
./gradlew :app:dependencyInsight --dependency com.android.support:appcompat --configuration debugCompileClasspath
我正在尝试使用在Flutter上,它在Android模拟器上运行完美。但是当我尝试在我的真实设备上使用它时,当我点击按钮打开相机时,它崩溃了,没有给出任何错误。我该如何解决它?我的手机是Android(小米8)。 我的代码:
问题内容: 所以这是我的问题。我正在使用Jquery的$ .ajax将一系列值传递回Web方法。Web方法获取值,创建一个对象,然后将其作为json发送回调用页面。收到响应后,我将无法访问响应并显示其值。 谁能解释我需要做些什么才能完成这项工作? jQuery脚本: 网络方法: 我得到的答复是: 这就是我应该回去的东西: 页面再次呈现后出现的错误是: 问题答案: 您的响应已经被解析为JSON,因此
我有,它有分页,当我滚动一些时候,它正在崩溃。当我慢慢滚动时,它没有崩溃。我已经提供了适配器和活动代码。请让我知道我在这里做错了什么。我已经搜索了相同的问题,但无法在此处捕获错误。 显示某些错误(日志):
我做了一个SAX解析器,它接受输入流作为文件进行解析。如果我使用本地文件,它可以工作,但如果我试图从internet获取它,当它打开输入流时就会崩溃。 这里有代码: 我已经尝试了几种方法,我在其他问题中看到过,它总是在或类似的地方崩溃。 提前道谢。
我正在工作的应用程序中,我被要求显示通知。对于通知,我使用的是FireBase云消息(FCM)。我能够得到通知,当应用程序在后台。 2.)MyFirebaseInstanceIDService 这是我在MyFirebaseMessagingService类中为onMessageReceived()方法编写的代码示例。
我还发现: