Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting a String Tag for a fragment
    primarykey
    data
    text
    <p>What is wrong with this code snippet .... my app crashes here</p> <pre><code>frag.settext("Default Messaage"); // dEBUGGER SAYS THE PROBLEM IS HERE IT THROWS NPE </code></pre> <p>Code Snippet</p> <pre><code>public void question_displayer(View v){ Log.i("create","question_displayer()"); RamadanData data_object = new RamadanData(); fragment_question_displayer at = new fragment_question_displayer(); FragmentTransaction fragment_question = getSupportFragmentManager().beginTransaction().add(at, "why"); fragment_question.replace(R.id.framelayout1, new fragment_question_displayer() ,null); fragment_question.addToBackStack(null); fragment_question.commit(); fragment_question_displayer frag = (fragment_question_displayer)getSupportFragmentManager().findFragmentByTag("why"); frag.settext("Default Messaage"); // dEBUGGER SAYS THE PROBLEM IS HERE IT THROWS NPE </code></pre> <p><strong>fragment_question_displayer CLASS</strong> </p> <pre><code>package com.alisaeed.fragments; import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView.FindListener; import android.widget.TextView; import com.alisaeed.newramadan.R; public class fragment_question_displayer extends Fragment { Context context; TextView question_displayer; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { context = inflater.getContext(); View v= inflater.inflate(R.layout.question_displayer, container, false); // TextView question_displayer = (TextView)v.findViewById(R.id.textView_question ); // question_displayer.setText("Default Message"); return v; } public void settext(String question){ question_displayer = (TextView)getView().findViewById(R.id.textView_question); question_displayer.setText(question); } } </code></pre> <p><strong>question_displayer XML</strong></p> <pre><code>&lt;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=".Question_displayer" android:tag="Hello" &gt; &lt;Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button3" android:layout_alignParentBottom="true" android:layout_marginBottom="36dp" android:text="D" /&gt; &lt;Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button4" android:layout_alignLeft="@+id/button2" android:layout_marginBottom="15dp" android:text="C" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button3" android:layout_alignParentLeft="true" android:layout_marginBottom="25dp" android:text="B" /&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button2" android:layout_alignLeft="@+id/button2" android:layout_marginBottom="16dp" android:text="A" /&gt; &lt;TextView android:id="@+id/textView_question" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="14dp" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Any help will be highly appreciated ... ........... Iam beginner at this android programming </p> <p><strong>SCOTT</strong></p> <pre><code>public void question_displayer(View v){ Log.i("create","question_displayer()"); RamadanData data_object = new RamadanData(); fragment_question_displayer at = new fragment_question_displayer(); FragmentTransaction fragment_question = getSupportFragmentManager().beginTransaction().add(android.R.id.content,at, "why"); fragment_question.replace(R.id.framelayout1, new fragment_question_displayer() ,null); fragment_question.addToBackStack(null); fragment_question.commit(); getSupportFragmentManager().executePendingTransactions(); fragment_question_displayer frag = (fragment_question_displayer)getSupportFragmentManager().findFragmentByTag("why"); if(v.getId()==R.id.buttonnext) { String q = data_object.question_output(flag_autoquestion,"child","prayer" ); frag.settext(q); } switch(v.getId()){ case (R.id.buttonPrayer): { Log.i("create","prayer()"); if(child_selected == true &amp;&amp; adult_selected==false &amp;&amp; teen_selected==false ) { Log.i("create","child_selected"); String question= data_object.question_output(flag_autoquestion, "child","prayer"); Log.i("create",question); frag.settext(question); flag_autoquestion++; } break;} } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload