making an image clickable

All your problems with Audio, Video and Images.

making an image clickable

Postby chaoz1336 » Fri Jan 16, 2009 12:41 pm

...see the title...

I got an Imageview, but anyhow it crashes when I add an onClickListener =/
Last edited by chaoz1336 on Fri Jan 16, 2009 1:42 pm, edited 1 time in total.
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top

Re: macking an image clickable

Postby MrSnowflake » Fri Jan 16, 2009 1:11 pm

chaoz1336 wrote:...see the title...

I got an Imageview, but anyhow it crashes when I add an onClickListener =/
That shouldn't happen... You are probably doing something very wrong... :)
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby chaoz1336 » Fri Jan 16, 2009 1:41 pm

thats my code:
(when I add the "imgSignature.setOnClickListener( ... " it crashes =/

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private ImageView imgSignature;
  3.  
  4.  
  5.  
  6. public void onCreate(Bundle savedInstanceState) {
  7.  
  8. ...
  9.  
  10. imgSignature = (ImageView) findViewById(R.drawable.mypic);
  11.  
  12. ...
  13.  
  14.  
  15.  
  16. }
  17.  
  18.  
  19.  
  20. private void addClickListener() {
  21.  
  22. imgSignature.setOnClickListener(new View.OnClickListener() {
  23.  
  24.                         public void onClick(View v) {
  25.  
  26.                                
  27.  
  28.                         }
  29.  
  30.                 });
  31.  
  32. }
  33.  
  34.  
  35.  
  36.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Postby MrSnowflake » Fri Jan 16, 2009 3:05 pm

check you log to see what the error is.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby chaoz1336 » Fri Jan 16, 2009 4:08 pm

ErrorLog:

01-16 16:06:47.257: ERROR/AndroidRuntime(1818): Uncaught handler: thread main exiting due to uncaught exception
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): java.lang.RuntimeException: Unable to start activity ComponentInfo{ --- }: java.lang.NullPointerException
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2156)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.os.Handler.dispatchMessage(Handler.java:88)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.os.Looper.loop(Looper.java:123)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.app.ActivityThread.main(ActivityThread.java:3742)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at java.lang.reflect.Method.invokeNative(Native Method)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at java.lang.reflect.Method.invoke(Method.java:515)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at dalvik.system.NativeStart.main(Native Method)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): Caused by: java.lang.NullPointerException
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at com.cortado.fax_and_scan.FaxAndScan.addClickListener(FaxAndScan.java:86)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at com.cortado.fax_and_scan.FaxAndScan.onCreate(FaxAndScan.java:51)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2103)
01-16 16:06:47.277: ERROR/AndroidRuntime(1818): ... 11 more
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Postby MrSnowflake » Fri Jan 16, 2009 4:37 pm

Seems like imgSignature is still null. check that.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby chaoz1336 » Sat Jan 17, 2009 10:06 am

MrSnowflake wrote:Seems like imgSignature is still null. check that.


it cant be null, coz I can display the control.
and in
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. imgSignature = (ImageView) findViewById(R.drawable.mypic);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


I initialise it.... =/
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Postby MrSnowflake » Sat Jan 17, 2009 11:13 am

chaoz1336 wrote:
MrSnowflake wrote:Seems like imgSignature is still null. check that.


it cant be null, coz I can display the control.
and in
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. imgSignature = (ImageView) findViewById(R.drawable.mypic);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


I initialise it.... =/
Then I have some bad(/good) news for you but findingViewById() with a drawable won't return you a View...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby chaoz1336 » Sat Jan 17, 2009 1:00 pm

Ehrm... ok ^^

I found it xD
I forgot the ID in the xml-layout,
therefore I hold the graphics be R.drawables, instead of R.id .

thx a lot MrSnowFlakes, kudos 2 u ;)
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 20 guests