我已经使用SVG和PNG图像创建了一个应用程序它完全适用于Android 5.1和Android 6.0但其他其他版本如android 4.4,7.1和8.1应用程序崩溃并向我显示此错误:
致命异常:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ejobbox.ejobbox/com.ejobbox.ejobbox.DrawerMenu}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
FATAL EXCEPTION: main
Process: com.ejobbox.ejobbox, PID: 8648
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ejobbox.ejobbox/com.ejobbox.ejobbox.DrawerMenu}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: Drawable com.ejobbox.ejobbox:drawable/ic_upsc with resource ID #0x7f0700a2
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v21/ic_upsc.xml from drawable resource ID #0x7f0700a2
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
我目前正在使用android studio 3.0版本,所以请让我知道如何解决它。我添加了
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
但错误未修复,请帮我解决此错误。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawermenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ejobbox.ejobbox.DrawerMenu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundcolor"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="4">
<android.support.v7.widget.CardView
android:id="@+id/card_add1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="?attr/cardbackground">
<LinearLayout
android:id="@+id/LayerImg1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?attr/cardbackground"
android:gravity="center"
android:orientation="vertical"
android:padding="2dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="@+id/img1"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/border"
android:padding="5dp"
android:src="@drawable/ic_letestjob" />
<TextView
android:id="@+id/badgeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/img1"
android:layout_alignTop="@+id/img1"
android:layout_marginRight="-2dip"
android:layout_marginTop="-2dip"
android:background="@drawable/item_count"
android:gravity="center"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:text="10"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:id="@+id/ltsjobs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img1"
android:layout_marginTop="-10dp"
android:background="@drawable/txtborder"
android:gravity="center"
android:paddingBottom="1dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="1dp"
android:text="Latest Jobs"
android:textColor="?attr/icontextcolor"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/BankingIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="?attr/cardbackground">
<LinearLayout
android:id="@+id/LayerBanking"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?attr/cardbackground"
android:gravity="center"
android:orientation="vertical"
android:padding="2dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="@+id/BankingLogo"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/border"
android:padding="5dp"
android:src="@drawable/ic_banking" />
<TextView
android:id="@+id/BankingBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/BankingLogo"
android:layout_alignTop="@+id/BankingLogo"
android:layout_marginRight="-2dip"
android:layout_marginTop="-2dip"
android:background="@drawable/item_count"
android:gravity="center"
android:textColor="#FFF"
android:textSize="11sp"
android:textStyle="bold"
android:visibility="gone" />
</RelativeLayout>
<TextView
android:id="@+id/BankingTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/BankingLogo"
android:layout_marginTop="-10dp"
android:background="@drawable/txtborder"
android:gravity="center"
android:paddingBottom="1dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="1dp"
android:text="Banking"
android:textColor="?attr/icontextcolor"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/PoliceIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="?attr/cardbackground">
<LinearLayout
android:id="@+id/LayerPolice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?attr/cardbackground"
android:gravity="center"
android:orientation="vertical"
android:padding="2dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="@+id/PoliceLogo"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/border"
android:padding="5dp"
android:src="@drawable/ic_police" />
<TextView
android:id="@+id/PoliceBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/PoliceLogo"
android:layout_alignTop="@+id/PoliceLogo"
android:layout_marginRight="-2dip"
android:layout_marginTop="-2dip"
android:background="@drawable/item_count"
android:gravity="center"
android:textColor="#FFF"
android:textSize="11sp"
android:textStyle="bold"
android:visibility="gone" />
</RelativeLayout>
<TextView
android:id="@+id/PoliceTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/PoliceLogo"
android:layout_marginTop="-10dp"
android:background="@drawable/txtborder"
android:gravity="center"
android:paddingBottom="1dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="1dp"
android:text="Police"
android:textColor="?attr/icontextcolor"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigationMenuView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/backgroundcolor"
app:headerLayout="@layout/header"
app:itemIconTint="?attr/tintcolor"
app:itemTextColor="?attr/textcolor"
app:menu="@menu/drawermenu">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
package com.ejobbox.ejobbox;
import android.app.Activity;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.renderscript.Sampler;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.CardView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.ShareActionProvider;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.ejobbox.ejobbox.Helper.LocalHelper;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.crash.FirebaseCrash;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import cc.cloudist.acplibrary.ACProgressConstant;
import cc.cloudist.acplibrary.ACProgressPie;
import in.galaxyofandroid.spinerdialog.OnSpinerItemClick;
import in.galaxyofandroid.spinerdialog.SpinnerDialog;
import io.paperdb.Paper;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class DrawerMenu extends AppCompatActivity implements View.OnClickListener {
private ArrayList<Model> list;
private String baseURL = "http://ejobbox.com/";
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
private NavigationView navMenuView;
SharedPreferences sharedPreferences;
private FirebaseAnalytics mFirebaseAnalytics;
Context context;
boolean doubleBackToExitPressed = false;
SharedPref sharedpref;
SharedPref Languagepref;
private float cVersion;
private String Applink;
private boolean is_first=true;
private String cVer;
private Menu menu;
ArrayList<String> items = new ArrayList<>();
ArrayList<String> Qualiitems = new ArrayList<>();
SpinnerDialog spinnerDialog;
SpinnerDialog spinnerDialogQuali;
ImageView imageView;
int GetMenuid;
public static final String PREFS_NAME = "Datakey";
public static final String PREFS_NAME2 = "Updatekey";
private CardView BtnAdd1, BtnAdd2, BtnAdd3, BtnAdd4, BtnAdd5, BtnAdd6, BtnAdd7, BtnAdd8, BtnAdd9, BtnAdd10, BtnAdd11, BtnAdd12, BtnAdd13, BtnAdd14, BtnAdd15, BtnAdd16, BtnAdd17, BtnAdd18;
int getBadgedataInt;
int getOLDVALUEInt;
int jobResponseValue;
int ResultUpd = 0;
int BankingValue;
int getBankingOLD;
int BankingResult = 0;
int ResultValue, AdmitCardValue, PoliceValue, RailwayValue, SscValue, UpscValue, DefenceValue, ITComputerValue, EngereeningValue, MedicalValue, SPSCValue, ITIValue, TeacherValue, InterviewValue, AdmitionValue, OtherjobValue;
int getResultOLD, getAdmitCardOLD, getPoliceOLD, getRailwayOLD, getSscOLD, getUpscOLD, getITComputerOLD, getDefenceOLD, getEngereeningOLD, getMedicalOLD, getSPSCOLD, getITIOLD, getTeacherOLD, getInterviewOLD, getAdmitionOLD, getOtherjobOLD;
int ResultResult = 0, AdmitResult = 0, PoliceResult = 0, RailwayResult = 0, SscResult = 0, UpscResult = 0, ITComputerResult = 0, DefenceResult = 0, EngereeningResult = 0, MedicalResult = 0, ITIResult = 0, SPSCResult = 0, TeacherResult = 0, InterviewResult = 0, AdmitionResult = 0, OtherjobResult = 0;
TextView ltsJobs, TextLang, BankingTxt, PoliceTxt, RailwayTxt, Ssctxt, UpscTxt, ITItxt, DefenceTxt, ITTxt, Teachertxt, InterviewTxt, AdmitionTxt, EngerTxt, MedicalTxt, spscTxt, OtherTxt, ResultTxt, AdmitTxt,StateTxt,QualiTxt;
private AdView mAdView;
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocalHelper.onAttach(newBase, "en"));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
sharedpref = new SharedPref(this);
if (sharedpref.loadNightModeState() == true) {
setTheme(R.style.darktheme);
} else setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer_menu);
android.widget.Toolbar toolbar=(android.widget.Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("EJOBBOX");
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
checkInternetConenction();
//TODO:Google ADS sense
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
// todo: Obtain the FirebaseAnalytics instance.
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.setAnalyticsCollectionEnabled(true);
mFirebaseAnalytics.setMinimumSessionDuration(20000);
final TextView badge = (TextView) findViewById(R.id.badgeCount);
final TextView Banking = (TextView) findViewById(R.id.BankingBadge);
final TextView Railway = (TextView) findViewById(R.id.RailwayBadge);
final TextView Police = (TextView) findViewById(R.id.PoliceBadge);
final TextView SSC = (TextView) findViewById(R.id.SscBadge);
final TextView UPSC = (TextView) findViewById(R.id.UpscBadge);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawermenu);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
navMenuView = (NavigationView) findViewById(R.id.navigationMenuView);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
BtnAdd1 = (CardView) findViewById(R.id.card_add1);
BtnAdd2 = (CardView) findViewById(R.id.BankingIcon);
BtnAdd3 = (CardView) findViewById(R.id.PoliceIcon);
BtnAdd4 = (CardView) findViewById(R.id.RailwayIcon);
BtnAdd5 = (CardView) findViewById(R.id.SscIcon);
BtnAdd6 = (CardView) findViewById(R.id.UpscIcon);
//add Click Listner
BtnAdd1.setOnClickListener(this);
BtnAdd2.setOnClickListener(this);
BtnAdd3.setOnClickListener(this);
BtnAdd4.setOnClickListener(this);
BtnAdd5.setOnClickListener(this);
BtnAdd6.setOnClickListener(this);
sharedPreferences = getSharedPreferences(PREFS_NAME, 0);
final SharedPreferences.Editor editors = sharedPreferences.edit();
navMenuView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Intent MenuIntent;
switch (item.getItemId()) {
case R.id.Alljobs:
MenuIntent = new Intent(DrawerMenu.this, AllJobsPage.class);
MenuIntent.putExtra("UpdResult", String.valueOf(jobResponseValue));
MenuIntent.putExtra("jobID", "190");
MenuIntent.putExtra("JOBSSTATE", R.string.All_jobs);
startActivity(MenuIntent);
break;
case R.id.countdown:
MenuIntent = new Intent(DrawerMenu.this, ExamCountdown.class);
startActivity(MenuIntent);
break;
case R.id.jobsummary:
MenuIntent = new Intent(DrawerMenu.this, JobSummary.class);
startActivity(MenuIntent);
break;
default:
break;
}
return false;
}
});
//TODO: Check Internet Connection [End]
private void initItems() {
for (int i = 0; i < 1; i++) {
items.add(this.getResources().getString(R.string.All_india));
items.add(this.getResources().getString(R.string.AndraPradesh));
items.add(this.getResources().getString(R.string.ArunachalPrades));
items.add(this.getResources().getString(R.string.Assam));
items.add(this.getResources().getString(R.string.Bihar));
}
}
private void eduQulification() {
for (int i = 0; i < 1; i++) {
Qualiitems.add(this.getResources().getString(R.string.ssc));
Qualiitems.add(this.getResources().getString(R.string.hsc));
Qualiitems.add(this.getResources().getString(R.string.Diploma));
Qualiitems.add(this.getResources().getString(R.string.ITI));
Qualiitems.add(this.getResources().getString(R.string.Graduate));
}
}
// Searching With Spinner[END]
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
GetMenuid= v.getId();
Intent i;
// i = new Intent(this, police.class);
switch (v.getId()) {
case R.id.card_add1:
i = new Intent(this, AllJobsPage.class);
i.putExtra("UpdResult", String.valueOf(jobResponseValue));
i.putExtra("jobID", "190");
i.putExtra("JOBSSTATE", R.string.All_jobs);
startActivity(i);
break;
case R.id.BankingIcon:
i = new Intent(this, police.class);
i.putExtra("BankingUPD",String.valueOf(BankingValue));
i.putExtra("jobID","197");
i.putExtra("JOBSSTATE",this.getResources().getString(R.string.Banking_Jobs));
startActivity(i);
break;
case R.id.PoliceIcon:
i = new Intent(this, police.class);
i.putExtra("PoliceUPD",String.valueOf(PoliceValue));
i.putExtra("jobID","198");
i.putExtra("JOBSSTATE",this.getResources().getString(R.string.Police_Jobs));
startActivity(i);
break;
default:
break;
}
}
private void setSupportActionBar(android.widget.Toolbar toolbar) {
if(getSupportActionBar()!=null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
}
//TODO: Actionbar Share Button
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.memu_items,menu);
MenuItem menushare=menu.findItem(R.id.sharMenu);
ShareActionProvider mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menushare);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,DrawerMenu.this.getResources().getString(R.string.shareTitle));
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, DrawerMenu.this.getResources().getString(R.string.shareContent)+"\n"+DrawerMenu.this.getResources().getString(R.string.applink));
mShareActionProvider.setShareIntent(sharingIntent);
return true;
}
}
答案 0 :(得分:0)
移动位于文件夹中的所有drawable&#34; / res / drawable-anydpi-v21&#34;进入正常的drawable文件夹。
另请参见错误消息行: 引起:android.content.res.Resources $ NotFoundException:来自可绘制资源ID的文件res / drawable-anydpi-v21 / ic_upsc.xml#0x7f0700a2
要支持图像文件的不同分辨率,最好使用以下文件夹:
希望能解决您的问题