java - New Activity Goes to Blank Screen -


i'm pretty new android studio , i'm having difficulty starting new activity. i've triple checked code , can't figure out problem is. i've google searched couple of hours nobody seems have had same problem me. logcat isn't reporting problem, when run app, , click button, app goes blank screen. please help!

public class originalfragment extends fragment {  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view rootview = inflater.inflate(r.layout.fragment_original, container, false);      return rootview; }  }  public class mainfragment extends fragment {  private alertdialog mdialog; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view rootview = inflater.inflate(r.layout.fragment_main, container, false);     //sets button     view aboutbutton = rootview.findviewbyid(r.id.about_button);     aboutbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             alertdialog.builder builder = new alertdialog.builder(getactivity());             builder.settitle(r.string.about_title);             builder.setmessage(r.string.about_text);             builder.setcancelable(false);             builder.setpositivebutton(r.string.ok_label,                     new dialoginterface.onclicklistener() {                         @override                         public void onclick(dialoginterface dialoginterface, int i) {                         }                      });             mdialog=builder.show();         }      });      view originalbutton = rootview.findviewbyid(r.id.original_button);     originalbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             intent intent = new intent(getactivity(), originalactivity.class);             getactivity().startactivity(intent);         }     });      view picturebutton = rootview.findviewbyid(r.id.picture_button);     originalbutton.setonclicklistener(new view.onclicklistener(){         @override         public void onclick(view view){             intent intent = new intent(getactivity(), pictureactivity.class);             getactivity().startactivity(intent);         }     });      return rootview; }   @override public void onpause(){     super.onpause();     if (mdialog != null)         mdialog.dismiss(); }  }  public class mainactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main); }  }   <framelayout  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:clipchildren= "false" tools:context= "org.example.abstract_art.mainactivity">   <fragment android:id= "@+id/main_fragment"     class= "org.example.abstract_art.mainfragment"     android:layout_width= "wrap_content"     android:layout_height= "wrap_content"     android:layout_gravity= "center"     tools:layout= "@layout/fragment_main" />  </framelayout>  <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:background="@drawable/select_shapes_background" tools:context="org.example.abstract_art.originalactivity">   <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="select shapes"     android:id="@+id/textview"     android:textsize="@dimen/menu_text_size"     android:layout_alignparenttop="true"     android:layout_centerhorizontal="true" />  <fragment     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:name="org.example.abstract_art.originalfragment"     android:id="@+id/fragment"     android:layout_below="@+id/textview"     android:layout_centerhorizontal="true"     tools:layout="@layout/fragment_original" />   </relativelayout>  <linearlayout 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:background="@drawable/menu_background" android:elevation="@dimen/elevation_high" android:orientation="vertical" android:padding="@dimen/menu_padding" tools:context=".org.example.abstract_art.mainfragment">   <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginbottom="@dimen/menu_space"     android:text="@string/long_app_name"     android:textappearance="?android:textappearancelarge"     android:textsize="@dimen/menu_text_size"/>  <button     android:id="@+id/original_button"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_margin="@dimen/menu_button_margin"     android:padding="@dimen/menu_button_padding"     android:text="@string/original_label"/>  <button     android:id="@+id/picture_button"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_gravity="center"     android:layout_margin="@dimen/menu_button_margin"     android:padding="@dimen/menu_button_padding"     android:text="@string/picture_label"/>  <button     android:id="@+id/about_button"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_gravity="center"     android:layout_margin="@dimen/menu_button_margin"     android:padding="@dimen/menu_button_padding"     android:text="@string/about_label"/>   </linearlayout>  <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:background="@drawable/menu_background"  android:orientation="vertical" android:padding="@dimen/menu_padding" tools:context="org.example.abstract_art.originalfragment">   <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="circles"     android:id="@+id/circlestext"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:textsize="@dimen/menu_text_size"/>  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="rectangles"     android:id="@+id/rectanglestext"     android:layout_below="@+id/circlestext"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:textsize="@dimen/menu_text_size"/>  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="squares"     android:id="@+id/squarestext"     android:layout_below="@+id/rectanglestext"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:textsize="@dimen/menu_text_size"/> <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="triangles"     android:id="@+id/trianglestext"     android:layout_below="@+id/squarestext"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:textsize="@dimen/menu_text_size"/> <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="4 point stars"     android:id="@+id/fourstartext"     android:layout_below="@+id/trianglestext"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:textsize="@dimen/menu_text_size"/> <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="6 point stars"     android:id="@+id/sixstartext"     android:layout_below="@+id/fourstartext"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:textsize="@dimen/menu_text_size"/>  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="create art!"     android:id="@+id/createoriginalbutton"     android:layout_below="@+id/sixstartext"     android:layout_centerhorizontal="true" />   </relativelayout> 

please make sure below things

  1. you have define main activity, originalactivity,pictureactivity in manifest file
  2. please make sure set layout in activity or fragment , bind components of layout in class
  3. try below code

    button originalbtn; //define class level

    originalbtn=(button)rootview.findviewbyid(r.id.original_button); 

now can set click listener , code in it

second main things define 2 times originalbutton click listener think thats why problem

i think second listener should picturebutton click listener


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -