Fatal Exception : Main on android app -


i have problem project. if can solve problem please me..

this main code

import android.app.activity; import android.app.dialog; import android.content.pm.activityinfo; import android.util.floatmath; import android.util.log; import android.os.bundle; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.toast; import java.lang.math;  import com.kalkulator.r;  public class mainactivity extends activity implements onclicklistener {  private string str1="",str2="",str3="",op=""; private float num1,num2,num3,num4,num5; private long a,b=1; edittext ed;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     //setcontentview(r.layout.main);     setrequestedorientation(activityinfo.screen_orientation_portrait);      ed=(edittext)findviewbyid(r.id.edittext01);     view[] keys=new view[30];       keys[0]= findviewbyid(r.id.button1);      keys[1]= findviewbyid(r.id.button2);      keys[2]= findviewbyid(r.id.button3);       for(int i=0;i<keys.length;i++)     {         keys[i].setonclicklistener(this);     }     ed.settext(""); }   public void onclick(view v) {      switch(v.getid())     {         case r.id.button1:             str3=ed.gettext().tostring();             if(str3.contains("e"))             {                 toast.maketext(getapplicationcontext(),"factorial limit upto 25", toast.length_short).show();                 break;             }             a=long.parselong(str3);             if(a>25)             {                 toast.maketext(getapplicationcontext(),"factorial limit upto 25", toast.length_short).show();                 break;             }             for(long i=1;i<=a;i++)             {                 b*=i;             }             ed.settext(string.valueof(b));             b=1;             break;  ......           

and xml code

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainactivity" >  <edittext     android:id="@+id/edittext01"     android:layout_width="fill_parent"     android:layout_height="40dip"     android:layout_alignparentright="true"     android:layout_gravity="right"     android:cursorvisible="false"     android:gravity="right"     android:textstyle="italic" > </edittext>  <tablelayout android:id="@+id/tablelayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/edittext01" android:layout_below="@+id/edittext01" android:layout_margintop="28dp" android:stretchcolumns="*" >  <tablerow     android:id="@+id/tablerow02"     android:layout_width="wrap_content"     android:layout_height="wrap_content" >      <button         android:id="@+id/button1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="n!" /> ....... 

i don't know why, when run project on avd_for_3_7_fwvga_slide, have notification on log cat fatal exception : main.

thanks

//setcontentview(r.layout.main); must not commented, , should consider moving orientation androidmanifest file

also,

 keys[0]= findviewbyid(r.id.button1);  keys[1]= findviewbyid(r.id.button2);  keys[2]= findviewbyid(r.id.button3);   for(int i=0;i<keys.length;i++) {     keys[i].setonclicklistener(this); } ed.settext(""); 

you're calling findviewbyid on keys values index > gets nullpointerexception.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -