This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

gridview keeps crashing on a click button  RSS feed

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im trying to load a gridview on a click but it keeps crashing. can some tell me why it keeps crashing. here is my code

It works fine if I don't use a click


java class





here is my main code
 
Marshal
Posts: 62801
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like FX code, so I shall move you to our FX forum.

Please supply more details of what is going wrong, e.g. the stack trace. You need that sort of information to sort out the crash.
 
Tony fig
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some of the err im geting



01-26 15:49:56.323 18612-18612/com.example.tony.concerts_ D/AndroidRuntime: Shutting down VM
01-26 15:49:56.323 18612-18612/com.example.tony.concerts_ W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4ce2b20)
01-26 15:49:56.331 18612-18612/com.example.tony.concerts_ D/dalvikvm: GC_FOR_ALLOC freed 336K, 1% free 53057K/53504K, paused 8ms, total 8ms
01-26 15:49:56.343 18612-18612/com.example.tony.concerts_ E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.example.tony.concerts_, PID: 18612
   java.lang.ClassCastException: com.example.tony.concerts_.MainActivity$1 cannot be cast to android.content.Context
       at com.example.tony.concerts_.ImageAdapter2.getView(ImageAdapter2.java:49)
       at android.widget.AbsListView.obtainView(AbsListView.java:2255)
       at android.widget.GridView.onMeasure(GridView.java:1044)
       at android.view.View.measure(View.java:16497)
       at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
       at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
       at android.view.View.measure(View.java:16497)
       at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
       at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
       at android.view.View.measure(View.java:16497)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
       at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
       at android.view.View.measure(View.java:16497)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
       at android.view.View.measure(View.java:16497)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
       at android.view.View.measure(View.java:16497)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
       at android.view.View.measure(View.java:16497)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
       at android.view.View.measure(View.java:16497)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
       at android.view.Choreographer.doCallbacks(Choreographer.java:574)
       at android.view.Choreographer.doFrame(Choreographer.java:544)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5001)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
       at dalvik.system.NativeStart.main(Native Method)
01-26 15:49:56.371 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:56.371 618-916/system_process W/ActivityManager:   Force finishing activity com.example.tony.concerts_/.MainActivity
01-26 15:49:56.447 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:56.527 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=558 frame_size=4 returned -EPIPE
01-26 15:49:56.607 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:56.715 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:56.723 1260-1260/com.google.android.gms D/dalvikvm: GC_EXPLICIT freed 6742K, 31% free 23758K/34188K, paused 0ms+0ms, total 84ms
01-26 15:49:56.751 618-683/system_process D/MobileDataStateTracker: default: setPolicyDataEnable(enabled=true)
01-26 15:49:56.807 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:56.891 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=558 frame_size=4 returned -EPIPE
01-26 15:49:56.967 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.023 618-634/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{529ef5b4 u0 com.example.tony.concerts_/.MainActivity t34 f}
01-26 15:49:57.059 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.131 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.207 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=558 frame_size=4 returned -EPIPE
01-26 15:49:57.259 564-564/? D/SurfaceFlinger: setOrientation, mFbdev=0xb8f67788, mFbDev->setOrientation=0x0, orientation=0
01-26 15:49:57.259 564-564/? E/SurfaceFlinger: setOrientation: can't set orientation
01-26 15:49:57.259 618-634/system_process I/ActivityManager: Config changes=480 {1.0 310mcc270mnc en_US ldltr sw384dp w384dp h567dp 320dpi nrml port finger qwerty/v/v dpad/v s.60}
01-26 15:49:57.271 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.291 700-700/com.android.systemui E/EGL_emulation: tid 700: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
01-26 15:49:57.291 700-700/com.android.systemui W/HardwareRenderer: Backbuffer cannot be preserved
01-26 15:49:57.307 700-700/com.android.systemui E/EGL_emulation: tid 700: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
01-26 15:49:57.307 700-700/com.android.systemui W/HardwareRenderer: Backbuffer cannot be preserved
01-26 15:49:57.311 700-700/com.android.systemui D/PhoneStatusBar: mSettingsPanelGravity = 55
01-26 15:49:57.343 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=558 frame_size=4 returned -EPIPE
01-26 15:49:57.391 618-671/system_process I/InputReader: Reconfiguring input devices.  changes=0x00000004
01-26 15:49:57.391 618-671/system_process I/InputReader: Device reconfigured: id=1, name='Genymotion Virtual Input', size 768x1280, orientation 0, mode 1, display id 0
01-26 15:49:57.391 618-671/system_process I/InputReader: Reconfiguring input devices.  changes=0x00000004
01-26 15:49:57.427 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.471 700-700/com.android.systemui E/EGL_emulation: tid 700: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
01-26 15:49:57.471 700-700/com.android.systemui W/HardwareRenderer: Backbuffer cannot be preserved
01-26 15:49:57.503 901-901/com.android.launcher E/EGL_emulation: tid 901: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
01-26 15:49:57.503 901-901/com.android.launcher W/HardwareRenderer: Backbuffer cannot be preserved
01-26 15:49:57.511 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.523 901-901/com.android.launcher E/HardwareRenderer: An error has occurred while drawing:
   java.lang.IllegalStateException: The display list is not valid.
       at android.view.GLES20DisplayList.getNativeDisplayList(GLES20DisplayList.java:49)
       at android.view.GLES20Canvas.drawDisplayList(GLES20Canvas.java:420)
       at android.view.HardwareRenderer$GlRenderer.drawDisplayList(HardwareRenderer.java:1646)
       at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1469)
       at android.view.ViewRootImpl.draw(ViewRootImpl.java:2377)
       at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2249)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1879)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
       at android.view.Choreographer.doCallbacks(Choreographer.java:574)
       at android.view.Choreographer.doFrame(Choreographer.java:544)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5001)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
       at dalvik.system.NativeStart.main(Native Method)
01-26 15:49:57.583 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.639 700-700/com.android.systemui E/EGL_emulation: tid 700: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
01-26 15:49:57.639 700-700/com.android.systemui W/HardwareRenderer: Backbuffer cannot be preserved
01-26 15:49:57.675 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=558 frame_size=4 returned -EPIPE
01-26 15:49:57.803 618-683/system_process D/MobileDataStateTracker: default: setPolicyDataEnable(enabled=true)
01-26 15:49:57.807 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.815 700-700/com.android.systemui D/dalvikvm: GC_FOR_ALLOC freed 11820K, 54% free 9486K/20300K, paused 20ms, total 20ms
01-26 15:49:57.847 700-700/com.android.systemui I/dalvikvm-heap: Grow heap (frag case) to 18.746MB for 9830412-byte allocation
01-26 15:49:57.863 700-709/com.android.systemui D/dalvikvm: GC_FOR_ALLOC freed 466K, 38% free 18619K/29904K, paused 16ms, total 16ms
01-26 15:49:57.891 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:57.975 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=557 frame_size=4 returned -EPIPE
01-26 15:49:58.063 227-354/? D/genymotion_audio: out_write: pcm_write() with out_frames=558 frame_size=4 returned -EPIPE
01-26 15:49:58.151 618-683/system_process D/MobileDataStateTracker: default: setPolicyDataEnable(enabled=true)
 
Campbell Ritchie
Marshal
Posts: 62801
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, it's Android is it? Another change of forum

Look at the 6th line of the stack trace; you're trying to cast an anonymous class to Context. where are you doing that? It appears to be on line 49.
 
Tony fig
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line 49 is setContentView(R.layout.activity_main); this

at startup and in my click button. but if I delete it still crashes

 
Campbell Ritchie
Marshal
Posts: 62801
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and what type is R.layout.activity_main? If you are getting other crashes, what is their stack trace?

By the way: that is a dreadful name for something, and the number of dots in there suggests you are designing things with non‑private fields.
 
Saloon Keeper
Posts: 5219
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a listener object for the context won't work; use the associated Activity (or Application) instead.

Campbell wrote:what type is R.layout.activity_main?
...
By the way: that is a dreadful name for something,


R.layout.activity_main is a standard Android notation for a layout resource, nothing wrong with that.
 
Campbell Ritchie
Marshal
Posts: 62801
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I take it back: sorry.
 
They weren't very bright, but they were very, very big. Ad contrast:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!