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

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive