Android Studio开发的Connect 3游戏在三星设备运行崩溃求助
Hey there! Let's break down what's going wrong here and get your Connect 3 game up and running smoothly on Samsung devices.
The Real Root Cause
First, let's cut through the noise in the Logcat. Those top-level errors (like the InflateException for GridLayout) are just symptoms—the actual problem lies with an invalid or missing drawable resource:
Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.stephenlearmonth.connect3game:drawable/board" (7f060054) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060054 a=-1 r=0x7f060054}
Your GridLayout is trying to use @drawable/board as its background, but the app can't recognize this file as a valid Drawable.
Step 1: Fix the board Drawable Resource
Check these common issues with your board resource:
- File location: Make sure
board.png(or your image's format) is placed in the correctdrawablefolder (notmipmap,raw, or other resource folders). If you use density-specific folders (likedrawable-hdpi), ensure the file exists in the basedrawablefolder at minimum. - File validity: Confirm the image is a valid format (PNG, JPG, etc.). Corrupted files will trigger this error—try re-importing the image into your project.
- Naming rules: Ensure the filename is all lowercase with no special characters (underscores are allowed). Android resource filenames can't have uppercase letters or spaces.
Step 2: Correct the GridLayout Import
Your attempt to switch to android.support.v7.widget.GridLayout was unnecessary (and caused a "Cannot resolve symbol" error because you don't have the corresponding support library in your dependencies).
The native android.widget.GridLayout has been available since API 14, and your minSdkVersion is set to 19—so it's fully supported on your target devices. Revert your import in MainActivity.java back to:
import android.widget.GridLayout;
Your XML layout uses the native GridLayout correctly, so no changes are needed there.
Step 3: Clean and Rebuild Your Project
After fixing the drawable and import, clear old cached resources with a clean build:
- In Android Studio, go to Build > Clean Project
- Then go to Build > Rebuild Project
Verify the Fix
Run your app on the Samsung device again—this should resolve the crash. If you still run into issues, double-check the drawable resource to ensure it's properly added and accessible.
内容的提问来源于stack exchange,提问作者user7142686

