Am experiencing a null pointer exception on the device.i have a app that is running well on the simulator but the android release produce an nullpointer exception .I have images and 3 csv files in my src folder.here is the code
package com.jmangirazi.Beer;
import com.codename1.components.MultiButton;
import com.codename1.io.CSVParser;
import com.codename1.location.Location;
import com.codename1.location.LocationManager;
import com.codename1.maps.Coord;
import com.codename1.maps.MapComponent;
import com.codename1.maps.layers.PointLayer;
import com.codename1.maps.layers.PointsLayer;
import com.codename1.ui.Container;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Image;
import com.codename1.ui.Label;
import com.codename1.ui.Tabs;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.ui.util.UITimer;
import java.io.IOException;
import java.io.InputStream;
public class Beer {
private Form current;
private Form splash;
public void init(Object context) {
try {
Resources theme = Resources.openLayered("/theme");
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
} catch(IOException e){
e.printStackTrace();
}
}
public void start() {
if(current != null){
current.show();
return;
}
try {
//SplashForm();
ShowMain();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void stop() {
current = Display.getInstance().getCurrent();
}
public void destroy() {
}
private Container getBeerComponent() throws IOException{
InputStream is = Display.getInstance().getResourceAsStream(getClass(),"/BeerList.csv");
CSVParser parser = new CSVParser();
String [][] data = parser.parse(is);
// System.out.println(data.length);
//jump row at 0 heading
Container m = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for(int row = 0;row < data.length -1;row ++) {
MultiButton mb = new MultiButton();
for (int col = 0; col < 3; col++) {
mb.setIcon(returnImage("/beerSample.png"));
mb.setTextLine1(data[row][1]);
mb.setTextLine2(data[row][2]);
mb.setTextLine3(data[row][3]);
}
m.addComponent(mb);
m.setScrollable(true);
}
return m;
}
private Container getLocationComponent() throws IOException{
InputStream is = Display.getInstance().getResourceAsStream(getClass(),"/bars.csv");
CSVParser parser = new CSVParser();
String [][] data = parser.parse(is);
//jump row at 0 heading
Container m = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for(int row = 0;row < data.length -1;row ++) {
MultiButton mb = new MultiButton();
for (int col = 0; col < 4; col++) {
mb.setTextLine1(data[row][1]);
mb.setTextLine2(data[row][2]);
mb.setTextLine3(data[row][3]);
}
m.addComponent(mb);
m.setScrollable(true);
}
return m;
}
private Container getEventsComponent() throws IOException{
InputStream is = Display.getInstance().getResourceAsStream(getClass(),"/events.csv");
CSVParser parser = new CSVParser();
String [][] data = parser.parse(is);
//jump row at 0 heading
Container m = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for(int row = 0;row < data.length -1;row ++) {
MultiButton mb = new MultiButton();
for (int col = 0; col < 4; col++) {
mb.setTextLine1(data[row][1]);
mb.setTextLine2(data[row][2]);
mb.setTextLine3(data[row][3]);
}
m.addComponent(mb);
m.setScrollable(true);
}
return m;
}
//this the splash screen
private void SplashForm() {
splash = new Form("Beer Genius");
splash.setLayout(new BorderLayout());
Container ConSplash = new Container();
BorderLayout b = new BorderLayout();
b.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER);
ConSplash.setLayout(b);
//set my image name
String imageName = "/beer.png";
//call image
Image img = returnImage(imageName);
Label l = new Label(img);
ConSplash.addComponent(BorderLayout.CENTER, l);
splash.addComponent(BorderLayout.CENTER, ConSplash);
splash.show();
Display.getInstance().callSerially(new Runnable() {
public void run() {
splash.getContentPane().animateHierarchy(5000);
new UITimer(new Runnable() {
public void run() {
try {
ShowMain();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}).schedule(2000, false, splash);
}
});
}
private Image returnImage(String imageName) {
Image img = null;
try {
img = Image.createImage(imageName);
} catch (IOException ex) {
}
return img;
}
private void ShowMain() throws IOException{
Form hi = new Form("Beer Genius");
//Toolbar t =new Toolbar();
hi.setLayout(new BorderLayout());
// Toolbar t= new Toolbar();
Tabs tb = new Tabs();
tb.addTab("Beer", getBeerComponent());
tb.addTab("Locations", getLocationComponent());
tb.addTab("Events", getEventsComponent());
tb.addTab("Humour", getJokes());
tb.addTab("Map",getMapComponent());
tb.showTabs();
hi.addComponent(BorderLayout.CENTER,tb);
hi.show();
}
private Container getJokes() throws IOException{
InputStream is = Display.getInstance().getResourceAsStream(getClass(),"/BeerHumor.csv");
CSVParser parser = new CSVParser(':');
String [][] data = parser.parse(is);
//jump row at 0 heading
Container m = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for(int row = 0;row < data.length -1;row ++) {
MultiButton mb = new MultiButton();
for (int col = 0; col < 2; col++) {
mb.setTextLine1(data[row][0]);
mb.setTextLine2(data[row][1]);
mb.setTextLine3(data[row][2]);
}
m.addComponent(mb);
m.setScrollable(true);
}
return m;
}
private Container getMapComponent (){
Container map = new Container();
map.setLayout(new BorderLayout());
MapComponent mc = new MapComponent();
try {
Location loc = LocationManager.getLocationManager().getCurrentLocation();
Coord lastLocation = new Coord(loc.getLatitude(),loc.getLongitude());
Image pin = returnImage("/pin.png");
PointsLayer pl = new PointsLayer();
pl.setPointIcon(pin);
PointLayer p = new PointLayer(lastLocation,"You are here",pin);
p.setDisplayName(true);
pl.addPoint(p);
mc.addLayer(pl);
} catch (IOException ex) {
ex.printStackTrace();
}
mc.zoomToLayers();
map.addComponent(BorderLayout.CENTER,mc);
return map;
}
}
on the simulator i dont have any parsing errors or exceptions.Is there way the that i can do to debug the error beta i the device which can reflect the error that