Even Activity is declare im Manifest but it shows exception - android

I declare my activity in manifest file but it shows exception for me
<activity android:name="BuyClick"></activity>
I did not get what is happening to my manifest file
Exception are as follow
02-04 12:33:52.161: E/AndroidRuntime(1260): FATAL EXCEPTION: main
02-04 12:33:52.161: E/AndroidRuntime(1260): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.kt.pos/com.kt.pos.BuyClick}; have you declared this activity in your AndroidManifest.xml?
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.app.Activity.startActivityForResult(Activity.java:3351)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.app.Activity.startActivityForResult(Activity.java:3312)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.app.Activity.startActivity(Activity.java:3522)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.app.Activity.startActivity(Activity.java:3490)
02-04 12:33:52.161: E/AndroidRuntime(1260): at com.kt.pos.POSMainActivity$1.onFinish(POSMainActivity.java:21)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.os.Looper.loop(Looper.java:137)
02-04 12:33:52.161: E/AndroidRuntime(1260): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-04 12:33:52.161: E/AndroidRuntime(1260): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 12:33:52.161: E/AndroidRuntime(1260): at java.lang.reflect.Method.invoke(Method.java:511)
02-04 12:33:52.161: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-04 12:33:52.161: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-04 12:33:52.161: E/AndroidRuntime(1260): at dalvik.system.NativeStart.main(Native Method)
02-04 12:38:52.231: I/Process(1260): Sending signal. PID: 1260 SIG: 9

It should be either
<activity android:name=".BuyClick"></activity>
or
<activity android:name="com.kt.pos.BuyClick"></activity>
It needs to be fully qualified with the package name or preceded with a "." if it's in the main package.

try this :
<activity android:name="com.kt.pos.BuyClick"></activity>
Always use your package name with activity before defining them in menifest.

Related

OutOfMemoryError when loading an animation .xml

I have the following ImageView:
imageView.setBackgroundResource(R.drawable.create_user);
My create_user drawable looks like this:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="#drawable/create_user_0" android:duration="500" />
<item android:drawable="#drawable/create_user_1" android:duration="500" />
</animation-list>
But when the .xml is being set in imageView.setBacgroundResource(R.drawable.create_user), it launches the following exception:
02-04 10:49:07.994: E/AndroidRuntime(1379): FATAL EXCEPTION: main
02-04 10:49:07.994: E/AndroidRuntime(1379): java.lang.OutOfMemoryError
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.loadDrawable(Resources.java:2988)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.getDrawable(Resources.java:1558)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.loadDrawable(Resources.java:2970)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.getDrawable(Resources.java:1558)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.view.View.setBackgroundResource(View.java:15697)
02-04 10:49:07.994: E/AndroidRuntime(1379): at com.facephi.sdk.ui.FragmentCreatingStructure.onCreateView(FragmentCreatingStructu re.java:29)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.Fragment.performCreateView(Fragment.java:1699)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.BackStackRecord.run(BackStackRecord.java:682)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1455)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.os.Handler.handleCallback(Handler.java:730)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.os.Handler.dispatchMessage(Handler.java:92)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.os.Looper.loop(Looper.java:176)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.ActivityThread.main(ActivityThread.java:5419)
02-04 10:49:07.994: E/AndroidRuntime(1379): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 10:49:07.994: E/AndroidRuntime(1379): at java.lang.reflect.Method.invoke(Method.java:525)
02-04 10:49:07.994: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
02-04 10:49:07.994: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
02-04 10:49:07.994: E/AndroidRuntime(1379): at dalvik.system.NativeStart.main(Native Method)
I have to say that I've been using this animation for a looong time. And yesterday was the first time it started crashing.
I can't imagine what's going on at this point... Can anyone help me find what I'm doing wrong?
NOTE: It says Out of memory on a 638416-byte allocation before the mistake is launched.
NOTE2: It also says this several times before the application crashes.
02-04 11:23:56.179: I/dalvikvm(7266): "Binder_1" prio=5 tid=9 RUNNABLE
02-04 11:23:56.179: I/dalvikvm(7266): | group="main" sCount=0 dsCount=0 obj=0x427f2200 self=0x4192fcd0
02-04 11:23:56.179: I/dalvikvm(7266): | sysTid=7277 nice=0 sched=0/0 cgrp=apps handle=1100151432
02-04 11:23:56.179: I/dalvikvm(7266): | state=R schedstat=( 504400204 75428596 671 ) utm=34 stm=15 core=2
02-04 11:23:56.179: I/dalvikvm(7266): at dalvik.system.NativeStart.run(Native Method)
02-04 11:23:56.179: E/Camera-JNI(7266): Couldn't allocate byte array for JPEG data
02-04 11:23:56.239: I/dalvikvm-heap(7266): Clamp target GC heap from 71.012MB to 64.000MB
02-04 11:23:56.239: D/dalvikvm(7266): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 11:23:56.239: D/dalvikvm(7266): GC_FOR_ALLOC freed 21K, 3% free 63352K/65192K, paused 17ms, total 17ms
02-04 11:23:56.239: I/dalvikvm-heap(7266): Forcing collection of SoftReferences for 460816-byte allocation
02-04 11:23:56.259: I/dalvikvm-heap(7266): Clamp target GC heap from 71.012MB to 64.000MB
02-04 11:23:56.259: D/dalvikvm(7266): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 11:23:56.259: D/dalvikvm(7266): GC_BEFORE_OOM freed 0K, 3% free 63352K/65192K, paused 20ms, total 20ms
02-04 11:23:56.259: E/dalvikvm-heap(7266): Out of memory on a 460816-byte allocation.
Try adding android:largeHeap="true", in the manifest to see if this solves it.
Or Use api inSampleSize of bitmapfactory to sample the images.
I also faced this kind of error once but when I re sized my images it got resolved.
Try to re-size your images.
You can try to resize your images to adapt them to the exact size of the view, as explained here. You can even try using libraries like universal image loader which make this task easier.

findViewById on an ImageView why does setBackgroundColor give NullPointerException

I have a very basic activity with an ImageView of android:id="#+id/imageViewTest"
and then in the OnCreate method calling:
ImageView imageView = (ImageView)findViewById(R.id.imageViewTest);
// Set the background color to white
imageView.setBackgroundColor(Color.WHITE);
this gives error:
10-15 16:36:27.552 29097-29097/org.explore.self.beginner D/dalvikvm﹕ Late-enabling CheckJNI
10-15 16:36:28.017 29097-29097/org.explore.self.beginner D/AndroidRuntime﹕ Shutting down VM
10-15 16:36:28.017 29097-29097/org.explore.self.beginner W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d9b2a0)
10-15 16:36:28.042 29097-29097/org.explore.self.beginner E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.explore.self.beginner/org.selfexplore.android.view.activity.TestActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.selfexplore.android.view.activity.TestActivity.onCreate(TestActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5188)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
            at android.app.ActivityThread.access$700(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4921)
            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:1038)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
            at dalvik.system.NativeStart.main(Native Method)
10-15 16:36:28.062 29097-29097/org.explore.self.beginner I/Process﹕ Sending signal. PID: 29097 SIG: 9
But when I do a
ImageView imageView = new ImageView(this);
it works fine, Why?
PS: I am not able to add the layout code here, so sharing it in this doc: https://docs.google.com/document/d/1fbi3B_hAYUh_C2IwPfInvZ-BG2bgsa4pZoJKj8NBT9o/edit?usp=sharing
Your layout you've set with setContentView() doesn't have a view with id imageViewTest and findViewById() returns null, or you haven't called setContentView() at all.

Android: Can't access to file stored in the SD card

I'm working on an app which reads a .txt file that is stored in the SD card (inside /data/local). The problem I have is that it seems that it can access to the file path, but it can't access the file itself (although it has read and write permissions), it throws a FileNotFoundException.
Here I leave you the code and the log:
String ruta="/data/local/textojson.txt";
System.out.println(ruta);
String cadena="", Jsontx="";
File sd = Environment.getExternalStorageDirectory();
File f = new File(sd.getAbsolutePath(), ruta);
System.out.println(f);
BufferedReader entrada;
try
{
entrada = new BufferedReader(new FileReader(f));
System.out.println(entrada);
try
{
while((cadena=entrada.readLine())!=null)
{
Jsontx=cadena;
}
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
I've added the READ_EXTERNAL_STORAGE permissions to the manifest, and the file really exists in that directory.
02-04 19:26:40.535: E/Trace(20167): error opening trace file: No such file or directory (2)
02-04 19:26:41.055: I/System.out(20167): /data/local/textojson.txt
02-04 19:26:41.066: I/System.out(20167): /mnt/sdcard/data/local/textojson.txt
02-04 19:26:41.066: W/System.err(20167): java.io.FileNotFoundException: /mnt/sdcard/data/local/textojson.txt: open failed: ENOENT (No such file or directory)
02-04 19:26:41.066: W/System.err(20167): at libcore.io.IoBridge.open(IoBridge.java:416)
02-04 19:26:41.075: W/System.err(20167): at java.io.FileInputStream.<init>(FileInputStream.java:78)
02-04 19:26:41.075: W/System.err(20167): at java.io.FileReader.<init>(FileReader.java:42)
02-04 19:26:41.075: W/System.err(20167): at es.example.jsonarchivo.Adapter.<init>(Adapter.java:47)
02-04 19:26:41.075: W/System.err(20167): at es.example.jsonarchivo.MainActivity.onCreate(MainActivity.java:27)
02-04 19:26:41.075: W/System.err(20167): at android.app.Activity.performCreate(Activity.java:5008)
02-04 19:26:41.085: W/System.err(20167): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-04 19:26:41.085: W/System.err(20167): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-04 19:26:41.085: W/System.err(20167): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-04 19:26:41.085: W/System.err(20167): at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-04 19:26:41.085: W/System.err(20167): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-04 19:26:41.085: W/System.err(20167): at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 19:26:41.085: W/System.err(20167): at android.os.Looper.loop(Looper.java:137)
02-04 19:26:41.085: W/System.err(20167): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-04 19:26:41.095: W/System.err(20167): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 19:26:41.105: W/System.err(20167): at java.lang.reflect.Method.invoke(Method.java:511)
02-04 19:26:41.105: W/System.err(20167): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-04 19:26:41.105: W/System.err(20167): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-04 19:26:41.105: W/System.err(20167): at dalvik.system.NativeStart.main(Native Method)
02-04 19:26:41.105: W/System.err(20167): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
02-04 19:26:41.116: W/System.err(20167): at libcore.io.Posix.open(Native Method)
02-04 19:26:41.116: W/System.err(20167): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
02-04 19:26:41.116: W/System.err(20167): at libcore.io.IoBridge.open(IoBridge.java:400)
02-04 19:26:41.125: W/System.err(20167): ... 18 more
02-04 19:26:41.125: D/AndroidRuntime(20167): Shutting down VM
02-04 19:26:41.125: W/dalvikvm(20167): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
02-04 19:26:41.145: E/AndroidRuntime(20167): FATAL EXCEPTION: main
02-04 19:26:41.145: E/AndroidRuntime(20167): java.lang.RuntimeException: Unable to start activity ComponentInfo{es.example.jsonarchivo/es.example.jsonarchivo.MainActivity}: java.lang.NullPointerException
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.os.Looper.loop(Looper.java:137)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-04 19:26:41.145: E/AndroidRuntime(20167): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 19:26:41.145: E/AndroidRuntime(20167): at java.lang.reflect.Method.invoke(Method.java:511)
02-04 19:26:41.145: E/AndroidRuntime(20167): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-04 19:26:41.145: E/AndroidRuntime(20167): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-04 19:26:41.145: E/AndroidRuntime(20167): at dalvik.system.NativeStart.main(Native Method)
02-04 19:26:41.145: E/AndroidRuntime(20167): Caused by: java.lang.NullPointerException
02-04 19:26:41.145: E/AndroidRuntime(20167): at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298)
02-04 19:26:41.145: E/AndroidRuntime(20167): at es.example.jsonarchivo.Adapter.<init>(Adapter.java:70)
02-04 19:26:41.145: E/AndroidRuntime(20167): at es.example.jsonarchivo.MainActivity.onCreate(MainActivity.java:27)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.Activity.performCreate(Activity.java:5008)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-04 19:26:41.145: E/AndroidRuntime(20167): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-04 19:26:41.145: E/AndroidRuntime(20167): ... 11 more
02-04 19:31:41.224: I/Process(20167): Sending signal. PID: 20167 SIG: 9
I hope I have explained it well, my mother tongue isn't english.
To recap in an answer,
java.io.FileNotFoundException: /mnt/sdcard/data/local/textojson.txt: open failed: ENOENT (No such file or directory)
means that the file does not exist. This can be verified with f.exists()
If the problem was permissions you should get open failed: EACCES (Permission denied)

Google Maps v2 : how import google-play-service.jar into Android Dependencies

I have created Google Maps v2 app. I followed the tutorial step by step. And when I'm launching this app.
It show pop up "Unfortunately, Google Maps v2 has stopped".
Here is the logcat...
09-03 04:51:33.296: E/AndroidRuntime(2148): FATAL EXCEPTION: main
09-03 04:51:33.296: E/AndroidRuntime(2148): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.achson.googlemapsv2/com.achson.googlemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.os.Looper.loop(Looper.java:137)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-03 04:51:33.296: E/AndroidRuntime(2148): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 04:51:33.296: E/AndroidRuntime(2148): at java.lang.reflect.Method.invoke(Method.java:525)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-03 04:51:33.296: E/AndroidRuntime(2148): at dalvik.system.NativeStart.main(Native Method)
09-03 04:51:33.296: E/AndroidRuntime(2148): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Activity.setContentView(Activity.java:1895)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.achson.googlemapsv2.MainActivity.onCreate(MainActivity.java:18)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Activity.performCreate(Activity.java:5133)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-03 04:51:33.296: E/AndroidRuntime(2148): ... 11 more
09-03 04:51:33.296: E/AndroidRuntime(2148): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Fragment.instantiate(Fragment.java:585)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Fragment.instantiate(Fragment.java:560)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Activity.onCreateView(Activity.java:4738)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
09-03 04:51:33.296: E/AndroidRuntime(2148): ... 21 more
I assume that google-play-services isn't inside of Android Dependencies folder.
But it's inside of Android Private Libraries folder. I don't know how to import to Android Dependencies folder. Anyone who knows ? Please share at this.
09-06 15:29:30.480: E/AndroidRuntime(1260): FATAL EXCEPTION: main
09-06 15:29:30.480: E/AndroidRuntime(1260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapsv2/com.example.googlemapsv2.MainActivity}: java.lang.NullPointerException: CameraUpdateFactory is not initialized
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.os.Looper.loop(Looper.java:137)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-06 15:29:30.480: E/AndroidRuntime(1260): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 15:29:30.480: E/AndroidRuntime(1260): at java.lang.reflect.Method.invoke(Method.java:511)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-06 15:29:30.480: E/AndroidRuntime(1260): at dalvik.system.NativeStart.main(Native Method)
09-06 15:29:30.480: E/AndroidRuntime(1260): Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.google.android.gms.internal.ac.a(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.google.android.gms.maps.CameraUpdateFactory.aV(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.example.googlemapsv2.MainActivity.onCreate(MainActivity.java:24)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.Activity.performCreate(Activity.java:5104)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-06 15:29:30.480: E/AndroidRuntime(1260): ... 11 more
Assuming a layout inflation error
Primarily caused by inflation of wrong fragment type based on imports.
Case 1: If you are using a MapFragment in your FragmentActivity or Activity, using the import android.support.v4.app.*(i.e. Your class extends the Activity or Fragment Activity from the this package), then you will get ClassCastException
Solution Use a SupportMapFragment
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
then use the code to get the map in your Activity.
SupportMapFragment mapFragment = ((SupportMapFragment) this
.getSupportFragmentManager().findFragmentById(R.id.map));
Case 2: If you are using a SupportMapfragment in your FragmentActivity or Activity ,using the import android.app.* (i.e. Your class extends the Activity or Fragment Activity from the this package), then also you will get ClassCastException
Solution: Use a MapFragment
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
then use in the code to get the map reference in your Acitivity
MapFragment mapFragment = ((MapFragment) this
.getSupportFragmentManager().findFragmentById(R.id.map));
Also, the play services need not to be specifically in the Android Dependencies folders, as Android Private folder is too added to your build path.
Have you declared the Activity in your manifest?
Edit: Once you import library into your workspace (In Eclipse), you right click on the project, open properties, click android and at the bottom you will see library import section. Add it to that.
What version of API are you using? How does look your xml with the map layout?
I had the same problem recently. And it was caused because I was using wrong fragment type.
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
It worked when I put android:name="com.google.android.gms.maps.SupportMapFragment"
then in your code if you work with map you must extend FragmentActivity insetad of Activity for your class (public class MapActivity extends FragmentActivity)
GoogleMap mMap;
SupportMapFragment mMapFragment;
mMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
mMap = mMapFragment.getMap();
And that is how you get the mapFragment in the code.

Android: Error inflating class <unknown> caused by OutOfMemoryError: bitmap size exceeds VM budget

I have a Error inflating class error that seemed to be caused by Bitmap (more details here: Android: Memory error because of an ImageView?) but when I comment the bitmap I still have the error while when I comment the Imageview5, no error. All the posts on stackoverflow about this error did not help solving my problem
02-04 10:03:04.353: E/AndroidRuntime(17427): FATAL EXCEPTION: main
02-04 10:03:04.353: E/AndroidRuntime(17427): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kersplatt/com.example.kersplatt.ShareActivity}: android.view.InflateException: Binary XML file line #23: Error inflating class <unknown>
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.os.Looper.loop(Looper.java:130)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-04 10:03:04.353: E/AndroidRuntime(17427): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 10:03:04.353: E/AndroidRuntime(17427): at java.lang.reflect.Method.invoke(Method.java:507)
02-04 10:03:04.353: E/AndroidRuntime(17427): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
02-04 10:03:04.353: E/AndroidRuntime(17427): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
02-04 10:03:04.353: E/AndroidRuntime(17427): at dalvik.system.NativeStart.main(Native Method)
02-04 10:03:04.353: E/AndroidRuntime(17427): Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class <unknown>
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
02-04 10:03:04.353: E/AndroidRuntime(17427): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-04 10:03:04.353: E/AndroidRuntime(17427): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.Activity.setContentView(Activity.java:1657)
02-04 10:03:04.353: E/AndroidRuntime(17427): at com.example.kersplatt.ShareActivity.onCreate(ShareActivity.java:64)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-04 10:03:04.353: E/AndroidRuntime(17427): ... 11 more
02-04 10:03:04.353: E/AndroidRuntime(17427): Caused by: java.lang.reflect.InvocationTargetException
02-04 10:03:04.353: E/AndroidRuntime(17427): at java.lang.reflect.Constructor.constructNative(Native Method)
02-04 10:03:04.353: E/AndroidRuntime(17427): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
02-04 10:03:04.353: E/AndroidRuntime(17427): ... 23 more
02-04 10:03:04.353: E/AndroidRuntime(17427): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.widget.ImageView.<init>(ImageView.java:118)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.widget.ImageView.<init>(ImageView.java:108)
02-04 10:03:04.353: E/AndroidRuntime(17427): ... 26 more
and my line 23 is imageview5
<ImageView
android:id="#+id/imageView5"
android:layout_width="85dp"
android:layout_height="100dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:src="#drawable/diviseur" />
It's a pretty misleading error, but it's caused by a nested exception, because the VM has run out of memory for the drawable diviseur. See the end of the stack trace:
02-04 10:03:04.353: E/AndroidRuntime(17427): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.widget.ImageView.<init>(ImageView.java:118)
02-04 10:03:04.353: E/AndroidRuntime(17427): at android.widget.ImageView.<init>(ImageView.java:108)
02-04 10:03:04.353: E/AndroidRuntime(17427): ... 26 more
Sometimes this may happen, the best practice is to create a scaled bitmap using the bitmap factory,
Bitmap result = Bitmap.createScaledBitmap(bitmapPicture,
imageWidth, imageHeight, false);
Try this and see if it helps
Also use,
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPurgeable = true; // Tell to garbage collector that whether it needs free memory, the Bitmap can be cleared
opts.inTempStorage = new byte[32 * 1024];
and always recycle your bitmap when you leave that activity as it helps in freeing memory.
Hope this helps
I got the same error. My problem was that every phone loaded a 2k image as background of the activity. I solved the problem by scaling down this background image to 800x480 and 1280x720. Then I put this images into the ldpi, mdpi, ... folders.Now it works

Categories

Resources