Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.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 试图拯救环境_Java_Android_Android Savedstate - Fatal编程技术网

Java 试图拯救环境

Java 试图拯救环境,java,android,android-savedstate,Java,Android,Android Savedstate,我有一个RemoteCar应用程序,可以调节空调、启动发动机等。在我的主要活动中有一个FuelBar和一个SeekBar(空调)。我想为下一次运行保存这些实例。例如,当我将空调设置为20°并关闭应用程序时,我希望空调按我离开时的方式设置为20°。但不知怎的,我把代码搞乱了,所以它甚至不能再启动了,你能解释一下我遗漏了什么吗 在C++中,我可以很容易地打开文件并关闭它,但是方法“CeleUE()”不太有效。我也很感激任何与这个话题相关的信息,我可以在这里阅读 保存方法“saveInfo”,在onS

我有一个RemoteCar应用程序,可以调节空调、启动发动机等。在我的主要活动中有一个FuelBar和一个SeekBar(空调)。我想为下一次运行保存这些实例。例如,当我将空调设置为20°并关闭应用程序时,我希望空调按我离开时的方式设置为20°。但不知怎的,我把代码搞乱了,所以它甚至不能再启动了,你能解释一下我遗漏了什么吗

在C++中,我可以很容易地打开文件并关闭它,但是方法“CeleUE()”不太有效。我也很感激任何与这个话题相关的信息,我可以在这里阅读

保存方法“saveInfo”,在onStop中,我希望它保存当前状态

package com.example.schwarzerritter.remotecv02;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import static com.example.schwarzerritter.remotecv02.R.id.engB;
import static com.example.schwarzerritter.remotecv02.R.id.fuelProgressBar;
import static com.example.schwarzerritter.remotecv02.R.id.refuelB;
import static com.example.schwarzerritter.remotecv02.R.id.seekBar;

public class MainActivity extends AppCompatActivity {
    public ProgressBar fuelBar;
    public Button lockButton;
    public Button engButton;
    public Button refuelButton;
    public Button locationButton;
    public SeekBar seekBarButton;
    public TextView seekText;
    int incFuel = 0;


    public void onClick(View v) {
        switch (v.getId()) {
            case engB:
                if (engButton.getText() == "ENGINE RUNNING") {
                    engButton.setText("START ENGINE");
                } else {
                    if (fuelBar.getProgress() > 0) {
                        Toast.makeText(MainActivity.this, "starting engine..", Toast.LENGTH_SHORT).show();
                        engButton.setText("ENGINE RUNNING");
                        if (fuelBar.getProgress() >= 10) {
                            incFuel = fuelBar.getProgress();
                            incFuel -= 10;
                            fuelBar.setProgress(incFuel);
                            if (fuelBar.getProgress() < 100)
                                refuelButton.setText("REFUEL");
                        }
                    } else if (fuelBar.getProgress() == 0) {
                        Toast.makeText(MainActivity.this, "no fuel", Toast.LENGTH_SHORT).show();
                        engButton.setText("EMPTY GASTANK");
                    } else
                        engButton.setText("START ENGINE");
                }
                break;
            case refuelB:
                if (fuelBar.getProgress() == 0) {
                    engButton.setText("START ENGINE");
                    incFuel = fuelBar.getProgress();
                    incFuel += 10;
                    fuelBar.setProgress(incFuel);
                } else if (fuelBar.getProgress() < 100) {
                    incFuel = fuelBar.getProgress();
                    incFuel += 10;
                    fuelBar.setProgress(incFuel);
                } else {
                    Toast.makeText(MainActivity.this, "tank is full", Toast.LENGTH_SHORT).show();
                    refuelButton.setText("FULL");
                }
                break;
        }
    }

    public void seek_bar() {
        seekBarButton = (SeekBar) findViewById(R.id.seekBar);
        seekText = (TextView) findViewById(R.id.seekText);
        seekText.setText("AC : " + (seekBarButton.getProgress() + 18) + "°");
        seekBarButton.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            int progressNum;

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                progressNum = progress;
                seekText.setText("AC : " + (seekBarButton.getProgress() + 18) + "°");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                seekText.setText("AC : " + (seekBarButton.getProgress() + 18) + "°");
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                seekText.setText("AC : " + (seekBarButton.getProgress() + 18) + "°");
            }
        });
    }

    public void saveInfo() {
        SharedPreferences sharedPref = getSharedPreferences("conditions", 0);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString("seekBar", seekText.getText().toString());
        editor.putInt("refuelBar", fuelBar.getProgress());
        editor.commit();
    }

    public void lockPage() {
        lockButton = (Button) findViewById(R.id.lockB);
        lockButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent lockPage = new Intent(MainActivity.this, lockDoor.class);
                startActivity(lockPage);
            }
        });
    }

    public void locationPage() {
        locationButton = (Button) findViewById(R.id.locationB);
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent locationPage = new Intent(MainActivity.this, location.class);
                startActivity(locationPage);
            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        saveInfo();//read files
        locationButton = (Button) findViewById(R.id.locationB);
        lockButton = (Button) findViewById(R.id.lockB);
        engButton = (Button) findViewById(R.id.engB);
        refuelButton = (Button) findViewById(R.id.refuelB);
        fuelBar = (ProgressBar) findViewById(R.id.fuelProgressBar);
        fuelBar.setMax(100);
        fuelBar.setProgress(30);
        refuelButton.setText(R.string.refuelB);
        lockButton.setText(R.string.lockB);
        locationButton.setText(R.string.locationB);
        engButton.setText(R.string.engB);
        seekBarButton = (SeekBar) findViewById(R.id.seekBar);
        seekText = (TextView) findViewById(R.id.seekText);
        seek_bar();
        lockPage();
        locationPage();


    }

    protected void onStop(){
        super.onStop();

        //Open SharedPref
        SharedPreferences sharedPref = getSharedPreferences("conditions", 0);
        //Edit
        SharedPreferences.Editor editor = sharedPref.edit();
        //Write file
        editor.putString("seekBar", seekText.getText().toString());
        editor.putInt("refuelBar", fuelBar.getProgress());
        //save
        editor.commit();
        //editor.close; Error: can't resolve method/symbol close
    }

}
    05-24 08:00:54.870 2026-2040/com.google.process.gapps W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gsf/databases/gservices.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:00:55.040 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/networkstatistics.sqlite' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:28:52.605 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:28:52.605 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/help_responses.db.18' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:28:52.606 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/metrics.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:29:04.497 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:29:04.499 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/help_responses.db.18' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:29:04.499 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/metrics.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:30:52.533 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/metrics.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:30:52.535 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/help_responses.db.18' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:30:52.541 2146-2157/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-24 08:31:07.294 1796-1796/com.google.android.googlequicksearchbox W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
05-24 08:31:51.101 3983-4041/com.google.android.gms I/FA-SVC: App measurement is starting up, version: 10298
05-24 08:31:51.190 3983-4199/com.google.android.gms I/FA-SVC: This instance being marked as an uploader