YouTubePlayer together with AppCompat v7 library - android

I have developed an app that uses YouTube android API to play a certain video inside the app. At that time I have used as target API 19, and also target API 19. Now I want do change the design of the app switching to Material Design using target API 22 and also using AppCompat-v7 :22+ library. But the YouTubeBaseActivity cant be opened and the application crashes. Below I will post what I have done so far.
EventDetail.java
public class EventDetail extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener { .
.
.
protected void onCreate(Bundle savedInstanceState) {
// remove the shadow from action bar
setTheme(R.style.Theme_TranslucentActionBar_ActionBar_NoOverlay);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event_detail);
// enable back button
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// setting the action bar initially transparent
mActionBarBackgroundDrawable = new ColorDrawable(
Color.parseColor("#ec5c59"));
mActionBarBackgroundDrawable.setAlpha(0);
getSupportActionBar().setBackgroundDrawable(mActionBarBackgroundDrawable);
// binding the scrollview
...
Manifest File
<activity
android:name="com.dev.apk.evente.al.EventDetail"
android:icon="#drawable/ikona_projekte"
android:label="#string/title_activity_event_detail"
android:screenOrientation="portrait"
android:theme="#style/Theme.TranslucentActionBar.ActionBar.Overlay" />
Layut File:
<RelativeLayout
android:id="#+id/video_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:paddingLeft="23dp"
android:paddingRight="23dp"
android:paddingBottom="15dp"
android:background="#drawable/event_background_block" >
<TextView
android:id="#+id/video_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/white"
android:gravity="left"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="Video"
android:textColor="#color/VeryDarkGray"
android:textSize="22sp" >
</TextView>
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtube_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/video_label"
android:background="#color/white" />
</RelativeLayout>
Theme.xml File
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.TranslucentActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/Widget.ActionBar</item>
</style>
<style name="Theme.TranslucentActionBar.ActionBar" />
<style name="Theme.TranslucentActionBar.ActionBar.Overlay">
<item name="android:actionBarStyle">#style/Widget.ActionBar.Transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="colorPrimary">#color/evente_date_color</item>
<item name="colorPrimaryDark">#color/evente_darken_color</item>
</style>
<!-- Theme without ActionBar shadow (inherits main theme) -->
<style name="Theme.TranslucentActionBar.ActionBar.NoOverlay" parent="Theme.TranslucentActionBar.ActionBar.Overlay">
<item name="android:windowContentOverlay">#null</item>
</style>
</resources>
So at the beginning it doesn't open because the method getActionBar() return Null, then i changed it to getSupportActionBar() but i doesn't recognized it. Then at the end I changed this line in the following:
public class EventDetail extends AppCompatActivity implements
YouTubePlayer.OnInitializedListener {
and it gives me the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myikub.al/com.dev.apk.evente.al.EventDetail}: android.view.InflateException: Binary XML file line #250: Error inflating class com.google.android.youtube.player.YouTubePlayerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5406)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #250: Error inflating class com.google.android.youtube.player.YouTubePlayerView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
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.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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.dev.apk.evente.al.EventDetail.onCreate(EventDetail.java:112)
at android.app.Activity.performCreate(Activity.java:5303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2296)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5406)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
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.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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.dev.apk.evente.al.EventDetail.onCreate(EventDetail.java:112)
at android.app.Activity.performCreate(Activity.java:5303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2296)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5406)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: A YouTubePlayerView can only be created with an Activity which extends YouTubeBaseActivity as its context.
at com.google.android.youtube.player.YouTubePlayerView.<init>(Unknown Source)
....
I am using Android Studio. Any idea will be appreciated.

The problem is that you're using the YouTubePlayerView, which requires your Activity to extend YouTubeBaseActivity. Then you changed your activity, so that it now extends AppCompatActivity. This breaks YouTubePlayerView.
The solution is pretty simple: use the YouTubePlayerFragment class. This does not pose any requirement on the Activity, leaving you with plenty of options for your theming.

According to the stack trace the activity has to extend YouTubeBaseActivity when using the YouTube API
If you need to have an actionbar then I think the best route is to change the style to have no actionbar and just use a toolbar in your view.

paste this code inside gradle app
compile 'com.google.android.gms:play-services:8.4.0'
compile files('libs/YouTubeAndroidPlayerApi.jar')

Related

Resource not found exception in android 4.2.2

I have created a theme for splash screen on style.xml file.
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_background_96dp</item>
</style>
The splash_background_96dp is a xml drawable.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorWhite"/>
<item android:gravity="center">
<bitmap
android:gravity="fill_horizontal|fill_vertical"
android:src="#drawable/logo1"/>
</item>
</layer-list>
The logo1 is a png file.
I use this theme for splash screen activity in my app. It works on android 7.1.0 but on android 4.2.2 the below exception occurs:
03-04 15:31:02.849 14225-14225/com.sarsabad.sarsabadmanager E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sarsabad.sarsabadmanager/com.sarsabad.sarsabadmanager.ui.SplashActivity}: android.content.res.Resources$NotFoundException: File res/drawable/splash_background_96dp.xml from drawable resource ID #0x7f0700e4
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_background_96dp.xml from drawable resource ID #0x7f0700e4
at android.content.res.Resources.loadDrawable(Resources.java:2842)
at android.content.res.Resources.getDrawable(Resources.java:1521)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:360)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:85)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:128)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70)
at com.sarsabad.sarsabadmanager.ui.SplashActivity.onCreate(SplashActivity.java:39)
at android.app.Activity.performCreate(Activity.java:5283)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299) 
at android.app.ActivityThread.access$700(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5283) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #7: <bitmap> requires a valid src attribute
at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:454)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:921)
at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:165)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:921)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)
at android.content.res.Resources.loadDrawable(Resources.java:2839)
at android.content.res.Resources.getDrawable(Resources.java:1521) 
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:360) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198) 
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:85) 
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:128) 
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149) 
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29) 
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183) 
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519) 
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70) 
at com.sarsabad.sarsabadmanager.ui.SplashActivity.onCreate(SplashActivity.java:39) 
at android.app.Activity.performCreate(Activity.java:5283) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299) 
at android.app.ActivityThread.access$700(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5283) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
at dalvik.system.NativeStart.main(Native Method) 
In order to make the logo1 file available, you need to put the image into your drawable folder to be accessed for all Android versions. As I guessed it correctly, the image was in other folder with a higher qualifier (i.e. drawable-v21 in your case).

CAST - Error inflating class android.widget.ImageButton

I have been using ChromeCast in my application before and it was working great. Recently I added Google Cloud Messaging in my application too, and for that I had to update dependency files to
'com.google.android.gms:play-services-cast:8.3.0' and 'com.google.android.gms:play-services-gcm:8.3.0'. But now when client disconnects chromecast we get the following fatal exceptions and the application crashes.
11-23 12:42:49.415 22117-22117/com.jadoo.jadooplus E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.jadoo.jadooplus, PID: 22117
android.view.InflateException: Binary XML file line #36: Error inflating class android.widget.ImageButton
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
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 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:315)
at android.app.Dialog.setContentView(Dialog.java:512)
at android.support.v7.app.MediaRouteControllerDialog.onCreate(MediaRouteControllerDialog.java:178)
at android.app.Dialog.dispatchOnCreate(Dialog.java:396)
at android.app.Dialog.show(Dialog.java:268)
at android.support.v4.app.DialogFragment.onStart(DialogFragment.java:399)
at android.support.v4.app.Fragment.performStart(Fragment.java:1813)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:989)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
preceded by an InvocationTargetException and Resources$NotFoundException.
Even now when I change the version anywhere below 7.5.x the code works great. Any ideas why ImageButton is not drawable. I've spent a day at following the stacktrace and today surfing the web, no luck. I haven't found anything useful on the topic.
I applologize for not posting stacktrace from other exception' stacktrace but I can't add more in formatted code.
Edit 1: I can't seem to add any more code here so here's a snapshot:
Edit 2:
I have already tried disabling Proguard, with no effect. The issue persists on a LG G2 d802, a range of Samsung Tabs and Nexus 7. Also I am not using CastCompanionLibrary.

At first install the app crashes, but after reinstall it works

