Child class of SurfaceView crashed the application - android-layout

I did simple application. I had added the new class TouchView:
package com.example.lookatme;
import android.content.Context;
import android.view.SurfaceView;
public class TouchView extends SurfaceView{
public TouchView(Context context) {
super(context);
}
}
... and added my new view at layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rlMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".BlockerActivity" >
<com.example.lookatme.TouchView
android:id="#+id/tvPaint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/ivCenter"
android:layout_marginTop="14dp" />
<ImageView
android:id="#+id/ivCenter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" android:contentDescription="TODO"/>
</RelativeLayout>
At the start crashed application on the code setContentView(R.layout.activity_blocker) in activity. That i did wrong? The LogCat have same text:
10-23 18:02:03.442: W/dalvikvm(1964): threadid=1: thread exiting with uncaught exception (group=0xb57ef4f0)
10-23 18:02:03.442: E/AndroidRuntime(1964): FATAL EXCEPTION: main
10-23 18:02:03.442: E/AndroidRuntime(1964): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lookatme/com.example.lookatme.BlockerActivity}: java.lang.ClassCastException: android.view.SurfaceView
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.os.Looper.loop(Looper.java:130)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-23 18:02:03.442: E/AndroidRuntime(1964): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 18:02:03.442: E/AndroidRuntime(1964): at java.lang.reflect.Method.invoke(Method.java:507)
10-23 18:02:03.442: E/AndroidRuntime(1964): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-23 18:02:03.442: E/AndroidRuntime(1964): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-23 18:02:03.442: E/AndroidRuntime(1964): at dalvik.system.NativeStart.main(Native Method)
10-23 18:02:03.442: E/AndroidRuntime(1964): Caused by: java.lang.ClassCastException: android.view.SurfaceView
10-23 18:02:03.442: E/AndroidRuntime(1964): at com.example.lookatme.BlockerActivity.onCreate(BlockerActivity.java:67)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-23 18:02:03.442: E/AndroidRuntime(1964): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-23 18:02:03.442: E/AndroidRuntime(1964): ... 11 more
10-23 18:04:01.741: W/ActivityThread(2020): Application com.example.lookatme is waiting for the debugger on port 8100...

I did found the desision: for child class need to overload other constructor: with Context and Attributes.

Related

Android toolbars and whether they are nullable

As seems to be typical for Android development, it doesn't work.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
//setSupportActionBar(toolbar) Why doesn't this work? Type mismatch: inferred type is android.widget.Toolbar but androidx.appcompat.widget.Toolbar? was expected
setSupportActionBar(findViewById(R.id.toolbar))
}
}
<LinearLayout
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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
However:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rwb.toolbarhide, PID: 3989
java.lang.NoClassDefFoundError: android.widget.Toolbar
at com.rwb.toolbarhide.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Is this something to do with androidx and different Toolbars?
How can you tell if this is so?
What can be done to fix it?
What I wanted to know, however, was why the line commented out doesn't work.
How can we tell if findViewById is returning a Toolbar or a Toolbar? (in VisualStudio you would just hover the mouse, but not so in AndroidStudio -- it seems to be impossible).
So, if indeed we do have a Toolbar and not a Toolbar? then how can we pass it to setSupportActionBar?
(I want a Toolbar not a Toolbar? because it's a right nuisance having to ? and !! all over the place.)
import android.widget.Toolbar. It would have been done by the intellisense if it wasn't there as standard because I have no idea what I'm doing. Did it guess the wrong one?
This seems to have pacified it:
import androidx.appcompat.widget.Toolbar

App stopped when start an new activity by Intent

I'm using Intent to start new activity. I have also add it in my AndroidManifest. But When I click button to call ContactsActivity.class, Application get crash.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ContactsActivity">
</activity>
</application>
Mainactivity.class
Intent myIntent = new Intent(MainActivity.this, ContactsActivity.class);
startActivityForResult(myIntent,SECOND_ACTIVITY_RESULT_CODE);
FATAL EXCEPTION:
2019-01-20 08:04:48.101 30203-30203/com.example.musicplayeronline E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.musicplayeronline, PID: 30203
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.musicplayeronline-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.musicplayeronline-2/lib/x86_64, /system/lib64, /vendor/lib64]]] couldn't find "libnative-lib.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1530)
at com.example.musicplayeronline.ContactsActivity.<clinit>(ContactsActivity.java:24)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2538)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

java.lang.IllegalStateException: Required view not found even after setContentView()

I am facing a weird problem related to view not found but everything seems to be right with the code (at least to me). Infact the program was working fine till some time back. I am not sure what change that i made causing this issue. Could anyone of you point me the problem? Thank you.
The below is the exception trace:
FATAL EXCEPTION: main
Process: co.mycompany, PID: 3923
java.lang.RuntimeException: Unable to start activity ComponentInfo{co.mycompany/co.mycompany.activities.MainActivity}: java.lang.RuntimeException: Unable to bind views for co.mycompany.activities.MainActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5065)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to bind views for co.mycompany.activities.MainActivity
at butterknife.ButterKnife.bind(ButterKnife.java:322)
at butterknife.ButterKnife.bind(ButterKnife.java:237)
at co.mycompany.activities.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2165)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250) 
at android.app.ActivityThread.access$800(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5065) 
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:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.IllegalStateException: Required view 'thUserProfilePic' with ID 2131558656 for field 'mUserProfilePic' was not found. If this view is optional add '#Nullable' annotation.
at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:140)
at co.mycompany.activities.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:17)
at co.mycompany.activities.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:8)
at butterknife.ButterKnife.bind(ButterKnife.java:319)
at butterknife.ButterKnife.bind(ButterKnife.java:237) 
at co.mycompany.activities.MainActivity.onCreate(MainActivity.java:51) 
at android.app.Activity.performCreate(Activity.java:5249) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2165) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250) 
at android.app.ActivityThread.access$800(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5065) 
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:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
at dalvik.system.NativeStart.main(Native Method) 
MainActivity.class
#Bind(R.id.thUserProfilePic)
CircleImageView mUserProfilePic;
#Bind(R.id.thUserDisplayName)
TextView mUserDisplayName;
#Bind(R.id.editProfileLink)
ImageView editProfileLink;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerLayout.setDrawerListener(toggle);
toggle.syncState();
mNavigationView.setNavigationItemSelectedListener(this);
navigate(AppScreen.HOME);
}
R.layout.activity_main
<?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/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">
<include layout="#layout/app_bar_main" android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView android:id="#+id/nav_view"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main" app:menu="#menu/activity_main_drawer"
android:background="#color/white"/>
</android.support.v4.widget.DrawerLayout>
R.layout.nav_header_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/editProfileLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_edit_white_24dp"
android:layout_gravity="end|right"/>
<include layout="#layout/user_thumbnail_large"/>
</LinearLayout>
R.layout.user_thumnail_large
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:id="#+id/userThumbnailLargeContainer">
<de.hdodenhof.circleimageview.CircleImageView android:layout_width="75dp" android:layout_height="75dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:src="#drawable/ic_face_white_48dp" android:id="#+id/thUserProfilePic" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing" android:text="John"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:id="#+id/thUserDisplayName"
android:textColor="#color/textColorSecondary"/>
</LinearLayout>
I am into second day of research and could not able to figure out what the issue is.
The issue is with support Library version. I was getting the above error since i upgraded support library to 23 version.
The below link has the solution.
NavigationView get/find header layout

android.view.InflateException: Binary XML file line #2: Error inflating class

