Unhandled Exception

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Unhandled Exception

Postby Emperor » Thu Jul 30, 2009 4:57 am

Hi,

I am creating 4 buttons in the linear layout at the very bottom of the screen using the below code snippet

<LinearLayout
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >

<Button
android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/darktext"
android:text="Back"
android:background="@drawable/blb_upr_r_btn"
android:layout_marginRight="1px"
android:layout_marginLeft="1px" android:clickable="true" android:ellipsize="none" />

similarly other 3 buttons such as Add, Find and Next

</LinearLayout>

I initialised all 4 buttons inside the onClick() using the following snippet

private Button back, add, find, next;

back=(Button)findViewById(R.id.back);
back.setOnClickListener(this);

similarly other 3

I am handling the same using onClickListener

if(id==back.getId())
{
//code
}
else if(id==add.getId())
{
//code
}
else if(id==find.getId())
{
//code
}
else if(id==next.getId())
{
next.setText("Clicked");
}

But When i run the application and click on any of these 4 buttons the application closes telling some unhandled exception has occured, please help me to sort out this
Emperor
Freshman
Freshman
 
Posts: 7
Joined: Thu Jul 30, 2009 4:36 am

Top

Postby Sowmya » Thu Jul 30, 2009 11:12 am

Hi,
Use ddms tool or launch logcat to check the exception
Sowmya
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Mar 06, 2009 7:49 am

Postby Emperor » Thu Jul 30, 2009 6:19 pm

Sowmya wrote:Hi,
Use ddms tool or launch logcat to check the exception




Hi sowmya,

I am using ddms tool, but its showing nothing in ddms, its blank
Emperor Bharath
Emperor
Freshman
Freshman
 
Posts: 7
Joined: Thu Jul 30, 2009 4:36 am

Postby Sowmya » Fri Jul 31, 2009 5:09 am

You can see the runtime exceptions in the log..i guess It would be helpful if you post your code and the xml..
Sowmya
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Mar 06, 2009 7:49 am

Me too

Postby Dayn » Tue Aug 04, 2009 2:27 pm

Hi

I think I have the same error of exception.

my simple code is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         final Button effacer = (Button)findViewById(R.id.effacer);
  3.  
  4.    
  5.  
  6.        
  7.  
  8.         effacer.setOnClickListener(new Button.OnClickListener()
  9.  
  10.         {
  11.  
  12.             public void onClick(View v)
  13.  
  14.             {
  15.  
  16.                 try
  17.  
  18.                 {
  19.  
  20.                         Log.v(TAG, "J'ai bien appuyé sur le bouton effacer");
  21.  
  22.                 }
  23.  
  24.                 catch (Exception e)
  25.  
  26.                 {
  27.  
  28.                         Log.v(TAG, "Failed Exception :"+ e.getMessage());
  29.  
  30.                 }
  31.  
  32.             }
  33.  
  34.         });
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


and ddms says:

