Null Pointer Exception Android
I am trying to make a button, count clicks and display them in a text
view. Here is my code:
public class Main extends Activity{
int c=0;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
if (container == null) {
return null;
}
ScrollView GPU_LAYOUT = (ScrollView)inflater.inflate(R.layout.gpu,
container, false);
TextView text =(TextView) GPU_LAY.findViewById(R.id.text1);
Button plus =(Button) GPU_LAY.findViewById(R.id.butt1);
plus.setOnClickListener(new OnClickListener() {//null pointer this
line, but it's from .setText i think
public void onClick(View v) {
c++;
text.setText(c);
}
});
}
return GPU_LAY;
}
No comments:
Post a Comment