Making imageview invisible causes NullPointerException - android

I am running the following code and it gives me NullPointerException in the line iv4.setVisibility(View.INVISIBLE)
Please suggest. Thanks
Code:
ImageView iv4;
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
iv4= (ImageView) findViewById(R.id.imageView4);
iv4.setVisibility(View.INVISIBLE);
}
<RelativeLayout
xmlns:android="schemas.android.com/apk/res/android";
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="#+id/imageView4"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/hg" />
</RelativeLayout>
The stack trace is as follows:
03-05 03:49:25.477: E/AndroidRuntime(1070): FATAL EXCEPTION: main
03-05 03:49:25.477: E/AndroidRuntime(1070): java.lang.RuntimeException: Unable to start activity ComponentInfo{bitcream.candyhive.candy/bitcream.candyhive.candy.ScoreActivity}: java.lang.NullPointerException
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.os.Looper.loop(Looper.java:123)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 03:49:25.477: E/AndroidRuntime(1070): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 03:49:25.477: E/AndroidRuntime(1070): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 03:49:25.477: E/AndroidRuntime(1070): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 03:49:25.477: E/AndroidRuntime(1070): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 03:49:25.477: E/AndroidRuntime(1070): at dalvik.system.NativeStart.main(Native Method)
03-05 03:49:25.477: E/AndroidRuntime(1070): Caused by: java.lang.NullPointerException
03-05 03:49:25.477: E/AndroidRuntime(1070): at bitcream.candyhive.candy.ScoreActivity.onCreate(ScoreActivity.java:42)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-05 03:49:25.477: E/AndroidRuntime(1070): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-05 03:49:25.477: E/AndroidRuntime(1070): ... 11 more
03-05 03:49:28.297: I/Process(1070): Sending signal. PID: 1070 SIG: 9

NullPointerException in the line iv4.setVisibility(View.INVISIBLE)
Probably there is no ImageView with the id imageView4 in activity_score.xml.
Either you referenced the wrong layout or your layout does not contain the imageview with the id mentioned.
Edit:
Change
<RelativeLayout
xmlns:android="schemas.android.com/apk/res/android"
to
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
You will get NullPointerException if findViewById does not find a view with the id mentioned in the current inflated layout.

Related

Crash when using Google Play Game Services (Unity3d in Android)

I have a problem. I am developing a game in Unity3d which uses the official Facebook SDK and NerdGPG for Google Play Game Services. However, there is an annoying bug:
WHen I want to see the Achievements or Leaderboards, it opnes the UI, but AFTER I CLOSE the UI, then the game crashes. The Logcat tells the following:
03-05 00:09:54.325: E/AndroidRuntime(10810): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9002, result=0, data=null} to activity {com.radioactivewasp.flyingwasp/com.facebook.unity.FBUnityPlayerActivity}: java.lang.NullPointerException
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.app.ActivityThread.deliverResults(ActivityThread.java:3182)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.app.ActivityThread.access$1100(ActivityThread.java:140)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.os.Looper.loop(Looper.java:137)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-05 00:09:54.325: E/AndroidRuntime(10810): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 00:09:54.325: E/AndroidRuntime(10810): at java.lang.reflect.Method.invoke(Method.java:511)
03-05 00:09:54.325: E/AndroidRuntime(10810): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-05 00:09:54.325: E/AndroidRuntime(10810): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-05 00:09:54.325: E/AndroidRuntime(10810): at dalvik.system.NativeStart.main(Native Method)
03-05 00:09:54.325: E/AndroidRuntime(10810): Caused by: java.lang.NullPointerException
03-05 00:09:54.325: E/AndroidRuntime(10810): at com.facebook.unity.FBUnityPlayerActivity.onActivityResult(FBUnityPlayerActivity.java:15)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
03-05 00:09:54.325: E/AndroidRuntime(10810): at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
Anybody know what could be the solution?
It looks like your Facebook plugin Activity doesn't know how to handle the onActivityResult() callback when you use the RC_UNUSED(9002) requestID.So I imagine you would want to modify your Facebook Player activity such that the NerdGPG plugin handles the callback.

VerrifyError with Guice on Android maven project

So I'm trying to get Guice to run in my android maven project and bundle in a 3rd party module. It runs fine in the normal junittest that does a test injection, but fails on the VM with the logcat message attached below.
What I can't understand is that there are numerous reports of Guice working fine on android . Despite this, my code seems to be failing on getBeanInfo() being called from the Guice injector. It seems I'm not the only one having this error.
Is there a work around for the Android error "Unable to resolve virtual method java/beans/PropertyDescriptor"?
So I have a couple of questions. Is the reason Guice isn't working for me, because some functionality is being invoked by my 3rd party module that would fail everywhere but isn't common? Is there a way to get more info out of Guice as to what specifically is triggering the offending getBeanInfo()? Are there work arounds? What avenues are available to me for further debugging.
The solution must be maven compatible, as answers to a similar question about tweaking eclipse settings for similar problems can't apply. Getting "Caused by: java.lang.VerifyError:"
(not that I got much mileage here anyway).
I think that all relevant files were processed by dx by the android maven plugin, as dependency:tree shows all relevant project at scope "compile", but I'm no expert here.
03-05 00:57:34.529: I/dalvikvm(2295): threadid=3: reacting to signal 3
03-05 00:57:34.568: I/dalvikvm(2295): Wrote stack traces to '/data/anr/traces.txt'
03-05 00:57:35.059: I/dalvikvm(2295): threadid=3: reacting to signal 3
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): Could not load Finalizer in its own class loader. Loading Finalizer in the current class loader instead. As a result, you will not be able to garbage collect this class loader. To support reclaiming this class loader, either resolve the underlying issue, or move Google Collections to your system class path.
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): java.io.FileNotFoundException: com/google/inject/internal/util/$Finalizer.class
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$FinalizableReferenceQueue$DecoupledLoader.getBaseUrl(FinalizableReferenceQueue.java:269)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$FinalizableReferenceQueue$DecoupledLoader.loadFinalizer(FinalizableReferenceQueue.java:253)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$FinalizableReferenceQueue.loadFinalizer(FinalizableReferenceQueue.java:175)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$FinalizableReferenceQueue.(FinalizableReferenceQueue.java:100)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$MapMaker$QueueHolder.(MapMaker.java:787)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$MapMaker$WeakEntry.(MapMaker.java:946)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$MapMaker$Strength$1.newEntry(MapMaker.java:312)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$MapMaker$StrategyImpl.newEntry(MapMaker.java:498)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$MapMaker$StrategyImpl.newEntry(MapMaker.java:419)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2029)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.Annotations$AnnotationChecker.hasAnnotations(Annotations.java:116)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.Annotations.isScopeAnnotation(Annotations.java:124)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.ScopeBindingProcessor.visit(ScopeBindingProcessor.java:40)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.ScopeBindingProcessor.visit(ScopeBindingProcessor.java:30)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.spi.ScopeBinding.acceptVisitor(ScopeBinding.java:59)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.AbstractProcessor.process(AbstractProcessor.java:55)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:165)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.Guice.createInjector(Guice.java:95)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.Guice.createInjector(Guice.java:72)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.google.inject.Guice.createInjector(Guice.java:62)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at za.co.mambo.cherrylist.android.CherryListActivity.onCreate(CherryListActivity.java:27)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.app.Activity.performCreate(Activity.java:4465)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.os.Looper.loop(Looper.java:137)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at java.lang.reflect.Method.invoke(Method.java:511)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 00:57:35.098: W/nalizableReferenceQueue(2295): at dalvik.system.NativeStart.main(Native Method)
03-05 00:57:35.108: I/dalvikvm(2295): Wrote stack traces to '/data/anr/traces.txt'
03-05 00:57:35.338: D/dalvikvm(2295): GC_CONCURRENT freed 391K, 4% free 12676K/13127K, paused 8ms+5ms
03-05 00:57:35.418: W/dalvikvm(2295): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-05 00:57:35.418: W/dalvikvm(2295): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-05 00:57:35.418: W/dalvikvm(2295): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-05 00:57:35.418: W/dalvikvm(2295): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-05 00:57:35.418: W/dalvikvm(2295): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-05 00:57:35.428: W/dalvikvm(2295): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-05 00:57:35.438: I/dalvikvm(2295): Could not find method java.beans.Introspector.getBeanInfo, referenced from method com.google.inject.internal.cglib.core.$ReflectUtils.getPropertiesHelper
03-05 00:57:35.438: W/dalvikvm(2295): VFY: unable to resolve static method 8989: Ljava/beans/Introspector;.getBeanInfo (Ljava/lang/Class;Ljava/lang/Class;)Ljava/beans/BeanInfo;
03-05 00:57:35.438: D/dalvikvm(2295): VFY: replacing opcode 0x71 at 0x000c
03-05 00:57:35.458: W/dalvikvm(2295): VFY: unable to resolve exception class 1373 (Ljava/beans/IntrospectionException;)
03-05 00:57:35.458: W/dalvikvm(2295): VFY: unable to find exception handler at addr 0x4e
03-05 00:57:35.458: W/dalvikvm(2295): VFY: rejected Lcom/google/inject/internal/cglib/core/$ReflectUtils;.getPropertiesHelper (Ljava/lang/Class;ZZ)[Ljava/beans/PropertyDescriptor;
03-05 00:57:35.458: W/dalvikvm(2295): VFY: rejecting opcode 0x0d at 0x004e
03-05 00:57:35.458: W/dalvikvm(2295): VFY: rejected Lcom/google/inject/internal/cglib/core/$ReflectUtils;.getPropertiesHelper (Ljava/lang/Class;ZZ)[Ljava/beans/PropertyDescriptor;
03-05 00:57:35.458: W/dalvikvm(2295): Verifier rejected class Lcom/google/inject/internal/cglib/core/$ReflectUtils;
03-05 00:57:35.488: D/AndroidRuntime(2295): Shutting down VM
03-05 00:57:35.498: W/dalvikvm(2295): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
03-05 00:57:35.508: I/dalvikvm(2295): threadid=3: reacting to signal 3
03-05 00:57:35.548: I/dalvikvm(2295): Wrote stack traces to '/data/anr/traces.txt'
03-05 00:57:35.568: E/AndroidRuntime(2295): FATAL EXCEPTION: main
03-05 00:57:35.568: E/AndroidRuntime(2295): java.lang.RuntimeException: Unable to start activity ComponentInfo{za.co.mambo.cherrylist.android/za.co.mambo.cherrylist.android.CherryListActivity}: com.google.inject.internal.util.$ComputationException: java.lang.VerifyError: com/google/inject/internal/cglib/core/$ReflectUtils
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.os.Looper.loop(Looper.java:137)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-05 00:57:35.568: E/AndroidRuntime(2295): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 00:57:35.568: E/AndroidRuntime(2295): at java.lang.reflect.Method.invoke(Method.java:511)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 00:57:35.568: E/AndroidRuntime(2295): at dalvik.system.NativeStart.main(Native Method)
03-05 00:57:35.568: E/AndroidRuntime(2295): Caused by: com.google.inject.internal.util.$ComputationException: java.lang.VerifyError: com/google/inject/internal/cglib/core/$ReflectUtils
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:49)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:125)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:521)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:847)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:853)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:46)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:133)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.Guice.createInjector(Guice.java:95)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.Guice.createInjector(Guice.java:72)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.Guice.createInjector(Guice.java:62)
03-05 00:57:35.568: E/AndroidRuntime(2295): at za.co.mambo.cherrylist.android.CherryListActivity.onCreate(CherryListActivity.java:27)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.Activity.performCreate(Activity.java:4465)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-05 00:57:35.568: E/AndroidRuntime(2295): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-05 00:57:35.568: E/AndroidRuntime(2295): ... 11 more
03-05 00:57:35.568: E/AndroidRuntime(2295): Caused by: java.lang.VerifyError: com/google/inject/internal/cglib/core/$ReflectUtils
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.cglib.reflect.$FastClassEmitter.(FastClassEmitter.java:67)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:207)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:53)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:153)
03-05 00:57:35.568: E/AndroidRuntime(2295): at com.google.inject.internal
03-05 00:57:36.178: I/dalvikvm(2295): threadid=3: reacting to signal 3
03-05 00:57:36.188: I/dalvikvm(2295): Wrote stack traces to '/data/anr/traces.txt'
03-05 00:57:36.530: I/dalvikvm(2295): threadid=3: reacting to signal 3
03-05 00:57:36.538: I/dalvikvm(2295): Wrote stack traces to '/data/anr/traces.txt'
The dalvik vm does not support aspected oriented programming so you can not use the plain JVM Guice. You have to use the no_aop version.
With a Maven build use
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<classifier>no_aop</classifier>
</dependency>
to get the no_aop jar into your build and apk.
Of course you can also look at using RoboGuice.

error when retrieving a record from the data base?

I'm trying to retrieve a name stred in SQLite table, despite the database has 11 or more records, when I try to retrieve any name from the stored records, The App. Crashs.
Java code:
OnClickListener btn_NavaigateListsner = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (!btn_Save.isEnabled()) {
int c = mpoh.getCurrentRowNumber();
Toast.makeText(getBaseContext(), ""+mpoh.getMP_Name(0), Toast.LENGTH_SHORT).show();
Bundle bundle = new Bundle();
//bundle.putString("name", mpoh.getMP_Name(c));
//bundle.putDouble("lat", mpoh.getMP_Lat(c));
//bundle.putDouble("lng", mpoh.getMP_Lng(c));
//bundle.putString("date", mpoh.getMP_Date(c));
//bundle.putString("time", mpoh.getMP_Time(c));
intent01 = new Intent(MPData.this, MPInfo.class);
intent01.putExtras(bundle);
startActivity(intent01);
}// End of If
}
};
Method that retrieves the stored name:
public String getMP_Name(long id) {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteCursor c = (SQLiteCursor) db.rawQuery("SELECT name FROM MPData WHERE "+
BaseColumns._ID+" = "+
Long.toString(id) +" AND name IS NOT NULL ", null);
c.moveToFirst();
String r = c.getString(0);
c.close();
db.close();
return r;
}
some of LogCat's output:
03-05 12:16:48.288: E/AndroidRuntime(973): FATAL EXCEPTION: main
03-05 12:16:48.288: E/AndroidRuntime(973): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.view.View.performClick(View.java:2485)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.view.View$PerformClick.run(View.java:9080)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Handler.handleCallback(Handler.java:587)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Handler.dispatchMessage(Handler.java:92)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Looper.loop(Looper.java:130)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:16:48.288: E/AndroidRuntime(973): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:16:48.288: E/AndroidRuntime(973): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:16:48.288: E/AndroidRuntime(973): at dalvik.system.NativeStart.main(Native Method)
03-05 12:32:19.897: E/AndroidRuntime(1022): FATAL EXCEPTION: main
03-05 12:32:19.897: E/AndroidRuntime(1022): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.view.View.performClick(View.java:2485)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.view.View$PerformClick.run(View.java:9080)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Handler.handleCallback(Handler.java:587)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Handler.dispatchMessage(Handler.java:92)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Looper.loop(Looper.java:130)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:32:19.897: E/AndroidRuntime(1022): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:32:19.897: E/AndroidRuntime(1022): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:32:19.897: E/AndroidRuntime(1022): at dalvik.system.NativeStart.main(Native Method)
03-05 12:39:24.627: E/AndroidRuntime(1093): FATAL EXCEPTION: main
03-05 12:39:24.627: E/AndroidRuntime(1093): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.performClick(View.java:2485)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.onKeyUp(View.java:4257)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.widget.TextView.onKeyUp(TextView.java:4587)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.KeyEvent.dispatch(KeyEvent.java:1280)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.dispatchKeyEvent(View.java:3855)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.os.Looper.loop(Looper.java:130)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:39:24.627: E/AndroidRuntime(1093): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:39:24.627: E/AndroidRuntime(1093): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:39:24.627: E/AndroidRuntime(1093): at dalvik.system.NativeStart.main(Native Method)
The code looks fine to me. Are you 100% sure you have an entry in your DB with an _id corresponding to 0?
If you call getMP_Name with an invalid _id then the exception will get raised as you posted it.
You should check for this case as follows:
if (c.getCount()==0) return "";
// rest of code
But I wouldn't do it like this anyway because your current implementation of getMP_XXX is very inefficient because you hit the database for each field and each row. You should minimise your number of queries and then iterate over the resulting cursor.
Look at the following line :
String r = c.getString(0);
You are not safe checking your cursor and just assuming a result was recieved.
Check you SQL query and add a safe check for making sure your cursor has retrieved results.

Android App ForceCloses on Starting of a new activity

I am new to android development and I have been having issues with Force Close on new Android Activity Pages.
My Structure is like this:
Main Page -> Menu Page (Works Fine) -> New Game Screen(force closes)
Call to the Activity:
public void btnNewGame_Click(View view)
{
Intent i = new Intent(this, NewGameScreen.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
Manifest
<activity android:name=".NewGameScreen"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ExpandableListView
android:id="#+id/eLVGameList"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight=".75"
android:background="#null" android:layout_height="0dip">
</ExpandableListView>
</LinearLayout>
NewGameScreenActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loadgame);
ExpandableListView epView = (ExpandableListView) findViewById(R.id.eLVGameList);
ExpandableListAdapter mAdapter = new GameListAdapter();
epView.setAdapter(mAdapter);
Errors:
03-05 20:16:57.375: E/AndroidRuntime(887): FATAL EXCEPTION: main
03-05 20:16:57.375: E/AndroidRuntime(887): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.NewGameScreen}: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.os.Looper.loop(Looper.java:137)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-05 20:16:57.375: E/AndroidRuntime(887): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 20:16:57.375: E/AndroidRuntime(887): at java.lang.reflect.Method.invoke(Method.java:511)
03-05 20:16:57.375: E/AndroidRuntime(887): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 20:16:57.375: E/AndroidRuntime(887): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 20:16:57.375: E/AndroidRuntime(887): at dalvik.system.NativeStart.main(Native Method)
03-05 20:16:57.375: E/AndroidRuntime(887): Caused by: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.ExpandableListActivity.onContentChanged(ExpandableListActivity.java:222)
03-05 20:16:57.375: E/AndroidRuntime(887): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.Activity.setContentView(Activity.java:1835)
03-05 20:16:57.375: E/AndroidRuntime(887): at com.example.helloandroid.NewGameScreen.onCreate(NewGameScreen.java:22)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.Activity.performCreate(Activity.java:4465)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-05 20:16:57.375: E/AndroidRuntime(887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-05 20:16:57.375: E/AndroidRuntime(887): ... 11 more
Change your ExpandableListView id with this
android:id="#android:id/list"
and if your class extends Activity then change it to
public class className extends ListActivity
and you can get your ExpandableListView by calling the method
ExpandableListView listView = getListView();
The answer is very simple, you just forgot to insert the NewGameScreen Activity's Entry in the AndroidManiFest.xml Write down following line in your AndroidManifest.xml file before the tag.
<activity android:name=".NewGameScreen"></activity>
And also important thing that your NewGameScreen class must extends Activity
You need to give the id of your ListView as android:id="#android:id/list" , if you are extending LIstActivity. Then you can get your ListView handler from getLIstView();
If you are extending Activity, then you can give any other id to your ListView and get it using findViewbyId()
From the LOgCat trace, it looks like you are using ListActivity.

android Mediaplayer can not work in emulator

I'm begginer in android Programming
My Question is...
I wanted to play backgroud Music.
So I read a code like this
public class Welcome extends Activity {
/** Called when the activity is first created. */
MediaPlayer player;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
player=MediaPlayer.create(Welcome.this, R.raw.song);
player.start();
But this code doesn't work in emulator. Error occured...
My Logcat is here..
03-05 15:36:36.588: ERROR/AndroidRuntime(954): FATAL EXCEPTION: main
03-05 15:36:36.588: ERROR/AndroidRuntime(954): java.lang.RuntimeException: Unable to start activity ComponentInfo{younkyung.app.lord_of_spelling/younkyung.app.lord_of_spelling.Welcome}: java.lang.NullPointerException
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.os.Looper.loop(Looper.java:123)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at java.lang.reflect.Method.invoke(Method.java:521)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at dalvik.system.NativeStart.main(Native Method)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): Caused by: java.lang.NullPointerException
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at younkyung.app.lord_of_spelling.Welcome.onCreate(Welcome.java:25)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): ... 11 more
I cannot understand what's wrong...
Please Help..! ...
You need to use one of the supported file formats. WMA is not one of them.

Categories

Resources