Nullpointer exception on android device

36 views
Skip to first unread message

johnma...@gmail.com

unread,
Apr 22, 2015, 11:11:10 AM4/22/15
to codenameone...@googlegroups.com
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
are happening in the device

Kindly assist



Shai Almog

unread,
Apr 22, 2015, 11:45:30 AM4/22/15
to codenameone...@googlegroups.com, johnma...@gmail.com
We will need the stack of the null pointer exception and the specific line referenced highlighted.

john mangirazi

unread,
Apr 22, 2015, 12:09:20 PM4/22/15
to codenameone...@googlegroups.com
The link is to the app.

Download the application by clicking this link 
http://codename-one.appspot.com/5787923359203328/d37d7935-beb4-4666-8151-dce534d91b8b/Beer-release.apk

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/OULdxGVH19I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/386689ea-3442-4daf-9e06-94813bcd32b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shai Almog

unread,
Apr 23, 2015, 2:13:22 AM4/23/15
to codenameone...@googlegroups.com, johnma...@gmail.com
We don't install user apps.
Please install DDMS and connect your device to get the stack trace.
Reply all
Reply to author
Forward
0 new messages