Thursday, April 24, 2014

imageButton null pointer error


Creating imagebutton null pointer error code below, please help seniors look
import android.content.Context;
import android.widget.ImageButton;
import android.widget.TableLayout;
import android.widget.TableRow;

public class PlatformPage extends TableLayout {
private ImageButton [] imageButton;

public PlatformPage (Context context) {
super (context);
}

public void show () {
buttonInit ();
addImageButton ();
}

public void buttonInit () {
/ / WeiimageButton set the background for each platform
for (int i = 0; i <6; i + +) {
imageButton [i] = new ImageButton (this.getContext ());
}
imageButton [0]. setBackground (getResources (). getDrawable (
R.drawable.qzone_116));
imageButton [1]. setBackground (getResources (). getDrawable (
R.drawable.sinaweibo_116));
imageButton [2]. setBackground (getResources (). getDrawable (
R.drawable.renren_116));
imageButton [3]. setBackground (getResources (). getDrawable (
R.drawable.tecentweibo_116));
imageButton [4]. setBackground (getResources (). getDrawable (
R.drawable.weixin_116));
. imageButton [5] setBackground (null);

for (int i = 0; i <6; i + +) {
imageButton [i]. setLayoutParams (new TableLayout.LayoutParams (
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
. imageButton [i] setPadding (5, 5, 5, 5);
}
}
}
Error prompt I imageButton [i] = new ImageButton (getContext ()) wrong
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
try
 
Context context = null;
public PlatformPage (Context context) {
super (context);
this.context = context;
}


 
imageButton [i] = new ImageButton (context);

Reply:
imgebutton not bound id chanting,,,
Reply:
cited a floor hjywyj reply:
try
 
Context context = null;
public PlatformPage (Context context) {
super (context);
this.context = context;
}


 
imageButton [i] = new ImageButton (context);
or error, the same error.
Reply:
private ImageButton [] imageButton ;/ / private ImageButton [] imageButton = new ImageButton [6];
Reply:
No array initialization problem, you have an array of six elements, private ImageButton [] imageButton = new ImageButton [6], there will certainly be wrong

No comments:

Post a Comment