For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Sunday, January 18, 2015

unable to start activity ComponentInfo MainActivity java.lang.NullPointer Exception

Problem:

While working with Android you can face the error
Fatal Exception:java.lang.RuntimeException:unable to start activity ComponentInfo
MainActivity : java.lang.NullPointer Exception
So how to overcome this run time error in android?

Solution:

This type of error is occurs when you trying to access android control Button or
EditText before set main activity. so first set you activity and then after it access the control

Example:

Do not use as belowloginBtn = (Button)findViewById(R.id.button1);
u_login = (EditText)findViewById(R.id.editText1);
setContentView(R.layout.activity_main);

Use as belowsetContentView(R.layout.activity_main);
loginBtn = (Button)findViewById(R.id.button1);
u_login = (EditText)findViewById(R.id.editText1);








Share:

0 comments:

Post a Comment

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip