MainActivity.java
public class MainActivity extends Activity {
static Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Class2 ji = new Class2();
ji.dothis();
}
});}}
Class2.java
public class Class2 extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void dothis() {
Toast.makeText(this,"It Doesn't Worked",Toast.LENGTH_LONG).show();
}
}
My Logcat generates NullPoint Exception every time.
java.lang.NullPointerException: Attempt to invoke virtual method ' android.content.res.Resources android.content.Context.getResources()' on a null object reference
I don't know what's wrong.
I face this problem many times, but I never understood the issue.