当我单击按钮时,出现此错误:我试图从电话中提取联系信息。我认为依赖项中的glide实现似乎存在错误。
请帮助我知道出了什么问题。我尝试更改实现,但随后又出现其他错误。
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cis436.ewalletprototype, PID: 25986
java.lang.NoSuchMethodError: No virtual method load(Ljava/lang/String;)Lcom/bumptech/glide/DrawableTypeRequest; in class Lcom/bumptech/glide/RequestManager; or its super classes (declaration of 'com.bumptech.glide.RequestManager' appears in /data/app/com.cis436.ewalletprototype-yE9uAio8CRZs0Gr1-2uFaQ==/base.apk:classes10.dex)
at jagerfield.app.ContactList.ListFragment.ContactListFragment$ContactListViewAdapter.onBindViewHolder(ContactListFragment.java:107)
at jagerfield.app.ContactList.ListFragment.ContactListFragment$ContactListViewAdapter.onBindViewHolder(ContactListFragment.java:81)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:944)
at android.view.View.layout(View.java:20822)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2948)
E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2635)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1779)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7810)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Application terminated.
ContactListFragment.java
package jagerfield.app.ContactList.ListFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import jagerfield.app.R;
import jagerfield.mobilecontactslibrary.Contact.Contact;
import jagerfield.app.ContactView.DisplayContactActivity;
import jagerfield.app.Utilities.C;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import jagerfield.mobilecontactslibrary.ImportContactsAsync;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
public class ContactListFragment extends Fragment
{
private ContactListFragment contactListFragment;
private RecyclerView recyclerView;
public ContactListFragment()
{}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_contact_list, container, false);
if (view instanceof RecyclerView)
{
Context context = view.getContext();
recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(context));
contactListFragment = this;
new ImportContactsAsync(getActivity(), new ImportContactsAsync.ICallback()
{
@Override
public void mobileContacts(ArrayList<Contact> contactList)
{
ArrayList<Contact> listItem = contactList;
if(listItem==null)
{
listItem = new ArrayList<Contact>() ;
Log.i(C.TAG_LIB, "Error in retrieving contacts");
}
if(listItem.isEmpty())
{
Toast.makeText(getActivity(), "No contacts found", Toast.LENGTH_LONG).show();
}
recyclerView.setAdapter(new ContactListViewAdapter(contactListFragment, listItem));
}
}).execute();
}
return view;
}
/**
* Fragment Contact List Adapter
*/
private class ContactListViewAdapter extends RecyclerView.Adapter<ContactListViewAdapter.ViewHolder>
{
private ContactListFragment fragment;
private Context context;
private ArrayList<Contact> contactList = new ArrayList<>();
public ContactListViewAdapter(ContactListFragment fragment, ArrayList<Contact> contactList) {
this.fragment = fragment;
context = fragment.getActivity();
this.contactList = contactList;
}
@Override
public ContactListViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_contact_list_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ContactListViewAdapter.ViewHolder holder, final int position) {
holder.vhContact = contactList.get(position);
holder.name.setText(holder.vhContact.getFirstName() + " " + holder.vhContact.getLastName());
String imageUri = contactList.get(position).getPhotoUri();
Glide.with(context)
.load(imageUri)
.error(R.drawable.person)
.bitmapTransform(new CropCircleTransformation(context))
.into(holder.image);
holder.mView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (contactList ==null )
{
return;
}
Intent i = new Intent(context, DisplayContactActivity.class);
GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
Gson gsonBuilder = builder.create();
String jsonContact = gsonBuilder.toJson(contactList.get(position));
i.putExtra(C.CONTACT, jsonContact);
context.startActivity(i);
}
});
}
@Override
public int getItemCount() {
return contactList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final TextView name;
public final ImageView image;
public Contact vhContact;
public ViewHolder(View view) {
super(view);
mView = view;
name = (TextView) view.findViewById(R.id.tv_name);
image = (ImageView) view.findViewById(R.id.iv_contact_Image);
}
}
}
}
DisplayContactActivity.java
package jagerfield.app.ContactView;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.palette.graphics.Palette;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import jagerfield.app.R;
import jagerfield.mobilecontactslibrary.ElementContainers.AddressContainer;
import jagerfield.mobilecontactslibrary.ElementContainers.EmailContainer;
import jagerfield.mobilecontactslibrary.ElementContainers.EventContainer;
import jagerfield.mobilecontactslibrary.ElementContainers.NoteContainer;
import jagerfield.mobilecontactslibrary.ElementContainers.NumberContainer;
import jagerfield.mobilecontactslibrary.ElementContainers.WebsiteContainer;
import jagerfield.mobilecontactslibrary.Contact.Contact;
import jagerfield.app.ContactView.FieldAdapters.NumberViewAdapter;
import jagerfield.app.ContactView.FieldAdapters.AddressViewAdapter;
import jagerfield.app.ContactView.FieldAdapters.EmailViewAdapter;
import jagerfield.app.ContactView.FieldAdapters.EventViewAdaptor;
import jagerfield.app.ContactView.FieldAdapters.NoteViewAdaptor;
import jagerfield.app.ContactView.FieldAdapters.WebsiteViewAdaptor;
import jagerfield.app.Utilities.C;
import com.google.android.material.appbar.AppBarLayout;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.LinkedList;
public class DisplayContactActivity extends AppCompatActivity {
private ImageView ivName;
private ImageView ivNumber;
private ImageView ivAddress;
private ImageView ivEmail;
private ImageView ivWebsite;
private ImageView ivNote;
private ImageView ivEvent;
private Toolbar toolbar;
private AppBarLayout appBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_contact);
toolbar =(Toolbar) findViewById(R.id.toolbar);
appBar = (AppBarLayout) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Contact contact = getArguments();
loadContactImage(contact.getPhotoUri());
loadNamesField(contact);
loadNumbersField(contact);
loadAddressField(contact);
loadEmailField(contact);
loadWebsiteField(contact);
loadEventField(contact);
loadNoteField(contact);
}
private void loadContactImage(String imageDir)
{
final ImageView imageView = (ImageView) findViewById(R.id.contactImage);
bindfieldIcons();
/**
* The material Palette.Swatch extracts six different color shades from the image for
* coloring the icons and titles.
* To get the palette colors, the image has t be a bitmap. Use Glide to generate the bitmap
* and when it is ready extract the colors.
*
*/
Glide
.with(getApplicationContext())
.load(imageDir)
.asBitmap()
.into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
imageView.setImageBitmap(resource);
Palette.Swatch color = C.getImageColor(C.VIBRANT, resource);
if (color!=null)
{
/**
* Recolor the icons
*/
recolorFieldIcons(color);
}
}
});
}
private void recolorFieldIcons(Palette.Swatch color)
{
ivName.setColorFilter(color.getRgb());
ivNumber.setColorFilter(color.getRgb());
ivAddress.setColorFilter(color.getRgb());
ivEmail.setColorFilter(color.getRgb());
ivWebsite.setColorFilter(color.getRgb());
ivNote.setColorFilter(color.getRgb());
ivEvent.setColorFilter(color.getRgb());
}
private void bindfieldIcons() {
ivName = (ImageView) findViewById(R.id.ivName);
ivNumber = (ImageView) findViewById(R.id.ivNumber);
ivAddress = (ImageView) findViewById(R.id.ivAddress);
ivEmail = (ImageView) findViewById(R.id.ivEmail);
ivWebsite = (ImageView) findViewById(R.id.ivWebsite);
ivNote = (ImageView) findViewById(R.id.ivNote);
ivEvent = (ImageView) findViewById(R.id.ivEvent);
}
private Contact getArguments() {
GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
Gson gsonBuilder = builder.create();
String gsonListString = getIntent().getStringExtra(C.CONTACT);
Contact contact = gsonBuilder.fromJson(gsonListString, Contact.class);
return contact;
}
private void loadNamesField(Contact contact)
{
if (contact == null) {
return;
}
TextView displayedName = (TextView) findViewById(R.id.tvValue_1);
TextView firstName = (TextView) findViewById(R.id.tvValue_2);
TextView lastName = (TextView) findViewById(R.id.tvValue_3);
/**
* If a name is missing then hide it
*/
setViewState(displayedName, contact.getDisplaydName());
boolean fName = setViewState(firstName, contact.getFirstName());
boolean lName = setViewState(lastName, contact.getLastName());
StringBuilder title = new StringBuilder();
if(fName) {title.append(contact.getFirstName() + " ");}
if(lName) {title.append(contact.getLastName());}
/**
* Set activity's title to show contact first and last names
*/
getSupportActionBar().setTitle(title.toString().trim());
displayedName.setText(contact.getDisplaydName());
firstName.setText(contact.getFirstName());
lastName.setText(contact.getLastName());
}
private boolean setViewState(TextView tv, String value)
{
if (value.trim().isEmpty())
{
tv.setVisibility(View.GONE);
return false;
}
else
{
tv.setVisibility(View.VISIBLE);
return true;
}
}
private void loadNumbersField(Contact contact) {
if (contact == null || contact.getNumbers() == null) {
return;
}
RecyclerView rvNumers = (RecyclerView) findViewById(R.id.rvNumbers);
LinkedList<NumberContainer> numberList = contact.getNumbers();
if (numberList == null) {
return;
}
rvNumers.setLayoutManager(new LinearLayoutManager(this));
rvNumers.setAdapter(new NumberViewAdapter(this, numberList));
}
private void loadAddressField(Contact contact) {
if (contact == null || contact.getAddresses() == null) {
return;
}
RecyclerView rvAddress = (RecyclerView) findViewById(R.id.rvAddress);
LinkedList<AddressContainer> addressList = contact.getAddresses();
if (addressList == null) {
return;
}
rvAddress.setLayoutManager(new LinearLayoutManager(this));
rvAddress.setAdapter(new AddressViewAdapter(this, addressList));
}
private void loadEmailField(Contact contact) {
if (contact == null || contact.getEmails() == null) {
return;
}
RecyclerView rvEmail = (RecyclerView) findViewById(R.id.rvEmail);
LinkedList<EmailContainer> emailList = contact.getEmails();
if (emailList == null) {
return;
}
rvEmail.setLayoutManager(new LinearLayoutManager(this));
rvEmail.setAdapter(new EmailViewAdapter(this, emailList));
}
private void loadWebsiteField(Contact contact) {
if (contact == null || contact.getWebsites() == null) {
return;
}
RecyclerView rvWebsite = (RecyclerView) findViewById(R.id.rvWebsite);
LinkedList<WebsiteContainer> websiteList = contact.getWebsites();
if (websiteList == null) {
return;
}
rvWebsite.setLayoutManager(new LinearLayoutManager(this));
rvWebsite.setAdapter(new WebsiteViewAdaptor(this, websiteList));
}
private void loadEventField(Contact contact) {
if (contact == null || contact.getEvents() == null) {
return;
}
RecyclerView rvEvent = (RecyclerView) findViewById(R.id.rvEvent);
LinkedList<EventContainer> eventList = contact.getEvents();
if (eventList == null) {
return;
}
rvEvent.setLayoutManager(new LinearLayoutManager(this));
rvEvent.setAdapter(new EventViewAdaptor(this, eventList));
}
private void loadNoteField(Contact contact) {
if (contact == null || contact.getNotes() == null) {
return;
}
RecyclerView rvNote = (RecyclerView) findViewById(R.id.rvNote);
LinkedList<NoteContainer> noteList = contact.getNotes();
if (noteList == null) {
return;
}
rvNote.setLayoutManager(new LinearLayoutManager(this));
rvNote.setAdapter(new NoteViewAdaptor(this, noteList));
}
}
build.grade:应用
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 10
versionName "5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':MobileContactsLib')
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'jp.wasabeef:glide-transformations:2.0.1'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'androidx.palette:palette:1.0.0'
testImplementation 'junit:junit:4.12'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
//Design for UI
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-database:19.0.0'
implementation 'com.google.firebase:firebase-storage:19.0.0'
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.github.Jagerfield:Android-Utilities-Library:v2.1'
api 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.paypal.sdk:paypal-android-sdk:2.15.3'
implementation 'androidx.appcompat:appcompat:1.0.0'
testImplementation 'junit:junit:4.12'
//CustomTabs for PayPal Send money
implementation 'androidx.browser:browser:1.0.0'
//Email Validation
implementation 'commons-validator:commons-validator:1.6'
implementation 'com.miguelcatalan:materialsearchview:1.4.0'
implementation 'com.hbb20:ccp:2.2.9'
testImplementation 'junit:junit:4.12'
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':MobileContactsLib')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'jp.wasabeef:glide-transformations:2.0.1'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:palette-v7:28.0.0'
implementation 'com.github.Jagerfield:Android-Utilities-Library:v2.1'
testImplementation 'junit:junit:4.12'
implementation 'com.github.bumptech.glide:glide:3.8.0'
//exclude glide coming from place api
implementation ('com.google.android.libraries.places:places:1.0.0'){
exclude module: 'glide'
}
}
build.gradle(模块:ModuleContactsLib)
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.Jagerfield'
android {
compileSdkVersion 28
//buildToolsVersion "24.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 10
versionName "5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.0.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.code.gson:gson:2.3.1'
}