When i click imgPlayGame -> Open new activity -> Error
My Main:
ImageView imgPlayGame;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.start_game);
AddEvents();
}
My Events:
public void AddEvents(){
imgPlayGame=(ImageView) findViewById(R.id.imgPlayGame);
//repeat imgPlayGame
Start_Repeat_ImgPlayGame();
imgPlayGame.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
StartGame();
}
});
}
Animation Drawable:
public void Start_Repeat_ImgPlayGame(){
imgPlayGame.setBackgroundResource(R.drawable.play_anim_repeat);
animationDrawable= (AnimationDrawable) imgPlayGame.getBackground();
animationDrawable.start();
}
Open new activity:
protected void StartGame() {
Intent select_level= new Intent(StartGameActivity.this, SelectLevelActivity.class);
startActivity(select_level);
}
Class play_anim_repeat:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/ic_play_2"
android:duration="300"
>
</item>
<item
android:drawable="#drawable/ic_play_3"
android:duration="300">
</item>
<item
android:drawable="#drawable/ic_play_4"
android:duration="300">
</item>
</animation-list>
Error:
11-30 16:14:16.476: E/dalvikvm-heap(11347): Out of memory on a 30025744-byte allocation. 11-30 16:14:16.491: E/AndroidRuntime(11347):
FATAL EXCEPTION: main 11-30 16:14:16.491: E/AndroidRuntime(11347):
Process: com.thoai.leminh.huntervsfruit, PID: 11347 11-30
16:14:16.491: E/AndroidRuntime(11347): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.thoai.leminh.huntervsfruit/com.thoai.leminh.huntervsfruit.EasyLevelActivity}:
android.view.InflateException: Binary XML file line #2: Error
inflating class 11-30 16:14:16.491: E/AndroidRuntime(11347):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.app.ActivityThread.access$900(ActivityThread.java:161) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.os.Handler.dispatchMessage(Handler.java:102) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.os.Looper.loop(Looper.java:157) 11-30 16:14:16.491:
E/AndroidRuntime(11347): at
android.app.ActivityThread.main(ActivityThread.java:5356) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
java.lang.reflect.Method.invokeNative(Native Method) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
java.lang.reflect.Method.invoke(Method.java:515) 11-30 16:14:16.491:
E/AndroidRuntime(11347): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
dalvik.system.NativeStart.main(Native Method) 11-30 16:14:16.491:
E/AndroidRuntime(11347): Caused by: android.view.InflateException:
Binary XML file line #2: Error inflating class 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.view.LayoutInflater.createView(LayoutInflater.java:626) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.view.LayoutInflater.inflate(LayoutInflater.java:470) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.view.LayoutInflater.inflate(LayoutInflater.java:398) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.view.LayoutInflater.inflate(LayoutInflater.java:354) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.app.Activity.setContentView(Activity.java:2010) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
com.thoai.leminh.huntervsfruit.EasyLevelActivity.onCreate(EasyLevelActivity.java:20)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.app.Activity.performCreate(Activity.java:5426) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
11-30 16:14:16.491: E/AndroidRuntime(11347): ... 11 more 11-30
16:14:16.491: E/AndroidRuntime(11347): Caused by:
java.lang.reflect.InvocationTargetException 11-30 16:14:16.491:
E/AndroidRuntime(11347): at
java.lang.reflect.Constructor.constructNative(Native Method) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
java.lang.reflect.Constructor.newInstance(Constructor.java:423) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.view.LayoutInflater.createView(LayoutInflater.java:600) 11-30
16:14:16.491: E/AndroidRuntime(11347): ... 23 more 11-30
16:14:16.491: E/AndroidRuntime(11347): Caused by:
java.lang.OutOfMemoryError 11-30 16:14:16.491:
E/AndroidRuntime(11347): at
android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.content.res.Resources.loadDrawable(Resources.java:3024) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.content.res.TypedArray.getDrawable(TypedArray.java:602) 11-30
16:14:16.491: E/AndroidRuntime(11347): at
android.view.View.(View.java:3694) 11-30 16:14:16.491:
E/AndroidRuntime(11347): at android.view.View.(View.java:3624)
11-30 16:14:16.491: E/AndroidRuntime(11347): at
android.view.ViewGroup.(ViewGroup.java:474) 11-30 16:14:16.491:
E/AndroidRuntime(11347): at
android.widget.RelativeLayout.(RelativeLayout.java:236) 11-30
16:14:16.491: E/AndroidRuntime(11347): ... 26 more
Your image #drawable/backgound_easy is probably is too large. Try to use another one
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

InflateException while LayoutInflater.inflate

Code crashes at second line:
LayoutInflater li = LayoutInflater.from(MyContext);
vView = li.inflate(R.layout.video, null);
Layout - video.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/GridItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:background="#000080">
<imageview android:id="#+id/grid_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</imageview>
<textview android:id="#+id/grid_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColor="#000000">
</textview>
</linearlayout>
Call Stack:
07-15 16:40:57.909: WARN/dalvikvm(7936): threadid=1: thread exiting with uncaught exception (group=0x40018560)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): FATAL EXCEPTION: main
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): android.view.InflateException: Binary XML file line #1: Error inflating class linearlayout
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at com.nitin.videosurf.VideoAdapter.getView(VideoAdapter.java:71)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.widget.AbsListView.obtainView(AbsListView.java:1456)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.widget.GridView.onMeasure(GridView.java:944)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.os.Looper.loop(Looper.java:123)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.app.ActivityThread.main(ActivityThread.java:3806)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at java.lang.reflect.Method.invoke(Method.java:507)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at dalvik.system.NativeStart.main(Native Method)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): Caused by: java.lang.ClassNotFoundException: android.view.linearlayout in loader dalvik.system.PathClassLoader[/data/app/com.nitin.videosurf-2.apk]
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): ... 26 more
It was simple and stupid issue: <linearlayout> <imageview> <textview> etc needs to capitalized to <LinearLayout> <ImageView> <TextView>.

Resources