I’m simply trying to trigger a new activity from a button click but every time I click said button I get an error saying “source not found” with “edit source lookup path” underneath. This seems to be a pretty common problem and usually seems to be associated with either the OnClickListener method or the source path not pointing at the right files.
Here’s the file for the original activity:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.homebutton2);
btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), DisplayExplanation.class);
startActivityForResult(intent,0);
}
});
}
}
I’m sure that there isn’t a problem with the OnClickListener because if I replace the intent with a toast, the toast appears just fine.
I’ve also restarted the project to make absolutely sure that the source path is right; it’s pointing at the right .jar files and my project folder. The API matches that in the manifest too.
For completeness, here is the activity that I’m trying to open:
public class DisplayExplanation extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_explanation);
}
}
I’d really appreciate any help you can give me on this – seems like I’ve been banging my head against a wall for hours!
use
instead of
to start New Activity on Button Click always pass Current Activity Context instead of Current View context like you are passing context for starting Activity