本文介绍了Android的无法调用另一个类时开始活动componentinfo错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林书面方式它调用另一个类的应用程序,但每次我这样做,我不断收到无法启动活动componentinfo的错误。

Im writting an app which calls another class, but everytime I do, i keep getting the "unable to start activity componentinfo" error.

在code是如下:

  package android.Maps;


public class HomeScreen extends MapActivity {
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    MapController mapController;
    MyPositionOverlay positionOverlay;

    GeneticAlgorithm2 GA2;
    //private MyPositionOverlay popListHome;
    //public static int populationSizeHome;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //popListHome = new MyPositionOverlay(null, null);

        //populationSizeHome = popListHome.overlayItemList();

        //positionOverlay.overlayItemList


        MapView myMapView = (MapView)findViewById(R.id.myMapView);
        //myMapView.setBuiltInZoomControls(true);
        mapController = myMapView.getController();

        myMapView.setSatellite(true);
        myMapView.setStreetView(true);
        myMapView.displayZoomControls(false);

        mapController.setZoom(17);

        Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
        int markerWidth = marker.getIntrinsicWidth();
        int markerHeight = marker.getIntrinsicHeight();
        marker.setBounds(0, markerHeight, markerWidth, 0);

        //Call Genetic Algorithm
        GA2 = new GeneticAlgorithm2();


        // Add the MyPositionOverlay
        positionOverlay = new MyPositionOverlay(marker, HomeScreen.this);
        List<Overlay> overlays = myMapView.getOverlays();
        overlays.add(positionOverlay);

        LocationManager locationManager;
        String context = Context.LOCATION_SERVICE;
        locationManager = (LocationManager)getSystemService(context);

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = locationManager.getBestProvider(criteria, true);

        Location location = locationManager.getLastKnownLocation(provider);

        updateWithNewLocation(location);

        locationManager.requestLocationUpdates(provider, 2000, 10,   
                locationListener);


        //GeneticAlgorithm2 GA2 = new GeneticAlgorithm2();

        final Button buttonRun = (Button) findViewById(R.id.btnRun);
        buttonRun.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                Context context = getApplicationContext();
                CharSequence text = "Running";
                int duration = Toast.LENGTH_SHORT;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();



                //This statement works
                System.out.println(positionOverlay.overlayItemList.size());

                Iterator<OverlayItem> iter = positionOverlay.overlayItemList.iterator();
                System.out.println(positionOverlay.overlayItemList);
                while (iter.hasNext()){
                    Object element = iter.next();
                    System.out.println(element + "");
                }

                //GeneticAlgorithm2 GA2;
                //GA2.start();
                GA2.test();



            }// End of onClick
        });

    }// End of onCreate

    /*public HomeScreen (){
        popListHome = new MyPositionOverlay(null, null);

        populationSizeHome = popListHome.overlayItemList();


    }*/

    private final LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            updateWithNewLocation(location);
        }

        public void onProviderDisabled(String provider){
            updateWithNewLocation(null);
        }

        public void onProviderEnabled(String provider){ }
        public void onStatusChanged(String provider, int status, 
                Bundle extras){ }
    };

    private void updateWithNewLocation(Location location) {
        String latLongString;
        TextView myLocationText;
        myLocationText = (TextView)findViewById(R.id.myLocationText);
        String addressString = "No address found";

        if (location != null) {
            // Update my location marker
            positionOverlay.setLocation(location);

            // Update the map location.
            Double geoLat = location.getLatitude()*1E6;
            Double geoLng = location.getLongitude()*1E6;
            GeoPoint point = new GeoPoint(geoLat.intValue(), 
                    geoLng.intValue());

            mapController.animateTo(point);

            double lat = location.getLatitude();
            double lng = location.getLongitude();
            latLongString = "Lat:" + lat + "\nLong:" + lng;

            double latitude = location.getLatitude();
            double longitude = location.getLongitude();

            Geocoder gc = new Geocoder(this, Locale.getDefault());
            try {
                List<Address> addresses = gc.getFromLocation(latitude, 
                        longitude, 1);
                StringBuilder sb = new StringBuilder();
                if (addresses.size() > 0) {
                    Address address = addresses.get(0);

                    for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
                        sb.append(address.getAddressLine(i)).append("\n");

                    sb.append(address.getLocality()).append("\n");
                    sb.append(address.getPostalCode()).append("\n");
                    sb.append(address.getCountryName());
                }
                addressString = sb.toString();
            } catch (IOException e) {}
        } else {
            latLongString = "No location found";
        }
        myLocationText.setText("Your Current Position is:\n" + 
                latLongString + "\n" + addressString);
    }




}

和从此类IM试图调用这个类:

and from this class im trying to call this class:

    package android.Maps;


public class GeneticAlgorithm2  {

    public static int populationSize;
    private MyPositionOverlay popList;

    public int route[] = new int[populationSize +1];
    int pointLimit;
    int iterations;
    double mutationRate = 0.10;

    //Canvas C = null;
    //Dimension CD;
    //Label L;
    //Graphics GC;
    //int Initial_population = 800;
    int matingPopulation = populationSize/2;
    int favPopulation = matingPopulation/2;
    int numOfCities = 30;
    int cutLength = numOfCities/5;
    //double Mutation_probability = 0.10;

    double loops=1.5;
    int Epoch;
    double xlow = 0.0;
    double ylow = 0.0;
    double xhigh = 100.0;
    double yhigh = 100.0;
    double xrange, yrange;
    double minCost = 5.0;
    double timeStart,timeEnd;
    Thread T = null;
    double costPerfect = 0.;

    boolean started = false;

    City [] cities;
    Chromosome [] chromosomes;







    public GeneticAlgorithm2() {

        // Calling My Position Overlay class
        popList = new MyPositionOverlay(null, null);

        //Sets the population size to the number of markers
        populationSize = popList.overlayItemList.size();
        //start();
        test();

    }



    public void test(){
        System.out.println("test");
    }




}//End of Genetic Algorithm 2 class

请帮忙

已更新*

15 05-30:33:33.161:E / AndroidRuntime(916):致命异常:主要
05-30 15:33:33.161:E / AndroidRuntime(916):了java.lang.RuntimeException:无法启动活动ComponentInfo {android.Maps.Google2 / android.Maps.HomeScreen}:显示java.lang.NullPointerException
05-30 15:33:33.161:E / AndroidRuntime(916):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.os.Handler.dispatchMessage(Handler.java:99)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.os.Looper.loop(Looper.java:123)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.app.ActivityThread.main(ActivityThread.java:4627)
05-30 15:33:33.161:E / AndroidRuntime(916):在java.lang.reflect.Method.invokeNative(本机方法)
05-30 15:33:33.161:E / AndroidRuntime(916):在java.lang.reflect.Method.invoke(Method.java:521)
05-30 15:33:33.161:E / AndroidRuntime(916):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
05-30 15:33:33.161:E / AndroidRuntime(916):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-30 15:33:33.161:E / AndroidRuntime(916):在dalvik.system.NativeStart.main(本机方法)
05-30 15:33:33.161:E / AndroidRuntime(916):致:显示java.lang.NullPointerException
05-30 15:33:33.161:E / AndroidRuntime(916):在com.google.android.maps.ItemizedOverlay.boundCenterBottom(ItemizedOverlay.java:158)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.Maps.MyPositionOverlay(MyPositionOverlay.java:28)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.Maps.GeneticAlgorithm2(GeneticAlgorithm2.java:51)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.Maps.HomeScreen.onCreate(HomeScreen.java:76)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-30 15:33:33.161:E / AndroidRuntime(916):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-30 15:33:33.161:E / AndroidRuntime(916):11 ...更多

05-30 15:33:33.161: E/AndroidRuntime(916): FATAL EXCEPTION: main05-30 15:33:33.161: E/AndroidRuntime(916): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.Maps.Google2/android.Maps.HomeScreen}: java.lang.NullPointerException05-30 15:33:33.161: E/AndroidRuntime(916): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)05-30 15:33:33.161: E/AndroidRuntime(916): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)05-30 15:33:33.161: E/AndroidRuntime(916): at android.app.ActivityThread.access$2300(ActivityThread.java:125)05-30 15:33:33.161: E/AndroidRuntime(916): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)05-30 15:33:33.161: E/AndroidRuntime(916): at android.os.Handler.dispatchMessage(Handler.java:99)05-30 15:33:33.161: E/AndroidRuntime(916): at android.os.Looper.loop(Looper.java:123)05-30 15:33:33.161: E/AndroidRuntime(916): at android.app.ActivityThread.main(ActivityThread.java:4627)05-30 15:33:33.161: E/AndroidRuntime(916): at java.lang.reflect.Method.invokeNative(Native Method)05-30 15:33:33.161: E/AndroidRuntime(916): at java.lang.reflect.Method.invoke(Method.java:521)05-30 15:33:33.161: E/AndroidRuntime(916): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)05-30 15:33:33.161: E/AndroidRuntime(916): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)05-30 15:33:33.161: E/AndroidRuntime(916): at dalvik.system.NativeStart.main(Native Method)05-30 15:33:33.161: E/AndroidRuntime(916): Caused by: java.lang.NullPointerException05-30 15:33:33.161: E/AndroidRuntime(916): at com.google.android.maps.ItemizedOverlay.boundCenterBottom(ItemizedOverlay.java:158)05-30 15:33:33.161: E/AndroidRuntime(916): at android.Maps.MyPositionOverlay.(MyPositionOverlay.java:28)05-30 15:33:33.161: E/AndroidRuntime(916): at android.Maps.GeneticAlgorithm2.(GeneticAlgorithm2.java:51)05-30 15:33:33.161: E/AndroidRuntime(916): at android.Maps.HomeScreen.onCreate(HomeScreen.java:76)05-30 15:33:33.161: E/AndroidRuntime(916): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)05-30 15:33:33.161: E/AndroidRuntime(916): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)05-30 15:33:33.161: E/AndroidRuntime(916): ... 11 more

推荐答案

在我看来就像一个 NullPointerException异常在某些code的不是的一部分片段。

Looks to me like a NullPointerException in some of your code that isn't part of the snippet.

15 05-30:33:33.161:E / AndroidRuntime(916):产生的原因:显示java.lang.NullPointerException

15 05-30:33:33.161:E / AndroidRuntime(916):在com.google.android.maps.ItemizedOverlay.boundCenterBottom(ItemizedOverlay.java:158)

05-30 15:33:33.161: E/AndroidRuntime(916): at com.google.android.maps.ItemizedOverlay.boundCenterBottom(ItemizedOverlay.java:158)

这篇关于Android的无法调用另一个类时开始活动componentinfo错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 23:57