我正在尝试让我的活动正常运行,但我不断得到下面的例外,知道发生了什么?谢谢!
(谢谢!抱歉缺少信息,我只是新手,也是Android xD)
异常
Process: com.generarencuestas.isbcan.generarencuestas, PID: 27050
android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.gestionencuestas.isbcan.gestionencuestas.DraftFragment.onCreateView(DraftFragment.java:59)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1965)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1078)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1259)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1624)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
at android.view.View.measure(View.java:18849)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:607)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1238)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:672)
at android.view.View.measure(View.java:18849)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:18849)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
at android.view.View.measure(View.java:18849)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
at android.view.View.measure(View.java:18849)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18849)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3073)
at android.view.View.measure(View.java:18849)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2342)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1379)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1622)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1264)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6944)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
XML
有一个xml(content_home),我在那里给CardView(card_survey.xml)充气
content_home.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity">
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="@dimen/_2dp"
android:horizontalSpacing="@dimen/_2dp"
android:stretchMode="columnWidth"
android:numColumns="2"/>
<LinearLayout
android:id="@+id/noMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
tools:visibility="gone">
<!-- LINE 24 below -->
<ImageView
android:id="@+id/noMessagesIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="@drawable/ic_empty"
android:tint="@android:color/darker_gray" />
<TextView
android:id="@+id/noMessagesText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="@string/no_surveys_found"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</LinearLayout>
</RelativeLayout>
card_survey.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="@dimen/_5dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/overlayImage"
android:layout_width="match_parent"
android:layout_height="@dimen/_150dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:scaleType="fitXY" />
<TextView
android:id="@+id/textNameAsset"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/overlayImage"
android:paddingLeft="@dimen/_10dp"
android:paddingRight="@dimen/_10dp"
android:paddingTop="@dimen/_10dp"
android:paddingBottom="@dimen/_10dp"
android:textSize="@dimen/_15dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/textDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textNameAsset"
android:paddingLeft="@dimen/_10dp"
android:paddingRight="@dimen/_10dp"
android:textSize="@dimen/_10dp"/>
<TextView
android:id="@+id/textParticip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textDate"
android:paddingBottom="@dimen/_10dp"
android:paddingLeft="@dimen/_10dp"
android:paddingRight="@dimen/_10dp"
android:textSize="@dimen/_10dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
CODE
DraftFragment.class
/**
* Created by n52830 on 20/07/2017.
*/
public class DraftFragment extends Fragment implements View.OnClickListener {
private HashMap<String,SurveyDao> surveyList = new HashMap<>();
private final FirebaseDatabase database = FirebaseDatabase.getInstance();
private SharedPreferences sharedpreferences;
private ProgressDialog progressDialog;
private LinearLayout noMessagesView;
private GridView gridView;
private View view;
@Override
public void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
}
@Override
public void onActivityCreated(Bundle saveInstanceState){
super.onActivityCreated(saveInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
surveyList = new HashMap<>();
sharedpreferences = this.getActivity().getSharedPreferences(PreferencesEnum.PREFERENCES.getCode(), Context.MODE_PRIVATE);
view = inflater.inflate(R.layout.content_home, container, false);
noMessagesView = (LinearLayout) view.findViewById(R.id.noMessages);
gridView = (GridView) view.findViewById(R.id.gridview);
getDrafts();
return view;
}
private void getDrafts(){
String loggedUser = sharedpreferences.getString(PreferencesEnum.NUMEMPLOYEE.getCode(), "");
final DatabaseReference usersReference = database.getReference(FirebaseReferences.USERS_REFERENCE);
Query queryAssetQueue = usersReference.orderByChild(FirebaseReferences.NUMEMPLOYEE_REFERENCE).equalTo(loggedUser);
progressDialog = new ProgressDialog(this.getActivity());
progressDialog.setMessage(this.getResources().getString(R.string.loading));
progressDialog.show();
queryAssetQueue.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
obtainSurvey(dataSnapshot, view);
dismissProgressDialog(progressDialog);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
obtainSurvey(dataSnapshot, view);
dismissProgressDialog(progressDialog);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
obtainSurvey(dataSnapshot, view);
dismissProgressDialog(progressDialog);
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
dismissProgressDialog(progressDialog);
}
@Override
public void onCancelled(DatabaseError databaseError) {
dismissProgressDialog(progressDialog);
}
});
}
private void obtainSurvey(DataSnapshot dataSnapshot, final View view){
surveyList = new LinkedHashMap<>();
UserDao user = dataSnapshot.getValue(UserDao.class);
HashMap draftSurveysMap = user.getDrafts();
Map<String, String> sortedSurveysMapAsc = sortByComparator(draftSurveysMap, true);
Object[] drafts = sortedSurveysMapAsc.entrySet().toArray();
if(drafts.length == 0){
progressDialog.dismiss();
showEmptyState(true);
}else {
for(Map.Entry<String, String> surveyEntry : sortedSurveysMapAsc.entrySet()){
final DatabaseReference surveysReference = database.getReference(FirebaseReferences.SURVEY_REFERENCE).child(surveyEntry.getKey());
surveysReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
SurveyDao survey = snapshot.getValue(SurveyDao.class);
if(survey != null){
survey.setId(snapshot.getKey());
surveyList.put(snapshot.getKey(),survey);
GridView gridView = (GridView) view.findViewById(R.id.gridview);
gridView.setAdapter(new SurveyAdapter(view.getContext(), surveyList, (SurveyAdapter.ListItemClickListener) getActivity()));
showEmptyState(surveyList.size() == 0);
}
}
@Override
public void onCancelled(DatabaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
}
}
}
@Override
public void onClick(View v){
//do whatever you want here
}
public void showEmptyState(boolean empty) {
if (empty) {
gridView.setVisibility(View.GONE);
noMessagesView.setVisibility(View.VISIBLE);
}else {
gridView.setVisibility(View.VISIBLE);
noMessagesView.setVisibility(View.GONE);
}
}
}
SurveyAdapter.class
public class SurveyAdapter extends BaseAdapter {
private final List<SurveyDao> mItems = new ArrayList<>();
private final LayoutInflater mInflater;
private static ListItemClickListener mOnClickListener; // Reference to item click item listener
private TabLayout tabLayout;
public SurveyAdapter(Context context, HashMap<String,SurveyDao> surveys, ListItemClickListener listener) {
mOnClickListener = listener;
mInflater = LayoutInflater.from(context);
for (SurveyDao survey : surveys.values()) {
mItems.add(new SurveyDao(survey.getId(), survey.getName(), survey.getStatus(), survey.getType_id(), survey.getGroup_id(), survey.getEndDate(),
survey.getPublishDate(), survey.getParticipation(), survey.getNumParticipation(), survey.getCreated(), survey.getModified(),
survey.getUsu_modified(), survey.getUsu_created(), survey.getQuestions()));
}
}
@Override
public int getCount() {
return mItems.size();
}
@Override
public SurveyDao getItem(int i) {
return mItems.get(i);
}
@Override
public long getItemId(int i) {
return mItems.get(i).getType_id();
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
View v = view;
ImageView picture;
TextView name, date, participation;
if (v == null) {
v = mInflater.inflate(R.layout.card_survey, viewGroup, false);
v.setTag(R.id.overlayImage, v.findViewById(R.id.overlayImage));
v.setTag(R.id.textNameAsset, v.findViewById(R.id.textNameAsset));
v.setTag(R.id.textDate, v.findViewById(R.id.textDate));
v.setTag(R.id.textParticip, v.findViewById(R.id.textParticip));
}
picture = (ImageView) v.getTag(R.id.overlayImage);
name = (TextView) v.getTag(R.id.textNameAsset);
date = (TextView) v.getTag(R.id.textDate);
participation = (TextView) v.getTag(R.id.textParticip);
SurveyDao item = getItem(i);
int typeSurvey;
switch (item.getType_id()) {
case 0:
typeSurvey = R.drawable.ic_survey;
break;
case 1:
typeSurvey = R.drawable.ic_training;
break;
case 2:
typeSurvey = R.drawable.ic_events;
break;
default:
typeSurvey = R.drawable.ic_blank;
break;
}
picture.setImageResource(typeSurvey);
name.setText(item.getName());
date.setText(v.getContext().getString(R.string.date_survey_ends, convertCompleteDate(item.getEndDate())));
participation.setText(v.getContext().getString(R.string.porc_participation, item.getParticipation().toString()+"%"));
picture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SurveyDao surveyItem = getItem(i);
mOnClickListener.onListItemClick(surveyItem);
}
});
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SurveyDao surveyItem = getItem(i);
mOnClickListener.onListItemClick(surveyItem);
}
});
return v;
}
public interface ListItemClickListener {
void onListItemClick(SurveyDao surveyItem);
}
public void onBackPressed() {
Intent intentSurvey = new Intent(context, LoginActivity.class);
startActivity(intentSurvey);
finish();
}
// more code ...
}
gradle compileSdkVersion: 24
gradle buildToolsVersion: 25
答案 0 :(得分:0)
在layout.xml中,视图的类名应该有错误。
如果您使用自定义视图,则应使用包
指明完整的类名<com.my.package.ui.MyAwesomeCustomView
android:id="@+id/my_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ... --->
</com.my.package.ui.MyAwesomeCustomView>
答案 1 :(得分:0)
我无法预测第24行的实际行,但您的行tools:visibility="gone"
似乎有问题。
将tools:visibility="gone"
更改为android:visibility="gone"
答案 2 :(得分:0)
我添加了
android:largeHeap="true"
到我的AndroidManifest.xml里面的应用程序标签,看起来像它的工作原理,至少对于崩溃的casuistic来说。希望它保持良好的运作......
答案 3 :(得分:0)
当抛出OutOfMemoryError