Thursday, 12 September 2013

Getting NullpointeException

Getting NullpointeException

Guys can you check it why i am getting a null pointer exception in this line,
cl = Class.forName(myClass);
Here's the code:
private void addBookmark(String[] values_array) {
LayoutInflater vi = (LayoutInflater)
getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.single_bookmark, null);
TextView text = (TextView) v.findViewById(R.id.bookmark_text);
Button button = (Button) v.findViewById(R.id.bookmark_button);
text.setText(values_array[1]);
final String myClass = values_array[0];
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Class<?> cl = null;
try {
cl = Class.forName(myClass); // <--- this is where i am
getting a null pointer exception
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Intent myIntent = new Intent(mContext, cl);
startActivity(myIntent);
}
});
how should I fix that? Or is there something I need to replace?

No comments:

Post a Comment