Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can´;不要使用意图将数据移动到其他活动_Java_Android_Android Studio_Methods_Crash - Fatal编程技术网

Java Can´;不要使用意图将数据移动到其他活动

Java Can´;不要使用意图将数据移动到其他活动,java,android,android-studio,methods,crash,Java,Android,Android Studio,Methods,Crash,这是我的第一个活动,每当我试图使用Intent通过双精度“纬度和经度”时,我的应用程序就会崩溃,我不知道还能做什么 我看到,如果我不把星触觉(意图)我不会崩溃 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // requestP

这是我的第一个活动,每当我试图使用Intent通过双精度“纬度和经度”时,我的应用程序就会崩溃,我不知道还能做什么

我看到,如果我不把星触觉(意图)我不会崩溃

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    //
    requestPermission();
    //
    client = LocationServices.getFusedLocationProviderClient(this);
    Button button = findViewById(R.id.getLocation);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

                    if(ActivityCompat.checkSelfPermission(MainActivity.this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
                        return;
                    }

                client.getLastLocation().addOnSuccessListener(MainActivity.this, new OnSuccessListener<Location>() {
                    @Override
                    public void onSuccess(Location location) {
                        if (location != null) {
                            TextView textView = findViewById(R.id.location);
                            textView.setText(location.toString());


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


                    Intent intent = new Intent(getApplicationContext(), MapsActivity.class);
                    intent.putExtra("Lat",latitude);
                    intent.putExtra("Lon",longitude);
                    startActivity(intent);

                     }


                });
        }
    });
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//
requestPermission();
//
client=LocationServices.getFusedLocationProviderClient(此);
按钮按钮=findViewById(R.id.getLocation);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
if(ActivityCompat.checkSelfPermission(MainActivity.this,访问\u FINE\u位置)!=PackageManager.PERMISSION\u已授予){
回来
}
client.getLastLocation().addOnSuccessListener(MainActivity.this,新的OnSuccessListener()){
@凌驾
成功时的公共无效(位置){
如果(位置!=null){
TextView TextView=findViewById(R.id.location);
textView.setText(location.toString());
}
双纬度=location.getLatitude();
double longitude=location.getLongitude();
Intent Intent=新的Intent(getApplicationContext(),MapsActivity.class);
意向。额外(“纬度”,纬度);
意图。putExtra(“Lon”,经度);
星触觉(意向);
}
});
}
});
这是另一项活动

希望有助于找到错误,我不知道为什么那条线会引起如此多的翻滚

谢谢你的建议

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {

private GoogleMap mMap;

public static final String FILENAME = "filename";

private ArrayList<Entity> selectedSat;

String fileName;
MenuItem favItem;




private DecimalFormat df = new DecimalFormat("#.00");

private Frame earthFixedFrame;
private OneAxisEllipsoid earth;
protected GeodeticPoint pointPlot = null;
protected Marker currentMarker = null;
protected Polyline line = null;
protected Polyline pastLine = null;
public static final int PATTERN_DASH_LENGTH_PX = 20;
public static final int PATTERN_GAP_LENGTH_PX = 20;
public static final PatternItem DOT = new Dot();
public static final PatternItem DASH = new Dash(PATTERN_DASH_LENGTH_PX);
public static final PatternItem GAP = new Gap(PATTERN_GAP_LENGTH_PX);
public static final List<PatternItem> PATTERN_POLYGON_ALPHA = Arrays.asList(GAP, DASH);
protected ArrayList<Marker> markers = new ArrayList<>();

boolean initial = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_ACTION_BAR);

    Drawable fav = getDrawable(R.drawable.favoritesicon);
    fav.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.MULTIPLY);

    selectedSat = SatelliteSelectActivity.getSelectedSat(); //Pulls a list of selected satellites from the previous activity
    System.out.println(selectedSat.get(0).getName());

    setContentView(R.layout.activity_maps);


    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setTitle(selectedSat.get(0).getName().trim());
    }

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    fileName = getIntent().getStringExtra(FILENAME);

    int i = 0;

    System.out.println(selectedSat.get(i).getName());   //Prints Entity Name to the Console

    try {
        System.out.println("Velocidad:");
        System.out.println(selectedSat.get(i).getVelocity());       //Prints the velocity of the entity
    } catch (OrekitException e) {
        e.printStackTrace();
    }
}

