Help with solving a NullPointerException issue I am working on a assignment. I am attempting to extend an existing class. I have unit tested my code. However, I have one method in my new class that has been giving me fits for the last couple of days. When I unit test my code, I am receiving NullPointerExceptions at a particular line in this code. I've rearranged the logic in this method many times without success. Will someone please take a look at my code below and provide me with some help or any suggestion. The method for which the exception is being thrown from is the addStatementBullet. This method is the last method in the code snippet below. Also, I've indicated, within the method, the statement that is throwing the exception. Your help will be greatly appreciated.
package practiceTEPT;
import java.io.*;
import java.io.File.*;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.aspose.slides.*;
import com.aspose.slides.Shapes;
import static practiceTEPT.ClearanceLevel.*;
/**
*
*/
public class TeboSlide extends Slide {
Rectangle body;
Rectangle[] classifiedBox = new Rectangle[2];
Rectangle titleBox;
Rectangle iconImageBar;
Rectangle subTitleBox;
int y=0;
/** Creates a new instance of TeboSlide */
public TeboSlide(ClearanceLevel slideClearanceLevel, String slTitle, String slSubTitle) {
super();
try{
String testText = "";
//For image Icon Bar
iconImageBar = super.getShapes().addRectangle(30,100,5650,600);
iconImageBar.getLineFormat().setShowLines(false);
iconImageBar.getFillFormat().setType(FillType.PICTURE);
InputStream iconInStream = new BufferedInputStream(new FileInputStream("C:\\NetBeansWorkspace\\TEPT\\NewCookBook\\tItemsGenerator\ \tIconGrouped.emf"));
Picture iconRectanglePicture = new Picture(super.getParent(), iconInStream);
int iconPictureId = super.getParent().getPictures().add(iconRectanglePicture);
iconImageBar.getFillFormat().setPictureId(iconPictureId);
//for classified rectangles
//Rectangle[] classifiedRect = new Rectangle[2];
classifiedBox[0] = super.getShapes().addRectangle(100,50,5560,100);
classifiedBox[1] = super.getShapes().addRectangle(100,4200,5560,100);
for (int index=0; index < classifiedBox.length; index++)
{
classifiedBox[index].addTextFrame(slideClearanceLevel.getClearanceLevelDesignation());
classifiedBox[index].getLineFormat().setShowLines(false);
if(index==0)
{
classifiedBox[index].getTextFrame().getParagraphs().get(0).setAlignment(TextAlignment.RIGHT);
}
else{
classifiedBox[index].getTextFrame().getParagraphs().get(0).setAlignment(TextAlignment.LEFT);
}
classifiedBox[index].getTextFrame().getParagraphs().get(0).getPortions().get(0).setFontColor(ja va.awt.Color.BLACK);
classifiedBox[index].getTextFrame().getParagraphs().get(0).getPortions().get(0).setFontHeight(( short)17);
classifiedBox[index].getTextFrame().getParagraphs().get(0).getPortions().get(0).setFontBold(tru e);
}
//for the slide title rectangle
titleBox = super.getShapes().addRectangle(100,200,5560,200);
titleBox.addTextFrame(slTitle);
titleBox.getLineFormat().setShowLines(false);
titleBox.getTextFrame().getParagraphs().get(0).setAlignment(TextAlignment.C ENTER);
titleBox.getTextFrame().getParagraphs().get(0).getPortions().get(0).setFont Color(java.awt.Color.BLACK);
titleBox.getTextFrame().getParagraphs().get(0).getPortions().get(0).setFont Height((short)36);
titleBox.getTextFrame().getParagraphs().get(0).getPortions().get(0).setFont Bold(false);
subTitleBox = super.getShapes().addRectangle(675,530,3060,150);
subTitleBox.addTextFrame(slSubTitle);
subTitleBox.getLineFormat().setShowLines(false);
subTitleBox.getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmen t.LEFT);
subTitleBox.getTextFrame().getParagraphs().get(0).getPortions().get(0).setF ontColor(java.awt.Color.BLACK);
subTitleBox.getTextFrame().getParagraphs().get(0).getPortions().get(0).setF ontHeight((short)17);
subTitleBox.getTextFrame().getParagraphs().get(0).getPortions().get(0).setF ontItalic(true);
subTitleBox.getTextFrame().getParagraphs().get(0).getPortions().get(0).setF ontBold(false);
//For slide body
body = super.getShapes().addRectangle(100,750,5560,3350);
body.getLineFormat().setShowLines(false);
addStatementBullet(testText);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
public Rectangle getBody(){
return body;
} public void addStatementBullet(String text){
int x=0;
Paragraph paragraph = new Paragraph();
try{
if(y==0){
this.getBody().addTextFrame(text); //<-- java.lang.NullPointerException thrown here
this.getBody().getTextFrame().setX(100);
this.getBody().getTextFrame().setY(750);
this.getBody().getTextFrame().setWidth(5560);
this.getBody().getTextFrame().setHeight(3350);
this.getBody().getTextFrame().setWrapText(true);
x=y;
y++;
}
else
{
paragraph.setText(text);
x = this.getBody().getTextFrame().getParagraphs().add(paragraph);
}
this.getBody().getTextFrame().getParagraphs().get(x).setHasBullet((short)1) ;
this.getBody().getTextFrame().getParagraphs().get(x).setBulletColor(java.aw t.Color.BLACK);
this.getBody().getTextFrame().getParagraphs().get(x).setBulletOffset((short )5);
this.getBody().getTextFrame().getParagraphs().get(x).setTextOffset((short)6 0);
this.getBody().getTextFrame().getParagraphs().get(x).getPortions().get(0).s etFontHeight((short)24);
}
catch(PptEditException ppt)
{
System.out.println(ppt.toString());
}
y++;
}
} |