I have never met so strange issue so far.
The app compiles fine. But at first run it crashes on the test device, but if the project is cleaned and re-run the app works fine.
If I try to install the apk the result is the same: installing the app crashes but after reinstalling it runs fine.
The issue is happening on all of my test devices and under Eclipss and Android Studio. I spent many hours to find a similar case but no avail.
The previous version of the app worked fine, but if I revert the files to an earlier version the issue remains.
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
My guess something went wrong with project set up but could not find the culprit. Deleting the bin folder, making countless project cleaning and restarts did not lead anywhere ...
The full stack trace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.plexnor.android.good/com.plexnor.android.good.CaptureActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class com.plexnor.android.good.ViewfinderView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2425)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5506)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class com.plexnor.android.good.ViewfinderView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:463)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
at android.app.Activity.setContentView(Activity.java:2010)
at com.plexnor.android.good.CaptureActivity.onCreate(SourceFile:317)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:565)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
... 22 more
android.view.InflateException: Binary XML file line #17: Error inflating class com.plexnor.android.good.ViewfinderView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:463)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
at android.app.Activity.setContentView(Activity.java:2010)
at com.plexnor.android.good.CaptureActivity.onCreate(SourceFile:317)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5506)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:565)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
... 22 more
java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:565)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:463)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
at android.app.Activity.setContentView(Activity.java:2010)
at com.plexnor.android.good.CaptureActivity.onCreate(SourceFile:317)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5506)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
EDIT 1:
The app crashes earlier even entering the main activity when processing the layout.
The beginning of the layout:
<?xml version="1.0" encoding="UTF-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<SurfaceView
android:id="#+id/preview_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="#+id/relative_layout_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp" >
<RelativeLayout
android:id="#+id/learning_swipe_relative_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:background="#android:color/transparent" >
<ImageView
android:id="#+id/learningSwipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:padding="30dp"
android:src="#drawable/swipe" />
</RelativeLayout>
<com.plexnor.android.good.ViewfinderView
android:id="#+id/viewfinder_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="#+id/learning_relative_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#android:color/transparent" >
Whats your logcat throws
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.plexnor.android.good.ViewfinderView"
ClassNotFoundException in Java is a subclass of java.lang.Exception and Comes when Java Virtual Machine tries to load a particular class and doesn't found the requested class in classpath.
Another important point about this Exception is that, It is a checked Exception and you need to provide explicitly Exception handling while using methods which can possibly throw classnotfoundexception in java either by using try-catch block or by using throws clause.
Solution
Check whether your classpath contains that jar, if your classpath
doesn't contain the jar then just add that class in your classpath.
Because I could not solve the issue I suspended that project for some months. Using Eclipse in my another project the same issue emerged after including a third party SDK to the project.
Cleaning project, changing things in build path did not help. So, I cloned the project to a new workspace and added the SDK ... and it worked that way. After trying out the old abandoned project it worked out of the box. Thus I think the issue caused by a bug in the development environment.

Trying to implement Toolbar with AppCompat v21

I'm trying to implement the Toolbar using AppCompat v21 following this guide, http://antonioleiva.com/material-design-everywhere/ however I am unable to launch on KitKat or Lollipop and get the same error message (below). I fully believe I have the theme set up correctly but I am stuck at this point and have been for over a day. I've searched unsuccessfully for the solution so now I'm asking for some help. Thanks!
> 11-29 06:08:46.892 29771-29771/com.chaoticearth.chaoticearth E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.ce.ce, PID: 29771
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ce.ce/com.ce.ce.DrawerActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
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:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.ce.ce.BaseActivity.onCreate(BaseActivity.java:16)
at com.ce.ce.DrawerActivity.onCreate(DrawerActivity.java:92)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5146)
            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:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
Here is my /res/values/themes.xml
<resources>
<style name="CETheme" parent="AppTheme" ></style>
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:colorPrimaryDark">#color/MidnightBlue</item>
<item name="android:colorAccent">#color/LightYellow</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Here is my /res/values-v21/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
<item name="android:colorPrimary">#color/ChaosBlue</item>
<item name="android:colorPrimaryDark">#color/MidnightBlue</item>
<item name="android:colorAccent">#color/LightYellow</item>
<item name="android:statusBarColor">#color/ChaosBlue</item>
</style>
Here is a snippet from my DrawerActivity.java where the error is being thrown:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setActionBarIcon(R.drawable.ic_drawer);
And a snippet from the BaseActivity.java that is being called out:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResource());
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
And finally here is a snippet from my AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/CETheme"
android:name="android.support.multidex.MultiDexApplication">
I finally stumbled onto the reason, in my AndroidManifest I was setting a theme for my DrawerActivity, this was causing the error.
Try replacing android:colorPrimaryDark with colorPrimaryDark and android:colorAccent with colorAccent in your res/values/themes.xml.