08-04 13:17:50.806: DEBUG/AndroidRuntime(1719): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
08-04 13:17:50.826: DEBUG/AndroidRuntime(1719): CheckJNI is ON
08-04 13:17:51.207: DEBUG/AndroidRuntime(1719): --- registering native functions ---
08-04 13:17:52.235: INFO/ActivityManager(565): Starting activity: Intent { flags=0x10000000 comp={m.dany.anrdoid.inertfacegraphiquevvm/m.dany.anrdoid.inertfacegraphiquevvm.InerfaceGraphiqueVVM} }
08-04 13:17:52.315: DEBUG/AndroidRuntime(1719): Shutting down VM
08-04 13:17:52.315: DEBUG/dalvikvm(1719): DestroyJavaVM waiting for non-daemon threads to exit
08-04 13:17:52.366: DEBUG/dalvikvm(1719): DestroyJavaVM shutting VM down
08-04 13:17:52.389: DEBUG/dalvikvm(1719): HeapWorker thread shutting down
08-04 13:17:52.389: DEBUG/dalvikvm(1719): HeapWorker thread has shut down
08-04 13:17:52.389: DEBUG/jdwp(1719): JDWP shutting down net...
08-04 13:17:52.418: ERROR/AndroidRuntime(1719): ERROR: thread attach failed
08-04 13:17:52.445: DEBUG/dalvikvm(1719): VM cleaning up
08-04 13:17:52.576: INFO/ActivityManager(565): Start proc m.dany.anrdoid.inertfacegraphiquevvm for activity m.dany.anrdoid.inertfacegraphiquevvm/.InerfaceGraphiqueVVM: pid=1727 uid=10021 gids={}
08-04 13:17:52.707: DEBUG/dalvikvm(1719): LinearAlloc 0x0 used 637060 of 4194304 (15%)
08-04 13:17:53.757: DEBUG/dalvikvm(1727): GC freed 747 objects / 53848 bytes in 110ms
08-04 13:17:54.186: DEBUG/AndroidRuntime(1727): Shutting down VM
08-04 13:17:54.186: WARN/dalvikvm(1727): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
08-04 13:17:54.209: ERROR/AndroidRuntime(1727): Uncaught handler: thread main exiting due to uncaught exception
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): java.lang.RuntimeException: Unable to start activity ComponentInfo{m.dany.anrdoid.inertfacegraphiquevvm/m.dany.anrdoid.inertfacegraphiquevvm.InerfaceGraphiqueVVM}: java.lang.NullPointerException
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.os.Looper.loop(Looper.java:123)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.app.ActivityThread.main(ActivityThread.java:3948)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at java.lang.reflect.Method.invoke(Method.java:521)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at dalvik.system.NativeStart.main(Native Method)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): Caused by: java.lang.NullPointerException
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at m.dany.anrdoid.inertfacegraphiquevvm.InerfaceGraphiqueVVM.onCreate(InerfaceGraphiqueVVM.java:51)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
08-04 13:17:54.226: ERROR/AndroidRuntime(1727): ... 11 more
08-04 13:17:54.286: INFO/Process(565): Sending signal. PID: 1727 SIG: 3
08-04 13:17:54.286: INFO/dalvikvm(1727): threadid=7: reacting to signal 3
08-04 13:17:54.386: INFO/dalvikvm(1727): Wrote stack trace to '/data/anr/traces.txt'
08-04 13:17:54.666: INFO/jdwp(1727): received file descriptor 24 from ADB
08-04 13:18:02.346: WARN/ActivityManager(565): Launch timeout has expired, giving up wake lock!
08-04 13:18:02.405: INFO/Process(1727): Sending signal. PID: 1727 SIG: 9
08-04 13:18:02.630: INFO/ActivityManager(565): Process m.dany.anrdoid.inertfacegraphiquevvm (pid 1727) has died.
08-04 13:18:03.156: WARN/InputManagerService(565): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4376f078


I can send you my complete code on a PM if you want

thanks

Dayn
User avatar
Dayn
Developer
Developer
 
Posts: 31
Joined: Thu Jul 09, 2009 10:45 am
Location: Paris and Dijon

re RE

Postby Dayn » Tue Aug 04, 2009 2:32 pm

So my complete java code is :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package m.dany.anrdoid.inertfacegraphiquevvm;
  2.  
  3.  
  4.  
  5. import android.app.TabActivity;
  6.  
  7. import android.content.Intent;
  8.  
  9. import android.os.Bundle;
  10.  
  11. import android.util.Log;
  12.  
  13. import android.view.View;
  14.  
  15. import android.widget.Button;
  16.  
  17. import android.widget.TabHost;
  18.  
  19. import android.widget.TabHost.TabSpec;
  20.  
  21.  
  22.  
  23. public class InterfaceGraphiqueVVM extends TabActivity {
  24.  
  25.        
  26.  
  27.         public Button effacer;
  28.  
  29.        
  30.  
  31.         private static final String TAG = "MyActivity";
  32.  
  33.                
  34.  
  35.     /** Called when the activity is first created. */
  36.  
  37.     @Override
  38.  
  39.     public void onCreate(Bundle savedInstanceState) {
  40.  
  41.         super.onCreate(savedInstanceState);
  42.  
  43.         //setContentView(R.layout.main);
  44.  
  45.        
  46.  
  47.         setContentView(R.layout.tabs);
  48.  
  49.        
  50.  
  51.         final TabHost oTabHost = getTabHost();
  52.  
  53.        
  54.  
  55.         TabSpec ts1 = oTabHost.newTabSpec("tab1");
  56.  
  57.                         ts1.setIndicator("Messagerie", getResources().getDrawable(R.drawable.mail_blue32));                    
  58.  
  59.                         ts1.setContent(new Intent(this, TabVoicemail.class));                          
  60.  
  61.         oTabHost.addTab(ts1);      
  62.  
  63.            
  64.  
  65.         TabSpec ts2 = oTabHost.newTabSpec("tab2");
  66.  
  67.                                 ts2.setIndicator("Configuration", getResources().getDrawable(R.drawable.config32));
  68.  
  69.                         ts2.setContent(new Intent(this, TabConfig.class));
  70.  
  71.         oTabHost.addTab(ts2);
  72.  
  73.                
  74.  
  75.         oTabHost.setCurrentTab(0);
  76.  
  77.        
  78.  
  79.        
  80.  
  81.        
  82.  
  83.         effacer = (Button)findViewById(R.id.effacer);
  84.  
  85.    
  86.  
  87.        
  88.  
  89.         effacer.setOnClickListener(new Button.OnClickListener()
  90.  
  91.         {
  92.  
  93.             public void onClick(View v)
  94.  
  95.             {
  96.  
  97.                 try
  98.  
  99.                 {
  100.  
  101.                         Log.v(TAG, "J'ai bien appuyé sur le bouton effacer");
  102.  
  103.                 }
  104.  
  105.                 catch (Exception e)
  106.  
  107.                 {
  108.  
  109.                         Log.v(TAG, "Failed Exception :"+ e.getMessage());
  110.  
  111.                 }
  112.  
  113.             }
  114.  
  115.         });
  116.  
  117.            
  118.  
  119.     }
  120.  
  121. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


thanks in advance

Dayn
User avatar
Dayn
Developer
Developer
 
Posts: 31
Joined: Thu Jul 09, 2009 10:45 am
Location: Paris and Dijon

Top

I fix it

Postby Dayn » Tue Aug 04, 2009 2:49 pm

I just add my java code on my tab class like that

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package m.dany.anrdoid.inertfacegraphiquevvm;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.util.Log;
  10.  
  11. import android.view.View;
  12.  
  13. import android.widget.Button;
  14.  
  15.  
  16.  
  17. public class TabVoicemail extends Activity {
  18.  
  19.        
  20.  
  21.         public Button effacer;
  22.  
  23.        
  24.  
  25.         private static final String TAG = "MyActivity";
  26.  
  27.        
  28.  
  29.         @Override
  30.  
  31.         protected void onCreate(Bundle savedInstanceState) {
  32.  
  33.                 // TODO Auto-generated method stub
  34.  
  35.                 super.onCreate(savedInstanceState);    
  36.  
  37.                
  38.  
  39.                  setContentView(R.layout.content_tab_voicemail);
  40.  
  41.                  
  42.  
  43.                   effacer = (Button)findViewById(R.id.effacer);
  44.  
  45.                    
  46.  
  47.                
  48.  
  49.               effacer.setOnClickListener(new Button.OnClickListener()
  50.  
  51.               {
  52.  
  53.                   public void onClick(View v)
  54.  
  55.                   {
  56.  
  57.                                 try
  58.  
  59.                                 {
  60.  
  61.                                 Log.v(TAG, "J'ai bien appuyé sur le bouton effacer");
  62.  
  63.                         }
  64.  
  65.                         catch (Exception e)
  66.  
  67.                         {
  68.  
  69.                                 Log.v(TAG, "Failed Exception :"+ e.getMessage());
  70.  
  71.                         }
  72.  
  73.                    }
  74.  
  75.                });
  76.  
  77.         }
  78.  
  79. }
  80.  
  81.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


which call on my first java code with this line

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. TabSpec ts1 = oTabHost.newTabSpec("tab1");
  2.  
  3.                         ts1.setIndicator("Messagerie", getResources().getDrawable(R.drawable.mail_blue32));                    
  4.  
  5.                         ts1.setContent(new Intent(this, TabVoicemail.class));                          
  6.  
  7.         oTabHost.addTab(ts1);  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



so now its fixed maybe its the same issue Emperor.

Dayn
User avatar
Dayn
Developer
Developer
 
Posts: 31
Joined: Thu Jul 09, 2009 10:45 am
Location: Paris and Dijon

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests