Android - MediaController leaking on activity - android

I am using MediaPlayer and MediaController objects to stream audio. When closing the activity I am getting a window leaked exception.
I have the following in my activity which doesn't help at all.
#Override
protected void onStop() {
super.onStop();
mediaController.hide();
}
I get the following stack trace:
01-24 20:11:18.317: E/WindowManager(26286): Activity
co.uk.ing_simmons.aberdeensoundsites.RecordingDetails has leaked
window com.android.internal.policy.impl.PhoneWindow$DecorView#4182d590
that was originally added here 01-24 20:11:18.317:
E/WindowManager(26286): android.view.WindowLeaked: Activity
co.uk.ing_simmons.aberdeensoundsites.RecordingDetails has leaked
window com.android.internal.policy.impl.PhoneWindow$DecorView#4182d590
that was originally added here 01-24 20:11:18.317:
E/WindowManager(26286): at
android.view.ViewRootImpl.(ViewRootImpl.java:418) 01-24
20:11:18.317: E/WindowManager(26286): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:294)
01-24 20:11:18.317: E/WindowManager(26286): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:226)
01-24 20:11:18.317: E/WindowManager(26286): at
android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:151)
01-24 20:11:18.317: E/WindowManager(26286): at
android.view.Window$LocalWindowManager.addView(Window.java:547) 01-24
20:11:18.317: E/WindowManager(26286): at
android.widget.MediaController.show(MediaController.java:470) 01-24
20:11:18.317: E/WindowManager(26286): at
android.widget.MediaController.show(MediaController.java:429) 01-24
20:11:18.317: E/WindowManager(26286): at
co.uk.ing_simmons.aberdeensoundsites.RecordingDetails$2.run(RecordingDetails.java:202)
01-24 20:11:18.317: E/WindowManager(26286): at
android.os.Handler.handleCallback(Handler.java:615) 01-24
20:11:18.317: E/WindowManager(26286): at
android.os.Handler.dispatchMessage(Handler.java:92) 01-24
20:11:18.317: E/WindowManager(26286): at
android.os.Looper.loop(Looper.java:153) 01-24 20:11:18.317:
E/WindowManager(26286): at
android.app.ActivityThread.main(ActivityThread.java:5006) 01-24
20:11:18.317: E/WindowManager(26286): at
java.lang.reflect.Method.invokeNative(Native Method) 01-24
20:11:18.317: E/WindowManager(26286): at
java.lang.reflect.Method.invoke(Method.java:511) 01-24 20:11:18.317:
E/WindowManager(26286): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
01-24 20:11:18.317: E/WindowManager(26286): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) 01-24
20:11:18.317: E/WindowManager(26286): at
dalvik.system.NativeStart.main(Native Method) 01-24 20:11:18.325:
E/InputEventReceiver(26286): channel '41c81858
Panel:co.uk.ing_simmons.aberdeensoundsites/co.uk.ing_simmons.aberdeensoundsites.RecordingDetails
(client)' ~ Publisher closed input channel or an error occurred.
events=0x9
Which seems to point to line 202 which is this line:
mediaController.show();
I have been Googling this for hours now and literally everything says to put "mediaController.hide()" in the onStop method to prevent leaks. Which clearly isn't working so any help or guidance here would be greatly appreciated.
Thanks

You probably want to reverse the lines
super.onStop();
mediaController.hide();
to
mediaController.hide();
super.onStop();

Related

unfortunately dialog has stopped

I used dialog theme in my code but emulator is showing message that Unfortunately dialog has stopped.
Also my AVD Emulator details are as follows:
Nexus 7
API 19
skin: HVGA
Here is my manifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dialog"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog">
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>`
Here is my main.java file
package com.example.dialog;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}`
Here is my log when I launched my app
01-24 12:56:23.232: I/ActivityManager(383): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.dialog/.MainActivity} from pid 546
01-24 12:56:23.322: E/gralloc_goldfish(55): gralloc_alloc: Mismatched usage flags: 164 x 246, usage 333
01-24 12:56:23.322: W/GraphicBufferAllocator(55): alloc(164, 246, 1, 00000333, ...) failed -22 (Invalid argument)
01-24 12:56:23.322: E/(55): GraphicBufferAlloc::createGraphicBuffer(w=164, h=246) failed (Invalid argument), handle=0x0
01-24 12:56:23.322: E/BufferQueue(383): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
01-24 12:56:23.332: W/WindowManager(383): Screenshot failure taking screenshot for (164x246) to layer 21005
01-24 12:56:23.432: D/dalvikvm(383): GC_FOR_ALLOC freed 735K, 23% free 6131K/7904K, paused 74ms, total 84ms
01-24 12:56:23.452: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.452: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.452: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.452: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.462: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.462: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.462: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:23.482: E/SoundPool(383): error loading /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:23.482: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:23.482: W/AudioService(383): onLoadSoundEffects(), Error -1 while loading samples
01-24 12:56:23.642: I/ActivityManager(383): Start proc com.example.dialog for activity com.example.dialog/.MainActivity: pid=1298 uid=10053 gids={50053}
01-24 12:56:23.692: D/dalvikvm(1298): Not late-enabling CheckJNI (already on)
01-24 12:56:24.172: D/AndroidRuntime(1298): Shutting down VM
01-24 12:56:24.172: W/dalvikvm(1298): threadid=1: thread exiting with uncaught exception (group=0xb2a2bba8)
01-24 12:56:24.242: E/AndroidRuntime(1298): FATAL EXCEPTION: main
01-24 12:56:24.242: E/AndroidRuntime(1298): Process: com.example.dialog, PID: 1298
01-24 12:56:24.242: E/AndroidRuntime(1298): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dialog/com.example.dialog.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.ActivityThread.access$800(ActivityThread.java:135)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.os.Handler.dispatchMessage(Handler.java:102)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.os.Looper.loop(Looper.java:136)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.ActivityThread.main(ActivityThread.java:5017)
01-24 12:56:24.242: E/AndroidRuntime(1298): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 12:56:24.242: E/AndroidRuntime(1298): at java.lang.reflect.Method.invoke(Method.java:515)
01-24 12:56:24.242: E/AndroidRuntime(1298): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-24 12:56:24.242: E/AndroidRuntime(1298): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-24 12:56:24.242: E/AndroidRuntime(1298): at dalvik.system.NativeStart.main(Native Method)
01-24 12:56:24.242: E/AndroidRuntime(1298): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
01-24 12:56:24.242: E/AndroidRuntime(1298): at com.example.dialog.MainActivity.onCreate(MainActivity.java:12)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.Activity.performCreate(Activity.java:5231)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-24 12:56:24.242: E/AndroidRuntime(1298): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
01-24 12:56:24.242: E/AndroidRuntime(1298): ... 11 more
01-24 12:56:24.282: W/ActivityManager(383): Force finishing activity com.example.dialog/.MainActivity
01-24 12:56:24.322: W/InputMethodManagerService(383): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#b2f48420 attribute=null, token = android.os.BinderProxy#b2ff3050
01-24 12:56:24.852: W/ActivityManager(383): Activity pause timeout for ActivityRecord{b304dbc0 u0 com.example.dialog/.MainActivity t6 f}
01-24 12:56:29.172: I/Process(1298): Sending signal. PID: 1298 SIG: 9
01-24 12:56:29.182: I/ActivityManager(383): Process com.example.dialog (pid 1298) has died.
01-24 12:56:29.262: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.262: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.332: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.332: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.382: E/SoundPool(383): error loading /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:29.382: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:29.382: E/SoundPool(383): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:29.392: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:29.392: E/SoundPool(383): error loading /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:29.402: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:29.402: E/SoundPool(383): error loading /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:29.432: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:29.442: E/SoundPool(383): error loading /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:29.442: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:29.442: W/AudioService(383): onLoadSoundEffects(), Error -1 while loading samples
01-24 12:56:29.512: W/InputMethodManagerService(383): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#b2d153c8 attribute=null, token = android.os.BinderProxy#b2ff3050
This is my Styles.xml file
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
You're inheriting ActionBarActivity which (as the log suggests) requires you to use the AppCompat theme.
Set your styles.xml to this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
Edit:
Also, in your manifest remove this:
android:theme="#android:style/Theme.Dialog">
Otherwise use a different activity class, e.g. Activity.

Rare crash when using fragments with unique id's

I have a very unusual crash that happens maybe once a month or so. There doesn't seem to be any rhyme or reason to it. This is part of a large project, and since I'm not sure where exactly the problem is originating, I'm not sure which portions of code to paste here. So instead I will just describe what I am doing, and I think might be causing the crash.
I have an activity with many nested fragments that I manage with the FragmentManager. Because the nested fragments can be of the same type, I have to give the root view of each fragment a unique ID. The app is crashing when calling super.onResume, and that call is the very first line of my overloaded onResume function (so my code is never given the chance to mess anything up). The reason I think it is crashing due to the unique fragment id's is because I started having this problem after moving to unique id's, and the crash always references a low number resource id.
This error seems to be being thrown in the framework itself, so I'm not sure there is anything I can do about it. Has anyone else come across this, and have the figured out a solution for it? Or alternatively, does anyone know if you can surround super.onResume with a try/catch block? I'm not sure whether the app would be able to recover at that point, and there does not seem to be any way to consistently reproduce this error in order to test it.
01-24 20:55:09.602 E/AndroidRuntime( 8156): FATAL EXCEPTION: main
01-24 20:55:09.602 E/AndroidRuntime( 8156): java.lang.RuntimeException: Unable to resume activity {github.daneren2005.dsub/github.daneren2005.dsub.activity.SubsonicFragmentActivity}: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x2
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3014)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3055)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.access$600(ActivityThread.java:151)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.os.Looper.loop(Looper.java:155)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.main(ActivityThread.java:5454)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at java.lang.reflect.Method.invoke(Method.java:511)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at dalvik.system.NativeStart.main(Native Method)
01-24 20:55:09.602 E/AndroidRuntime( 8156): Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x2
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.content.res.Resources.getResourceName(Resources.java:1666)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:445)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at github.daneren2005.dsub.activity.SubsonicActivity.onResume(SubsonicActivity.java:130)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at github.daneren2005.dsub.activity.SubsonicFragmentActivity.onResume(SubsonicFragmentActivity.java:250)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1266)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.Activity.performResume(Activity.java:5148)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2997)
01-24 20:55:09.602 E/AndroidRuntime( 8156): ... 12 more
01-24 20:55:09.602 W/ActivityManager( 596): Force finishing activity github.daneren2005.dsub/.activity.SubsonicFragmentActivity
Edit: Added unique id generation. In onCreateView I use rootView.setId(rootId):
public SelectDirectoryFragment() {
super();
rootId = getNewId();
}
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if(bundle != null) {
int tmp = bundle.getInt(Constants.FRAGMENT_ID, -1);
if(tmp > 0) {
rootId = tmp;
}
entries = (List<MusicDirectory.Entry>) bundle.getSerializable(Constants.FRAGMENT_LIST);
restoredInstance = true;
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(Constants.FRAGMENT_ID, rootId);
outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) entries);
}
protected int getNewId() {
for (;;) {
final int result = nextGeneratedId.get();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that.
int newValue = result + 1;
if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
if (nextGeneratedId.compareAndSet(result, newValue)) {
return result;
}
}
}
Check anywhere in your Fragment or Activity that you might be doing a setText() call. It's possible you're trying to set the text to the String.valueOf() value of an integer, but setText() also has an overload which takes an integer resource value (e.g. R.string.my_string). I've seen this crash when I mistakenly did something like the following:
int myCount = doSomeCalculation();
textView.setText(myCount);
This will internally try to resolve myCount as a resource (e.g. getString(myCount)) rather than setting the text to the string value of the myCount variable.
EDIT: Wait, how are you setting this unique ID on your Fragment's root?

illegarlargumentexception in inflating library in popup window

I'm working on showing emoji in popup window just like whatsapp from this library. I have created a popup window to show it in main activity. On click of button I made the following code
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
View popUp = getLayoutInflater().inflate(R.layout.popup_item, null);
window = new PopupWindow(getApplicationContext());
window = new PopupWindow(popUp,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,true);
window.setAnimationStyle(android.R.style.Animation_Activity);
window.showAtLocation(popUp, Gravity.BOTTOM, 0, 0);
window.setFocusable(true);
window.setOutsideTouchable(true);
}
});
The popup_item contain the following
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:emojicon="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.rockerhieu.emojicon.example.MainActivity$PlaceholderFragment" >
<com.rockerhieu.emojicon.EmojiconTextView
android:id="#+id/txtEmojicon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<com.rockerhieu.emojicon.EmojiconEditText
android:id="#+id/editEmojicon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
emojicon:emojiconSize="28sp" />
<fragment
android:id="#+id/emojicons"
android:layout_width="fill_parent"
android:layout_height="220dp"
class="com.rockerhieu.emojicon.EmojiconsFragment" />
</LinearLayout>
it is showing the following error.
01-24 01:07:25.245: E/AndroidRuntime(5420): FATAL EXCEPTION: main
01-24 01:07:25.245: E/AndroidRuntime(5420): android.view.InflateException: Binary XML file line #21: Error inflating class fragment
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-24 01:07:25.245: E/AndroidRuntime(5420): at com.example.popupemoji.MainActivity$1.onClick(MainActivity.java:29)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.View.performClick(View.java:4204)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.View$PerformClick.run(View.java:17355)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.os.Handler.handleCallback(Handler.java:725)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.os.Handler.dispatchMessage(Handler.java:92)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.os.Looper.loop(Looper.java:137)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-24 01:07:25.245: E/AndroidRuntime(5420): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 01:07:25.245: E/AndroidRuntime(5420): at java.lang.reflect.Method.invoke(Method.java:511)
01-24 01:07:25.245: E/AndroidRuntime(5420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-24 01:07:25.245: E/AndroidRuntime(5420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-24 01:07:25.245: E/AndroidRuntime(5420): at dalvik.system.NativeStart.main(Native Method)
01-24 01:07:25.245: E/AndroidRuntime(5420): Caused by: java.lang.IllegalArgumentException: Binary XML file line #21: Duplicate id 0x7f080000, tag null, or parent id 0x0 with another fragment for com.rockerhieu.emojicon.EmojiconsFragment
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
I found that the reason for it is the nested fragment. But don't know the solution for it. Please help on this. I really need to solve this. I'm new to android. Thanks.

Good dynamics fatal exception from sample app

Has anyone encountered this error while trying to use Good Dynamics sample applications from their SDK?
It has me stumped as i have included the what should be all the necessary files
01-24 06:28:21.463: E/AndroidRuntime(1436): FATAL EXCEPTION: main
01-24 06:28:21.463: E/AndroidRuntime(1436): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.good.gd.example.policy/com.good.gd.example.policy.ApplicationPolicy}: java.lang.ClassNotFoundException: Didn't find class "com.good.gd.example.policy.ApplicationPolicy" on path: DexPathList[[zip file "/data/app/com.good.gd.example.policy-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.good.gd.example.policy-2, /vendor/lib, /system/lib]]
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.os.Looper.loop(Looper.java:137)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.reflect.Method.invoke(Method.java:525)
01-24 06:28:21.463: E/AndroidRuntime(1436): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-24 06:28:21.463: E/AndroidRuntime(1436): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-24 06:28:21.463: E/AndroidRuntime(1436): at dalvik.system.NativeStart.main(Native Method)
01-24 06:28:21.463: E/AndroidRuntime(1436): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.good.gd.example.policy.ApplicationPolicy" on path: DexPathList[[zip file "/data/app/com.good.gd.example.policy-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.good.gd.example.policy-2, /vendor/lib, /system/lib]]
01-24 06:28:21.463: E/AndroidRuntime(1436): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
01-24 06:28:21.463: E/AndroidRuntime(1436): ... 11 more
Yeah, first you need to import project from good sdk folder in extras folder of Android SDK folder, then in gd folder...import the project in workspace, then whenevr you try to run any app on Good Technology, create dependency on that imported project. then you dont get exception. Hope this helps you.

Classnotfound exception even when there is class declared

My app runs fine when i run it through eclipse, but when i export it and then install it through adb install and run, it crashes with following stacktrace.
basically, it says that main launcher activity not found, although it is declared, and is set to main activity with launcher category:
Stacktrace:
01-24 11:50:59.029: E/AndroidRuntime(7768): Uncaught handler: thread main exiting due to uncaught exception
01-24 11:50:59.299: E/AndroidRuntime(7768): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.nitinbansal85.android.carplexindia/com.nitinbansal85.android.carplexindia.ActivityDashboard}: java.lang.ClassNotFoundException: com.nitinbansal85.android.carplexindia.ActivityDashboard in loader dalvik.system.PathClassLoader#32518de0
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2474)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.app.ActivityThread.access$2200(ActivityThread.java:125)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1914)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.os.Looper.loop(Looper.java:123)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.app.ActivityThread.main(ActivityThread.java:4420)
01-24 11:50:59.299: E/AndroidRuntime(7768): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 11:50:59.299: E/AndroidRuntime(7768): at java.lang.reflect.Method.invoke(Method.java:521)
01-24 11:50:59.299: E/AndroidRuntime(7768): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
01-24 11:50:59.299: E/AndroidRuntime(7768): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
01-24 11:50:59.299: E/AndroidRuntime(7768): at dalvik.system.NativeStart.main(Native Method)
01-24 11:50:59.299: E/AndroidRuntime(7768): Caused by: java.lang.ClassNotFoundException: com.nitinbansal85.android.carplexindia.ActivityDashboard in loader dalvik.system.PathClassLoader#32518de0
01-24 11:50:59.299: E/AndroidRuntime(7768): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-24 11:50:59.299: E/AndroidRuntime(7768): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-24 11:50:59.299: E/AndroidRuntime(7768): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-24 11:50:59.299: E/AndroidRuntime(7768): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2466)
01-24 11:50:59.299: E/AndroidRuntime(7768): ... 11 more
01-24 11:51:01.369: E/msm7k.gralloc(1281): [unregister] handle 0x43bf20 still locked (state=40000001)
Im also using facebook sdk, and airpush and startApp sdk's, and have included them in order import/export
Any suggestions whats going wrong?
thanx in advance
EDIT
Forget to mention that i had renamed my project and folder that contained it.
For an android app, I'd same issue with an external jar file. In my case the solution was to move the jar from "lib" folder to the android default "libs" folder.
When the jar was in lib folder (was added to build path as well), while there are was no build issue in Eclipse, the app was giving ClassNotFoundException at runtime. Once I moved the jar to "libs" folder, the jar started appearing under "Android Dependencies" and app started working fine.
These are some of the other discussions about the same topic.
1)http://stackoverflow.com/questions/3642928/adding-a-library-jar-to-an-eclipse- android-project
2)http://stackoverflow.com/questions/7185488/android-what-is-the-folder-name-of-the-jar-files-lib-or-libs
3)http://stackoverflow.com/questions/2611105/how-to-specify-lib-folder-for-jars-when-using-android-generated-ant-build-file
may this could help...!!!!!
As the Stacktrace tells that android first starts the NewActivity -> LoadClass -> FindClass -> ClassNotFoundException, could be:
wrong package declaration in Manifest(com.nitinbansal85.android.carplexindia.ActivityDashboard)
Android Debug Bridge(ADB) apk creation problem.
Failed to load other jars from libs
You can also try compiling the project from eclipse and use .apk directly from bin directory of your project and check the difference.

Categories

Resources