我的应用程序具有minSdkVersion14。我的应用程序的欢迎屏幕运行正常,但第二个活动在Android 6.0及更低版本上崩溃了。
我有问题的活动
Intent IntWellcome = getIntent();
//----Get Card Count From Previous Activity
final Integer HowMuchCard = IntWellcome.getIntExtra("StartUpCardCount", 0);
final GridLayout CardGrid = (GridLayout) findViewById(R.id.CardHolder);
//----MyCard is my class that defines card properties.
final MyCard Cards[] = new MyCard[HowMuchCard];
for (int i = 0; i < HowMuchCard; i++) {
Cards[i] = new MyCard(this, i, HowMuchCard);
Cards[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final MyCard k = (MyCard) view;
k.Turn();
k.setClickable(false);ClickError=0;
TextView TVMyScore = (TextView)findViewById(R.id.TVScore);
TVMyScore.setText(Integer.toString(point));
if (LastCard > -1) {
final MyCard k2 = (MyCard) findViewById(LastCard);
//k2.Turn();
if ((k2.FrontSideID == k.FrontSideID) && (k2.getId() != k.getId())) {
//Match
k2.Turnable=false;
k.Turnable=false;
k.setBackgroundResource(R.drawable.rocket_thrust);
k2.setBackgroundResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) k.getBackground();
rocketAnimation.start();
rocketAnimation = (AnimationDrawable) k2.getBackground();
rocketAnimation.start();
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
k.setVisibility(View.INVISIBLE);
k2.setVisibility(View.INVISIBLE);
}
},600);
//k.setVisibility(View.INVISIBLE);
//k2.setVisibility(View.INVISIBLE);
score++;
point = point+(100);
LastCard = -1;
TVMyScore.setText(Integer.toString(point));
if(score==(HowMuchCard/2)){
CardGrid.setVisibility(View.GONE);
TextView TVMyCongratMessage = (TextView)findViewById(R.id.TVCongrats);
TVMyCongratMessage.setVisibility(View.VISIBLE);
//oyun bitti
}
} else {
point = point - 10;
TVMyScore.setText(Integer.toString(point));
LastCard=-1;
Handler h = new Handler();
h.postDelayed(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void run() {
k.Turn();
k2.Turn();
k.setClickable(true);
k2.setClickable(true);
}
},500);
}
} else {
LastCard = k.getId();
}
}
});
}
//------Shuffle Cards
for (int i = 0; i < (HowMuchCard); i++) {
int rg = (int) (Math.random() * HowMuchCard);
MyCard k = Cards[rg];
Cards[rg] = Cards[i];
Cards[i] = k;
}
//-----Put Cards in GridLayout
for (int j = 0; j < HowMuchCard; j++) {
CardGrid.addView(Cards[j]);
}
此代码块可在Android 7.0和其他版本上完美运行。但是在Android 6.0及更早版本上进行欢迎活动后,它永远无法工作。
它说:“不幸的是,MyApp已停止”。我的哪个代码不适合Android 6.0及更低版本?
这是堆栈跟踪
10-15 14:14:04.232 3749-3749/greyworkssoftware.memoryskills E/AndroidRuntime: FATAL EXCEPTION: main
Process: greyworkssoftware.memoryskills, PID: 3749
java.lang.RuntimeException: Unable to start activity ComponentInfo{greyworkssoftware.memoryskills/greyworkssoftware.memoryskills.CardsActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f060066
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f060066
at android.content.res.Resources.getValue(Resources.java:1351)
at android.content.res.Resources.getDrawable(Resources.java:804)
at android.content.Context.getDrawable(Context.java:458)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:351)
at greyworkssoftware.memoryskills.MyCard.<init>(MyCard.java:99)
at greyworkssoftware.memoryskills.CardsActivity.onCreate(CardsActivity.java:81)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)