Android: Cannot inflate custom view in Robolectric test

So this is a possible duplicate of this question: Testing custom Views with Robolectric
But since that one doesn't have an accepted answer, I'm going to ask again, with my own code examples.
I'm using Robolectric 2.3 to run unit tests on a project which uses a custom view defined in a file called "here_now.xml" as:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<me.ambient.meetup.swiper.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/nearbyPeopleList"
android:listSelector="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
swipe:swipeFrontView="#+id/user_profile_layout"
swipe:swipeBackView="#+id/user_profile_bg"
swipe:swipeDrawableChecked="#drawable/plus"
swipe:swipeDrawableUnchecked="#drawable/minus"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeMode="both"/>
</LinearLayout>
That 'SwipeListView' is a custom view and it has those custom XML attributes. Now, this compiles and runs okay on the app. But when running Robolectric tests involving the parent activity that instantiates that view, I run into inflation errors:
me.ambient.meetup.test.HereNowActivityTest > testEditProfileMenuButton FAILED
android.view.InflateException: XML file /Users/shayak/Documents/SourceCode/MagnetAndroid/magnet-android/meetup/src/main/res/layout/here_now.xml line #-1 (sorry, not yet implemented): Error inflating class me.ambient.meetup.swiper.SwipeListView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
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 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
at android.app.Activity.setContentView(Activity.java:1895)
at me.ambient.meetup.HereNowActivity.init(HereNowActivity.scala:93)
at me.ambient.meetup.HereNowActivity.onCreate(HereNowActivity.scala:34)
at android.app.Activity.performCreate(Activity.java:5133)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:113)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:265)
at org.robolectric.util.ActivityController.create(ActivityController.java:110)
at org.robolectric.util.ActivityController.create(ActivityController.java:120)
at me.ambient.meetup.test.HereNowActivityTest.testEditProfileMenuButton(HereNowActivityTest.scala:25)
Caused by:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createView(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:353)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at com.android.internal.policy.impl.PhoneWindow.$$robo$$PhoneWindow_1a87_setContentView(PhoneWindow.java:267)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)
at android.app.Activity.$$robo$$Activity_c57b_setContentView(Activity.java:1895)
at android.app.Activity.setContentView(Activity.java)
at me.ambient.meetup.HereNowActivity.init(HereNowActivity.scala:93)
at me.ambient.meetup.HereNowActivity.onCreate(HereNowActivity.scala:34)
at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5133)
at android.app.Activity.performCreate(Activity.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
... 6 more
Caused by:
java.lang.RuntimeException: You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use 'swipelist_frontview' and 'swipelist_backview' identifiers
at me.ambient.meetup.swiper.SwipeListView.init(SwipeListView.java:211)
at me.ambient.meetup.swiper.SwipeListView.<init>(SwipeListView.java:159)
... 36 more
I'll also put my Robolectric test here, which is in Scala FWIW:
#Config(manifest = "./src/main/AndroidManifest.xml")
#RunWith(classOf[RobolectricTestRunner])
class HereNowActivityTest extends Asserter with ThreadManipulator {
#Test
def testEditProfileMenuButton(): Unit = {
val activity: HereNowActivity = Robolectric.buildActivity(classOf[HereNowActivity]).create().start().get()
val editProfileItem = activity.findViewById(R.id.action_edit_profile).asInstanceOf[MenuItem]
activity.onOptionsItemSelected(editProfileItem)
val shadowActivity = Robolectric.shadowOf(activity)
val startedIntent = shadowActivity.getNextStartedActivity()
val shadowIntent = Robolectric.shadowOf(startedIntent)
assertEquals(shadowIntent.getComponent().getClassName(), "me.ambient.meetup.EditProfileActivity")
}
}
Does anyone know why I am unable to inflate a custom view when running Robolectric tests, as well as unable to set any of the custom attributes?

Categories

Resources