Android TextView is failing with null pointer exception -


एंड्रॉइड टेक्स्टव्यू रिक्त सूचक अपवाद के साथ असफल रहा है

और इसके "disp.setText (" 0 ");"

इस विधि के अंदर "संरक्षित शून्य को क्रेट (बंडल से बचाया गया इन्स्टेंसस्टेट) {"

मैंने नेट में दिए गए अधिकांश सुझावों का प्रयास किया अभी भी इसे हल नहीं कर सका।

कृपया मदद की ज़रूरत है ....

मेरा लेआउट: "fragment_main.xml"

  & lt; रिलेटिव लेआउट xmlns: एंड्रॉयड = "http://schemas.android.com/apk/res/android" xmlns: उपकरण = "http://schemas.android.com/tools" एंड्रॉयड: layout_width = "match_parent" एंड्रॉयड: layout_height = "match_parent" एंड्रॉइड: onClick = "num_Clicked" android: paddingBottom = "@ dimen / activity_vertical_margin" एंड्रॉइड: paddingLeft = "@ dimen / activity_horizontal_margin" एंड्रॉइड: paddingRight = "@ dimen / activity_horizontal_margin" एंड्रॉइड: paddingTop = "@ dimen / activity_vertical_margin" उपकरण: संदर्भ = "Com.ullas.Test1.MainActivity $ प्लेसहोल्डर फ्रेगमेंट" & gt; & LT; TextView एंड्रॉयड: आईडी = "@ + id / textView1" एंड्रॉयड: layout_width = "fill_parent" एंड्रॉयड: layout_height = "wrap_content" एंड्रॉयड: layout_alignParentTop = "true" एंड्रॉयड: layout_centerHorizontal = "true" एंड्रॉयड: layout_marginTop = "17dp" एंड्रॉयड : गुरुत्वाकर्षण = "दाएं" एंड्रॉइड: टेक्स्ट = "बड़ा टेक्स्ट" एंड्रॉइड: टेक्स्ट एपरेरेंस = "? एंड्रॉइड: एटीआर / टेक्स्ट अप्परेंस लार्ज" / & gt; & Lt; / RelativeLayout & gt;   

और मेरी गतिविधि यह है: "MainActivity.java"

  आयात करें android.support.v7.app.ActionBarActivity; Import android.support.v4.app.Fragment; Importroid.os.Bundle; आयात करें android.view.LayoutInflater; Import android.view.Menu; आयात करें android.view.MenuItem; आयात करें android.view.View; आयात करें android.view.ViewGroup; Import android.widget। *; सार्वजनिक कक्षा MainActivity ActionBarActivity विस्तार [TextView disp; @ ओवरराइड संरक्षित शून्य को क्रिएट (बंडल सहेजा गया इन्स्टैंसस्टेट) {सुपर.नक्रेट (सहेजे गए इन्स्टेंसस्टेट); setContentView (R.layout.activity_main); Disp = (TextView) findViewById (R.id.textView1); disp.setText ( "0"); अगर (सहेजे गए इन्स्टेंसस्टेट == रिक्त) {getSupportFragmentManager ()। beginTransaction ()। जोड़ें (आर.आईड.कंटेनइयर, नया प्लेसहोल्डर फ्रेगमेंट ())। commit (); }}    

आप अपने लेआउट को बताते हैं "fragment_main.xml" और textview इस में है xml।

अपने कोड में, आप एक अलग लेआउट xml सेट कर रहे हैं:

  setContentView (R.layout.activity_main); disp = (TextView) findViewById (R.id.textView1);   

, लेआउट आप उपयोग करना चाहते सेट करना होगा क्रम में अपने TextView तक पहुंचने के लिए सक्षम होने के लिए:

  setContentView (R.layout.fragment_main); disp = (TextView) findViewById (R.id.textView1);    

Comments

Post a Comment

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -