我创建了一个音板应用程序,它可以在Galaxy S7或LG G2上完美运行,但它与LG G4或华为Y625等设备有一些问题。 问题是这样的: android.content.res.Resources $ NotFoundException 这是堆栈:
java.lang.RuntimeException: Unable to start activity ComponentInfo{cassiocorporation.overwapp/cassiocorporation.overwapp.Home}: android.view.InflateException: Binary XML file line #24: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2272)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5135)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at cassiocorporation.overwapp.Home.onCreate(Home.java:31)
at android.app.Activity.performCreate(Activity.java:5289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2186)
... 11 more Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020053
at android.content.res.Resources.getValue(Resources.java:1128)
at android.support.v7.widget.ResourcesWrapper.getValue(ResourcesWrapper.java:204)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:332)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:66)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:118)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1021)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1080)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
... 27 more
所以,这是我的Home.java代码:
public class Home扩展了AppCompatActivity 实现NavigationView.OnNavigationItemSelectedListener {
ImageButton imageButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//bottoni eroi
addListenerOnButtonAna();
addListenerOnButtonBastion();
addListenerOnButtonDVa();
addListenerOnButtonDoomfist();
addListenerOnButtonGenji();
addListenerOnButtonHanzo();
addListenerOnButtonJunkrat();
addListenerOnButtonLucio();
addListenerOnButtonMcCree();
addListenerOnButtonMei();
addListenerOnButtonMercy();
addListenerOnButtonOrisa();
addListenerOnButtonPharah();
addListenerOnButtonReaper();
addListenerOnButtonReinhardt();
addListenerOnButtonRoadhog();
addListenerOnButtonSoldier();
addListenerOnButtonSombra();
addListenerOnButtonSymmetra();
addListenerOnButtonTorbjorn();
addListenerOnButtonTracer();
addListenerOnButtonWidowmaker();
addListenerOnButtonZarya();
addListenerOnButtonZenyatta();
}
// Inizio Eroi
public void addListenerOnButtonAna() {
imageButton = (ImageButton) findViewById(R.id.ana);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent ana=new Intent(Home.this, Ana.class);
startActivity(ana);
Toast.makeText(Home.this, "You pressed on Ana", Toast.LENGTH_SHORT).show();
}
});
}
public void addListenerOnButtonBastion() {
final MediaPlayer bastionSound = MediaPlayer.create(this, R.raw.bastion_ulti); //UPDATED 24/03 21:23
imageButton = (ImageButton) findViewById(R.id.bastionbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent bastion=new Intent(Home.this, Bastion.class);
startActivity(bastion);
Toast.makeText(Home.this, "You pressed on Bastion", Toast.LENGTH_SHORT).show();
}
});
}
public void addListenerOnButtonDVa() {
final MediaPlayer dvaSound = MediaPlayer.create(this, R.raw.dva_ulti);
imageButton = (ImageButton) findViewById(R.id.dvabutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent dva=new Intent(Home.this, DVa.class);
startActivity(dva);
Toast.makeText(Home.this, "You pressed on D.Va", Toast.LENGTH_SHORT).show();
}
});
}
public void addListenerOnButtonDoomfist() {
final MediaPlayer doomfistSound = MediaPlayer.create(this, R.raw.eh_volevi);
imageButton = (ImageButton) findViewById(R.id.doomfistbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Doomfist", Toast.LENGTH_SHORT).show();
doomfistSound.start();
}
});
}
public void addListenerOnButtonGenji() {
imageButton = (ImageButton) findViewById(R.id.genjibutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent genji=new Intent(Home.this, Genji.class);
startActivity(genji);
Toast.makeText(Home.this, "You pressed on Genji", Toast.LENGTH_SHORT).show();
}
});
}
public void addListenerOnButtonHanzo() {
imageButton = (ImageButton) findViewById(R.id.hanzobutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent hanzo=new Intent(Home.this, Hanzo.class);
startActivity(hanzo);
Toast.makeText(Home.this, "You pressed on Hanzo", Toast.LENGTH_SHORT).show();
}
});
}
public void addListenerOnButtonJunkrat() {
final MediaPlayer junkratSound = MediaPlayer.create(this, R.raw.junkrat_ulti);
imageButton = (ImageButton) findViewById(R.id.junkratbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Junkrat", Toast.LENGTH_SHORT).show();
junkratSound.start();
}
});
}
public void addListenerOnButtonLucio() {
imageButton = (ImageButton) findViewById(R.id.luciobutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent lucio=new Intent(Home.this, Lucio.class);
startActivity(lucio);
Toast.makeText(Home.this, "Rastaman89 is here", Toast.LENGTH_SHORT).show();
}
});
}
public void addListenerOnButtonMcCree() {
final MediaPlayer mccreeSound = MediaPlayer.create(this, R.raw.mccree_ulti_music);
imageButton = (ImageButton) findViewById(R.id.mccreebutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on McCree", Toast.LENGTH_SHORT).show();
mccreeSound.start();
}
});
}
public void addListenerOnButtonMei() {
final MediaPlayer meiSound = MediaPlayer.create(this, R.raw.mei_ulti);
imageButton = (ImageButton) findViewById(R.id.meibutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Mei", Toast.LENGTH_SHORT).show();
meiSound.start();
}
});
}
public void addListenerOnButtonMercy() {
final MediaPlayer mercySound = MediaPlayer.create(this, R.raw.mercy_ulti);
imageButton = (ImageButton) findViewById(R.id.mercybutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Mercy", Toast.LENGTH_SHORT).show();
mercySound.start();
}
});
}
public void addListenerOnButtonOrisa() {
final MediaPlayer orisaSound = MediaPlayer.create(this, R.raw.orisa_ulti);
imageButton = (ImageButton) findViewById(R.id.orisabutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Orisa", Toast.LENGTH_SHORT).show();
orisaSound.start();
}
});
}
public void addListenerOnButtonPharah() {
final MediaPlayer pharahSound = MediaPlayer.create(this, R.raw.pharah_ulti);
imageButton = (ImageButton) findViewById(R.id.pharahbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Pharah", Toast.LENGTH_SHORT).show();
pharahSound.start();
}
});
}
public void addListenerOnButtonReaper() {
final MediaPlayer reaperSound = MediaPlayer.create(this, R.raw.reaper_ulti);
imageButton = (ImageButton) findViewById(R.id.reaperbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Reaper", Toast.LENGTH_SHORT).show();
reaperSound.start();
}
});
}
public void addListenerOnButtonReinhardt() {
final MediaPlayer reinhardtSound = MediaPlayer.create(this, R.raw.reinhardt_ulti);
imageButton = (ImageButton) findViewById(R.id.reinhardtbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Reinhardt", Toast.LENGTH_SHORT).show();
reinhardtSound.start();
}
});
}
public void addListenerOnButtonRoadhog() {
final MediaPlayer roadhogSound = MediaPlayer.create(this, R.raw.roadhog_ulti);
imageButton = (ImageButton) findViewById(R.id.roadhogbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Roadhog", Toast.LENGTH_SHORT).show();
roadhogSound.start();
}
});
}
public void addListenerOnButtonSoldier() {
final MediaPlayer soldierSound = MediaPlayer.create(this, R.raw.soldier_ulti);
imageButton = (ImageButton) findViewById(R.id.soldierbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Soldier: 76", Toast.LENGTH_SHORT).show();
soldierSound.start();
}
});
}
public void addListenerOnButtonSombra() {
final MediaPlayer sombraSound = MediaPlayer.create(this, R.raw.sombra_ulti);
imageButton = (ImageButton) findViewById(R.id.sombrabutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Sombra", Toast.LENGTH_SHORT).show();
sombraSound.start();
}
});
}
public void addListenerOnButtonSymmetra() {
final MediaPlayer symmetraSound = MediaPlayer.create(this, R.raw.symmetra_ulti);
imageButton = (ImageButton) findViewById(R.id.symmetrabutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Symmetra", Toast.LENGTH_SHORT).show();
symmetraSound.start();
}
});
}
public void addListenerOnButtonTorbjorn() {
final MediaPlayer torbjornSound = MediaPlayer.create(this, R.raw.torbjorn_ulti);
imageButton = (ImageButton) findViewById(R.id.torbjornbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Torbjörn", Toast.LENGTH_SHORT).show();
torbjornSound.start();
}
});
}
public void addListenerOnButtonTracer() {
final MediaPlayer tracerSound = MediaPlayer.create(this, R.raw.tracer_ulti);
imageButton = (ImageButton) findViewById(R.id.tracerbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Tracer", Toast.LENGTH_SHORT).show();
tracerSound.start();
}
});
}
public void addListenerOnButtonWidowmaker() {
final MediaPlayer widowSound = MediaPlayer.create(this, R.raw.widow_ulti);
imageButton = (ImageButton) findViewById(R.id.widowbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Widowmaker", Toast.LENGTH_SHORT).show();
widowSound.start();
}
});
}
public void addListenerOnButtonZarya() {
final MediaPlayer zaryaSound = MediaPlayer.create(this, R.raw.zarya_ulti);
imageButton = (ImageButton) findViewById(R.id.zaryabutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Zarya", Toast.LENGTH_SHORT).show();
zaryaSound.start();
}
});
}
public void addListenerOnButtonZenyatta() {
final MediaPlayer zenyattaSound = MediaPlayer.create(this, R.raw.zenyatta_ulti);
imageButton = (ImageButton) findViewById(R.id.zenyattabutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(Home.this, "You pressed on Zenyatta", Toast.LENGTH_SHORT).show();
zenyattaSound.start();
}
});
}
//Fine Eroi
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_voice) {
String voice="https://docs.google.com/forms/d/e/1FAIpQLSeWEN08PJOhXxf3N3upyyi8msUqBJSX_ry-3HXm6ONdfBX1eA/viewform";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
builder.setToolbarColor(Color.argb(255,47,60,86));
customTabsIntent.launchUrl(Home.this, Uri.parse(voice));
} else if (id == R.id.nav_alpha) {
String feed="https://docs.google.com/forms/d/e/1FAIpQLScdBlonNBn6nRx_QTgGkfe9R_Q9TvwAhYFomphSER2e_4xP8w/viewform";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
builder.setToolbarColor(Color.argb(255,205,220,57));
customTabsIntent.launchUrl(Home.this, Uri.parse(feed));
} else if (id == R.id.nav_feed) {
String feed="https://docs.google.com/forms/d/e/1FAIpQLSclPQIJL8ci9AxlAzakg1cZpYFhWCArssCrz562zLNj15stmQ/viewform";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
builder.setToolbarColor(Color.argb(255,15,157,88));
customTabsIntent.launchUrl(Home.this, Uri.parse(feed));
} else if (id == R.id.nav_bug) {
String bug = "https://docs.google.com/forms/d/e/1FAIpQLSf2h0nO32xWlx0yP6HNMcWXX3ogO1i4ISz4o-EzIlnM4NvzpQ/viewform";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
builder.setToolbarColor(Color.argb(255, 219, 68, 55));
customTabsIntent.launchUrl(Home.this, Uri.parse(bug));
} else if (id == R.id.nav_settings){
Intent set=new Intent (Home.this, Settings.class);
startActivity(set);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
这就是明白:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_overwapp"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashCassio"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Home"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Credits"
android:label="Credits"
android:parentActivityName=".Home" />
<activity
android:name=".Ana"
android:label="@string/title_activity_ana"
android:parentActivityName=".Home"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Genji"
android:label="@string/title_activity_genji"
android:parentActivityName=".Home"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Hanzo"
android:label="@string/title_activity_hanzo"
android:parentActivityName=".Home"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Lucio"
android:label="@string/title_activity_lucio"
android:parentActivityName=".Home"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Bastion"
android:label="@string/title_activity_bastion"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Settings"
android:label="About"
android:parentActivityName=".Home" />
<activity
android:name=".Pop"
android:theme="@style/AppTheme.CustomTheme" />
<activity
android:name=".PatchNotes"
android:theme="@style/AppTheme.CustomTheme" />
<activity
android:name=".Cassio"
android:theme="@style/AppTheme.CustomTheme" />
<activity
android:name=".DVa"
android:label="D.Va"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>
我没有任何想法来解决这个问题......请帮帮我