Issue
I used AVD to create a virtual device that is 7 inches and has a screen resolution of 2880x1800. My goal is to get 7-inch screenshots that are high resolution. But my app fails to load on this device. The log says that the resource at setContentView(R.layout.my_activity_layout)
is not found. How is that true? It works on every other device from normal to xlarge. Any ideas?
Here's my stack trace.
04-21 21:31:52.513 2380-2380/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.nsouthproductions.mathanimalsaddition, PID: 2380
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nsouthproductions.mathanimalsaddition/com.nsouthproductions.mathanimalsaddition.Main}: android.content.res.Resources$NotFoundException: Resource ID #0x7f040008
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040008
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2598)
at android.content.res.Resources.getLayout(Resources.java:1049)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2144)
at com.nsouthproductions.mathanimalsaddition.Main.onCreate(Main.java:333)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-21 21:31:52.740 933-933/? E/EGL_emulation﹕ tid 933: eglCreateSyncKHR(1237): error 0x3004 (EGL_BAD_ATTRIBUTE)
EDIT: adding Java and XML, though they are very standard and are proven to work on other devices.
Java: (error occurs at setContentView()
)
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Ensures they resume where left off if hit launcher and game already playing
// If the launcher is trying to create a new instance of Main, this checks to see
// if this is a new instance of the app. If not, close this activity so that the
// one below it (where they left off) is at the top.
if (!isTaskRoot()
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
Intent intent = getIntent();
if(savedInstanceState != null){
START_IN_PLAY = savedInstanceState.getBoolean(KEY_SHOWING_PLAY, false);
START_IN_PRACTICE = savedInstanceState.getBoolean(KEY_SHOWING_PRACTICE, false);
START_IN_QUIZ = savedInstanceState.getBoolean(KEY_SHOWING_QUIZ, false);
}
context = this;
mDecorView = getWindow().getDecorView();
// call before setContentView to avoid system bars briefly showing
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
System.out.println("checking os version");
if (currentapiVersion >= Build.VERSION_CODES.KITKAT) {
System.out.println("KitKat or newer");
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
);
} else{
System.out.println("Older than KitKat");
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
main_layout
for land
resource
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" tools:context=".Main"
android:id="@+id/area_main_layout">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="@+id/imageView6"
android:src="@drawable/title_math_animals"
android:cropToPadding="false"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="@+id/imageView7"
android:src="@drawable/title_addition"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_marginBottom="15dp"
android:layout_weight="3"
android:id="@+id/linlay_main_2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_play"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_play" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_play_text"
android:src="@drawable/text_play"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_practice"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_practice_text"
android:src="@drawable/text_practice"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_quiz"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_quiz_text"
android:src="@drawable/text_quiz"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_animals"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_animals_text"
android:src="@drawable/text_animals"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</LinearLayout>
main_layout
for land
resource
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" tools:context=".Main"
android:id="@+id/area_main_layout">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView6"
android:src="@drawable/title_math_animals"
android:cropToPadding="false"
android:layout_gravity="center_horizontal"
android:layout_marginTop="7dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="45dp"
android:id="@+id/imageView7"
android:src="@drawable/title_addition"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_marginBottom="10dp"
android:layout_weight="3"
android:id="@+id/linlay_main_2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_play"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_play" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_play_text"
android:src="@drawable/text_play"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_practice"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_practice_text"
android:src="@drawable/text_practice"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_quiz"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_quiz_text"
android:src="@drawable/text_quiz"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_animals"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_animals_text"
android:src="@drawable/text_animals"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</LinearLayout>
main_layout
for large_land
resource
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" tools:context=".Main"
android:id="@+id/area_main_layout">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="3"
android:layout_marginTop="15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="@+id/imageView6"
android:src="@drawable/title_math_animals"
android:cropToPadding="false"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="70dp"
android:id="@+id/imageView7"
android:src="@drawable/title_addition"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_marginBottom="15dp"
android:layout_weight="6"
android:id="@+id/linlay_main_2"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_play"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_play" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_play_text"
android:src="@drawable/text_play"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_practice"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_practice_text"
android:src="@drawable/text_practice"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_quiz"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_quiz_text"
android:src="@drawable/text_quiz"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_animals"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_animals_text"
android:src="@drawable/text_animals"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</LinearLayout>
I cannot post for xlarge-land
without going over the character limit. I've seen all of these resources load successfully on other devices.
Solution
For any resource, you always have to provide a default version (in an unqualified resource directory) as the fallback for when the system cannot determine the most appropriate resource (or there isn't one that matches the current configuration).
See Providing Resources - Compatibility for more info:
Likewise, if you provide different layout resources based on the screen orientation, you should pick one orientation as your default. For example, instead of providing layout resources in layout-land/ for landscape and layout-port/ for portrait, leave one as the default, such as layout/ for landscape and layout-port/ for portrait.
Answered By - Kevin Coppock
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.