public void onBackPressed() {       //Runs when you exit the activity
    selectedSat.clear();            //Clears the satellite list
    System.out.println("Terminar con el mapa");        //Prints to the console that we are done with the Maps activity
    initial = false;                //Boolean variable specifying we are dealing with the first satellite
    Intent intent = new Intent(getApplicationContext(), SatelliteSelectActivity.class);
    startActivity(intent);
    this.finish();                  //Closes the activity
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {     //Creates action bar in the MapsActivity UI

    MenuInflater item = getMenuInflater();     //Specifies the item fit
    item.inflate(R.menu.actionbar, menu);   //Fits the menu to the item fit
    setTitle("SatFun");                  //Sets the action bar title
    favItem = menu.findItem(R.id.actionbar_fav);
    checkifFavorite(); // see if sat is favorite
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {       //Called when icon in the action bar is selected

    switch (item.getItemId()) {


        case R.id.actionbar_fav:
            selectedSat = SatelliteSelectActivity.getSelectedSat();
            String fileName = getIntent().getStringExtra(FILENAME);

            if (!Favorites.contains(selectedSat.get(0).getName(), fileName, getApplicationContext())) {
                item.setIcon(R.drawable.favoritesicon_filled);
                for (int i = 0; i < selectedSat.size(); i++)
                    try {
                        Favorites.addFavorite(selectedSat.get(i).getName(), selectedSat.get(i).getLine1(), selectedSat.get(i).getLine2(), fileName, getApplicationContext());
                        return true;
                    } catch (OrekitException e) {
                        e.printStackTrace();
                    }
            } else {
                item.setIcon(R.drawable.favoritesicon);
                for (int i = 0; i < selectedSat.size(); i++) {
                    try {
                        boolean removed = Favorites.removeFavorite(selectedSat.get(i).getName(), selectedSat.get(i).getLine1(), selectedSat.get(i).getLine2(), fileName, getApplicationContext());
                        System.out.print(removed);
                    } catch (OrekitException e) {
                        e.printStackTrace();
                    }
                }
                return true;
            }

        case R.id.actionbar_info:
            ConstraintLayout satInfo = findViewById(R.id.satelliteInfo);
            if (satInfo.getVisibility() == View.INVISIBLE) {
                satInfo.setVisibility(View.VISIBLE);
            } else {
                satInfo.setVisibility(View.INVISIBLE);
            }
    }
    return super.onOptionsItemSelected(item);
}




@Override
public void onMapReady(final GoogleMap googleMap) {
    mMap = googleMap;


    mapUpdater(getCreatedTime());

}

private int incr = 0;


public void mapUpdater(Date date) {

    if (date == null) {
        dateTime = getCreatedTime();
    } else {
        dateTime = date;
    }

    new Thread() {
        public void run() {
            System.out.println("Nueva");
            while (incr++ < 1000) {
                try {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                updateMap();
                            } catch (OrekitException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();

}

private void setPastLine(AbsoluteDate date, double satPeriod) {
    ArrayList<LatLng> plotPoints = new ArrayList<>();
    for (int k = 0; k < 50; k++) {
        int period = (int) Math.round(satPeriod);
        int periodMin = (period / 100);
        System.out.println("DATE: " + date);
        pointPlot = updatePosition(date, 0);
        System.out.println("FRAGMENT (width, height): " + findViewById(R.id.map).getWidth() + "   " + findViewById(R.id.map).getHeight());
        double longitude = pointPlot.getLongitude() * 180 / Math.PI;
        double latitude = pointPlot.getLatitude() * 180 / Math.PI;

        //Creates map objects
        LatLng point_a = new LatLng(latitude, longitude);
        MarkerOptions point = new MarkerOptions().position(point_a);

        plotPoints.add(point_a);
        date = new AbsoluteDate(date, -periodMin);
    }

    pastLine = mMap.addPolyline(new PolylineOptions().addAll(plotPoints));
    pastLine.setWidth(5);//Sets width of polyline
    pastLine.setPattern(PATTERN_POLYGON_ALPHA);
    pastLine.setColor(Color.RED);
}

private Date getCreatedTime() {  //Creates a new date with the current time and returns it
    return new Date();
}

private Date dateTime = null;



private void updateMap() throws OrekitException {

    System.out.println("Entering update map");
    if (dateTime == null) {
        dateTime = getCreatedTime();
    }
    AbsoluteDate date;

    for (int i = 0; i < selectedSat.size(); i++) {

        double satNum = selectedSat.get(i).getSatNum();
        TextView satNumberText = findViewById(R.id.satelliteNumber);







        String satelliteNumberString = "Número De Satelite: " + Math.round(satNum);
        satNumberText.setText(satelliteNumberString);


        TimeScale utc = TimeScalesFactory.getUTC();




        ArrayList<LatLng> plotPoints = new ArrayList<>();
        Calendar calendar = GregorianCalendar.getInstance();

        double satPeriod = selectedSat.get(i).getPeriod();
        int period = (int) Math.round(satPeriod);
        int periodMin = (period / 100);
        System.out.println("Interval: " + periodMin);
        calendar.setTime(dateTime);

        System.out.println(calendar.get(Calendar.YEAR));
        calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        date = new AbsoluteDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), utc); //creates orekit absolute date from calender

        this.initializeFrames();

        pointPlot = updatePosition(date, 0);

        String velocityString = df.format(selectedSat.get(i).getVelocity() * 3.6);

        velocityString = "Velocidad: " + velocityString + "km/h";

        TextView satVelocity = findViewById(R.id.velocity);
        satVelocity.setText(velocityString);


        //Finds longitude
        double longitude = pointPlot.getLongitude() * 180 / Math.PI;
        String longitudeString = "Longitud: " + df.format(longitude);
        TextView satLongitude = findViewById(R.id.satLongitude);
        satLongitude.setText(longitudeString);


        //Finds latitude
        double latitude = pointPlot.getLatitude() * 180 / Math.PI;
        String latitudeString = "Latitud: " + df.format(latitude);
        TextView satLatitude = findViewById(R.id.satLatitude);
        satLatitude.setText(latitudeString);


        double altitude = pointPlot.getAltitude() / 1000;
        TextView satAltitude = findViewById(R.id.satAltitude);
        String altitudeString = "Altitud: " + df.format(altitude) + "km";
        satAltitude.setText(altitudeString);



        //CALCULOS
        double longi= 78.5082717;
        double lati=0.245496;
        double delta1 = Math.abs(longitude);
        double delta = Math.abs(delta1-longi);

        double elev=Math.atan(((Math.cos(lati)*Math.cos(delta))-(6378/42164))/Math.sin(Math.acos(Math.cos(lati)*Math.cos(delta))));
        double az1 = Math.tan(Math.toDegrees(delta));
        double az2 = Math.sin(Math.toDegrees(lati));
        double az3 = Math.toDegrees(az1/az2);
        double az = Math.abs(Math.toDegrees(Math.atan(az3)));

        double dis1 = (Math.cos(Math.toRadians(lati)));
        double dis2 = (Math.cos(Math.toRadians(delta)));
        double dis3 = (dis1*dis2);
        double dis4 = (1-dis3);
        double dis5 = (0.41999*dis4);
        double dis6 = (1+dis5);
        double dis = (35786.04*(Math.sqrt(dis6)));




        TextView satdelta = findViewById(R.id.satdelta);
        String deltaString = "Delta: " + df.format(delta);
        satdelta.setText(deltaString);

        TextView azimuts = findViewById(R.id.azimut);
        String AzimutString = "Azimut: " + df.format(az);
        azimuts.setText(AzimutString);

        TextView disf = findViewById(R.id.distancia);
        String disString = "Distancia: " + df.format(dis) + "Km";
        disf.setText(disString);




        //////////////////////////////////////////////////////////



        System.out.println("Latitud: " + latitude);
        System.out.println("Longitud: " + longitude);
        System.out.println("PERIODO: " + periodMin);




        for (int k = 0; k < 300; k++) {

            System.out.println("DATE: " + date);
            pointPlot = updatePosition(date, i);
            System.out.println("FRAGMENT (width, height): " + findViewById(R.id.map).getWidth() + "   " + findViewById(R.id.map).getHeight());
            longitude = pointPlot.getLongitude() * 180 / Math.PI;
            latitude = pointPlot.getLatitude() * 180 / Math.PI;

            //Creates map objects
            LatLng point_a = new LatLng(latitude, longitude);
            MarkerOptions pointA = new MarkerOptions().position(point_a);

            if (k == 0) {
                if(currentMarker != null) {
                    currentMarker.remove();
                }
                if(line != null) {
                    line.remove();
                }
                if(pastLine != null) {
                    pastLine.remove();
                }
             }
                pointA.title(selectedSat.get(i).getName().trim() + "Poscicion Actual");
                if (initial) {
                    initial = false;
                    mMap.moveCamera(CameraUpdateFactory.newLatLng(point_a));
                }
            }
            plotPoints.add(point_a);
            date = new AbsoluteDate(date, periodMin);
        }
        date = new AbsoluteDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), utc); //creates orekit absolute date from calender
        setPastLine(date, satPeriod);

        line = mMap.addPolyline(new PolylineOptions().addAll(plotPoints));
        line.setWidth(5);
        line.setColor(Color.RED);
    }
}

    private void initializeFrames() {

    try {
        Frame f;
        f = CelestialBodyFactory.getEarth().getBodyOrientedFrame();

        earthFixedFrame = FramesFactory.getTEME();

        earth = new OneAxisEllipsoid(
                Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                Constants.WGS84_EARTH_FLATTENING,
                f);
    } catch (OrekitException e) {
        System.out.println("ERROR");
        e.printStackTrace();
    }
}


private GeodeticPoint updatePosition(AbsoluteDate date, int i) {
    GeodeticPoint point = null;

    SpacecraftState scs = selectedSat.get(i).updateState(date);
    System.out.println(scs);
    System.out.println(scs.getPVCoordinates().getPosition());
    System.out.println(scs.getDate());
    System.out.println(earthFixedFrame);

    try {
        point = earth.transform(selectedSat.get(i).getVector(date), earthFixedFrame, date);
    } catch (OrekitException e) {
        System.out.println("Fallo al realizar la conversion cartesiana");
        e.printStackTrace();
    }
    return point;
}


private void checkifFavorite() {

    if (fileName.contains("favorites_")) {
        fileName = fileName.replace("favorites_", "");
    }


    File test1 = new File(this.getFilesDir(), "favorites_" + fileName);


    if (test1.exists()) {
        System.out.println("file exists");
        try {
            ArrayList<String> favs = celestrakData.getNames("favorites_" + fileName, this);


            if (favs.contains(selectedSat.get(0).getName())) {
                System.out.println("already is a favorite");
                favItem.setIcon(R.drawable.favoritesicon_filled);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("file doesnt exist");
    }


}
公共类MapsActivity扩展了AppCompatActivity在MapReadyCallback上的实现{
私有谷歌地图;
公共静态最终字符串FILENAME=“FILENAME”;
专用阵列列表selectedSat;
字符串文件名;
梅努特姆·法维滕;
私有DecimalFormat df=新的DecimalFormat(#.00”);
专用框架接地固定框架;
椭圆地球;
受保护的大地测量点点图=空;
受保护的标记currentMarker=null;
受保护的多段线=空;
受保护的多段线pastLine=null;
公共静态最终整数模式_破折号_长度_PX=20;
公共静态最终整数模式\u间距\u长度\u PX=20;
公共静态最终模式项目点=新点();
公共静态最终模式项目破折号=新破折号(模式破折号长度PX);
公共静态最终图案项目间隙=新间隙(图案间隙长度x);
公共静态最终列表模式\多边形\α=数组.asList(间隙,破折号);
受保护的ArrayList标记=新建ArrayList();
布尔初始值=真;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口.功能\u操作\u栏);
可拉伸fav=可拉伸(R.Drawable.favoritesicon);
fav.setColorFilter(Color.parseColor(#FFFFFF)),PorterDuff.Mode.MULTIPLY;
selectedSat=SatelliteSelectActivity.getSelectedSat();//从上一个活动中提取选定卫星的列表
System.out.println(selectedSat.get(0.getName());
setContentView(R.layout.activity_映射);
ActionBar ab=getSupportActionBar();
如果(ab!=null){
ab.setTitle(selectedSat.get(0.getName().trim());
}
//获取SupportMapFragment,并在地图准备好使用时收到通知。
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
fileName=getIntent().getStringExtra(文件名);
int i=0;
System.out.println(selectedSat.get(i).getName());//将实体名称打印到控制台
试一试{
System.out.println(“Velocidad:”);
System.out.println(selectedSat.get(i.getVelocity());//打印实体的速度
}渔获物(Orekite){
e、 printStackTrace();
}
}
public void onBackPressed(){//在退出活动时运行
selectedSat.clear();//清除卫星列表
System.out.println(“Terminar con el mapa”);//打印到控制台,表明我们已经完成了映射活动
initial=false;//指定我们正在处理第一个卫星的布尔变量
Intent Intent=新的Intent(getApplicationContext(),SatelliteSelectActivity.class);
星触觉(意向);
this.finish();//关闭活动
}
@凌驾
公共布尔onCreateOptions菜单(菜单菜单){//在MapsActivity UI中创建操作栏
MenuInflater item=getMenuInflater();//指定项目的匹配
item.inflate(R.menu.actionbar,menu);//使菜单与项目匹配
setTitle(“SatFun”);//设置操作栏标题
favItem=menu.findItem(R.id.actionbar\u fav);
checkifFavorite();//查看sat是否最受欢迎
返回super.onCreateOptions菜单(菜单);
}
@凌驾
公共布尔值OnOptions ItemSelected(MenuItem项){//在选择操作栏中的图标时调用
开关(item.getItemId()){
案例R.id.actionbar\u fav:
selectedSat=SatelliteSelectActivity.getSelectedSat();
字符串文件名=getIntent().getStringExtra(文件名);
如果(!Favorites.contains(selectedSat.get(0).getName(),fileName,getApplicationContext())){
项目设置图标(右侧可绘制、收藏夹图标填充);
对于(int i=0;i Intent intent = new Intent(yourActivityName.this, MapsActivity.class);