机器人工作室“运行程序”对话框中不出现另外一个项目,但会另外一个、对话框、中不、机器人

由网友(败类)分享简介:我玩弄Android的工作室制作了一个非常简单非常愚蠢的应用程序,以了解节能的关键preferences,我遇到了一个奇怪的障碍。我会尽力提供尽可能多的,因为我可以,因为它可能很难重现这个bug,但说实话,我同时运行应用程序是超级基本并有没有编译错误 规格:没有模拟器,我运行一个的三星Galaxy平板电脑的。 Win...

我玩弄Android的工作室制作了一个非常简单非常愚蠢的应用程序,以了解节能的关键preferences,我遇到了一个奇怪的障碍。我会尽力提供尽可能多的,因为我可以,因为它可能很难重现这个bug,但说实话,我同时运行应用程序是超级基本并有没有编译错误

规格: 没有模拟器,我运行一个的三星Galaxy平板电脑的。 Windows 7中,机器人工作室1.2,摇篮2.2.1。

在这个问题标题,我的意思是我有一个项目名为小鹰的(pretty的多的Hello World和一个按钮)。我点击运行 - >运行应用程序 - >(对话框打开) - >确定 - >在时刻在我的平板电脑上的应用程序启动

^^^这是唯美的画面我想看到的共享preferences 的,但它只是在的小猫的。

现在,我开始叫的共享preferences 的(GIST另一个项目:两个复选框问你你喜欢巧克力和你喜欢路易吉,​​你选中一个没有或双方和preSS保存。两个textviews下将更新说,如果你喜欢这些事情,甚至以后如果重新打开该应用程序的textviews会记得巧克力路易吉preferences)。这仅仅是一个main_activity。

我不认为我改变了两者之间的任何设置或项目preferences并没有给我一个错误。 MainActivity.java的过时ORIGINAL请参阅编辑的:

 包gaga.shared preferences;

进口android.content.Shared preferences;
进口android.support.v7.app.ActionBarActivity;
进口android.os.Bundle;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.widget.CheckBox;
进口android.widget.CheckedTextView;
进口android.widget.TextView;

公共类MainActivity扩展ActionBarActivity {

    公共final类设置扩展MainActivity {
        公共无效设置(){
            //没什么可看这里!
        }

        //定义了preFS文件;如果不存在创建
        公共静态最后弦乐preFS_NAME =我的prefsFile;

        // 启动
        @覆盖
        公共无效的onCreate(包状态){
            super.onCreate(州);

            //恢复启动时preferences
            共享preferences设置= getShared preferences(preFS_NAME,0);
            布尔巧克力= settings.getBoolean(checkChocolate,假);
            布尔路易吉= settings.getBoolean(checkLuigi,假);
            //功能设置为任何
            // setSilent(沉默);
            /* 注意:
            * CheckedTextView和CheckBox ::器isChecked()
            *复选框:: setChecked()
            * * /
            复选框checkHandleChocolate =(复选框)findViewById(R.id.checkChocolate);
            复选框checkHandleLuigi =(复选框)findViewById(R.id.checkLuigi);

            //什么是preference?在开始将其设置为它离开的布尔
            checkHandleChocolate.setChecked(巧克力);
            checkHandleLuigi.setChecked(路易);

            在开始//更改报告正文
            TextView的buttonHandleChocolate =(TextView中)findViewById(R.id.chocolate);
            TextView的buttonHandleLuigi =(TextView中)findViewById(R.id.luigi);

            如果(巧克力)
                buttonHandleChocolate.setText(我做preFER巧克力);
            其他
                buttonHandleChocolate.setText(我不preFER巧克力);
            如果(路易)
                buttonHandleLuigi.setText(我做preFER路易吉);
            其他
                buttonHandleLuigi.setText(我不preFER路易吉);

        }

        公共无效saveChocolate(布尔C){
            //从android.context.Context所有对象
            共享preferences设置= getShared preferences(preFS_NAME,0);
            共享preferences.Editor编辑器= settings.edit();
            editor.putBoolean(巧克力,C);
            //提交修改
            editor.commit();
        }
        公共无效saveLuigi(布尔L){
            //从android.context.Context所有对象
            共享preferences设置= getShared preferences(preFS_NAME,0);
            共享preferences.Editor编辑器= settings.edit();
            editor.putBoolean(巧克力,升);
            //提交修改
            editor.commit();
        }
    }


    @覆盖
    保护无效的onStop(){
        super.onStop();
        //对象是来自android.context.Context
        //通常我会把编辑提交这里,但事实并非如此
    }

    //点​​击上完成
    公共无效userDone(查看视图){
        //查看是小部件
        布尔查=((复选框)查看).isChecked();

        //其中的复选框被点击
        开关(view.getId()){
            案例R.id.checkChocolate:
                设置实例1 =新的设置();
                instance1.saveChocolate(选中);
                // 没有休息;继续沿着
            案例R.id.checkLuigi:
                设置INSTANCE2 =新设置();
                instance2.saveLuigi(选中);
                打破;
        }
    }


    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
    }

    @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气菜单;这增加了项目操作栏,如果它是present。
        。getMenuInflater()膨胀(R.menu.menu_main,菜单);
        返回true;
    }

    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。将操作栏
        //自动在主/向上按钮操作的点击,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT的id = item.getItemId();

        // noinspection SimplifiableIfStatement
        如果(ID == R.id.action_settings){
            返回true;
        }

        返回super.onOptionsItemSelected(项目);
    }
}
 
为什么电脑启动不了任务管理器

logcat中的红色部分:

  06-02 20:49:57.245 25557-25557 /? I / SDP.PUB_CRYPTOD:启动
06-02 20:49:57.245 25557-25557 /? I / SDP.PUB_CRYPTOD:插座,FD创建:-1
06-02 20:49:57.245 25557-25557 /? E / SDP.PUB_CRYPTOD:无法打开网络连接套接字错误:不支持协议
06-02 20:49:57.245 25557-25557 /? E / SDP.PUB_CRYPTOD:退出
06-02 20:49:59.995 2866-3012 /? V / AlarmManager:waitForAlarm结果:8
06-02 20:50:02.280 25633-25633 /? I / SDP.PUB_CRYPTOD:启动
06-02 20:50:02.280 25633-25633 /? I / SDP.PUB_CRYPTOD:插座,FD创建:-1
06-02 20:50:02.280 25633-25633 /? E / SDP.PUB_CRYPTOD:无法打开网络连接套接字错误:不支持协议
06-02 20:50:02.280 25633-25633 /? E / SDP.PUB_CRYPTOD:退出
 

感谢您的帮助。我没有看到这个问题,而窜来窜去网上所以它可能是过于小白。

编辑:在较大MainActivity类改写,唯一的onCreate

 包gaga.shared preferences;

进口android.content.Shared preferences;
进口android.support.v7.app.ActionBarActivity;
进口android.os.Bundle;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.widget.CheckBox;
进口android.widget.CheckedTextView;
进口android.widget.TextView;

公共类MainActivity扩展ActionBarActivity {

    公共final类设置扩展MainActivity {
        公共无效设置(){
            //没什么可看这里!
        }

        //定义了preFS文件;如果不存在创建
        公共静态最后弦乐preFS_NAME =我的prefsFile;

        // 启动
        公共无效onCreateSubclass(){
            // super.onCreate(州);

            //恢复启动时preferences
            共享preferences设置= getShared preferences(preFS_NAME,0);
            布尔巧克力= settings.getBoolean(checkChocolate,假);
            布尔路易吉= settings.getBoolean(checkLuigi,假);
            //功能设置为任何
            // setSilent(沉默);
            /* 注意:
            * CheckedTextView和CheckBox ::器isChecked()
            *复选框:: setChecked()
            * * /
            复选框checkHandleChocolate =(复选框)findViewById(R.id.checkChocolate);
            复选框checkHandleLuigi =(复选框)findViewById(R.id.checkLuigi);

            //什么是preference?在开始将其设置为它离开的布尔
            checkHandleChocolate.setChecked(巧克力);
            checkHandleLuigi.setChecked(路易);

            在开始//更改报告正文
            TextView的buttonHandleChocolate =(TextView中)findViewById(R.id.chocolate);
            TextView的buttonHandleLuigi =(TextView中)findViewById(R.id.luigi);

            如果(巧克力)
                buttonHandleChocolate.setText(我做preFER巧克力);
            其他
                buttonHandleChocolate.setText(我不preFER巧克力);
            如果(路易)
                buttonHandleLuigi.setText(我做preFER路易吉);
            其他
                buttonHandleLuigi.setText(我不preFER路易吉);

        }

        公共无效saveChocolate(布尔C){
            //从android.context.Context所有对象
            共享preferences设置= getShared preferences(preFS_NAME,0);
            共享preferences.Editor编辑器= settings.edit();
            editor.putBoolean(巧克力,C);
            //提交修改
            editor.commit();
        }
        公共无效saveLuigi(布尔L){
            //从android.context.Context所有对象
            共享preferences设置= getShared preferences(preFS_NAME,0);
            共享preferences.Editor编辑器= settings.edit();
            editor.putBoolean(巧克力,升);
            //提交修改
            editor.commit();
        }
    }


    @覆盖
    保护无效的onStop(){
        super.onStop();
        //对象是来自android.context.Context
        //通常我会把编辑提交这里,但事实并非如此
    }

    //点​​击上完成
    公共无效userDone(查看视图){
        //查看是小部件
        布尔查=((复选框)查看).isChecked();

        //其中的复选框被点击
        开关(view.getId()){
            案例R.id.checkChocolate:
                设置实例1 =新的设置();
                instance1.saveChocolate(选中);
                // 没有休息;继续沿着
            案例R.id.checkLuigi:
                设置INSTANCE2 =新设置();
                instance2.saveLuigi(选中);
                打破;
        }
    }


    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        设置startInstance =新设置();
        startInstance.onCreateSubclass();
    }

    @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气菜单;这增加了项目操作栏,如果它是present。
        。getMenuInflater()膨胀(R.menu.menu_main,菜单);
        返回true;
    }

    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。将操作栏
        //自动在主/向上按钮操作的点击,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT的id = item.getItemId();

        // noinspection SimplifiableIfStatement
        如果(ID == R.id.action_settings){
            返回true;
        }

        返回super.onOptionsItemSelected(项目);
    }
}
 

解决方案

在Android的工作室,你需要在你的项目中创建一个运行配置。

转到此链接到左运行图标

和点击编辑配置,在windows后配置是这样的:

和保存,测试点击运行图标。

I'm toying with Android Studio making a very simple very stupid app to learn about saving key preferences and I ran into a weird obstacle. I'll try to provide as much as I can since it may be hard to reproduce this bug but honestly both apps I'm running are super basic and there no compile errors.

Specs: No emulator, I'm running a Samsung Galaxy Tablet. Windows 7, Android Studio 1.2, Gradle 2.2.1.

In the question title, I mean that I have a project named Kitty (pretty much hello world and a button). I click Run->'Run app'->(Dialogue box opens)->OK->Within moments the app launches on my tablet.

^^^THIS IS THE BEAUTIFUL SCREEN I WANT TO SEE ON Sharedpreferences, but it's only on kitty.

Now I started another project called SharedPreferences (gist: two checkboxes ask you "do you like chocolate" and "do you like luigi" and you check one none or both and press save. Two textviews underneath will update to say if you like those things and even later if you reopen the app the textviews will remember Chocolate Luigi preferences). It is just a main_activity.

I don't think I changed any settings or project preferences between the two and neither give me an error. MainActivity.java OUTDATED ORIGINAL SEE EDIT:

package gaga.sharedpreferences;

import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    public final class setup extends MainActivity {
        public void setup () {
            //Nothing to see here!
        }

        // Define the File of Prefs; created if nonexistent
        public static final String PREFS_NAME = "MyPrefsFile";

        // Start up
        @Override
        public void onCreate(Bundle state) {
            super.onCreate(state);

            // Restore preferences on Startup
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            boolean Chocolate = settings.getBoolean("checkChocolate", false);
            boolean Luigi = settings.getBoolean("checkLuigi", false);
            // Function set to Whatever
            // setSilent(silent);
            /* Note:
            * CheckedTextView and CheckBox::isChecked()
            * CheckBox::setChecked()
            * */
            CheckBox checkHandleChocolate = (CheckBox) findViewById(R.id.checkChocolate);
            CheckBox checkHandleLuigi = (CheckBox) findViewById(R.id.checkLuigi);

            // What was the preference? On Start set it to the bool it left off in
            checkHandleChocolate.setChecked(Chocolate);
            checkHandleLuigi.setChecked(Luigi);

            // Change report text on Start
            TextView buttonHandleChocolate = (TextView) findViewById(R.id.chocolate);
            TextView buttonHandleLuigi = (TextView) findViewById(R.id.luigi);

            if(Chocolate)
                buttonHandleChocolate.setText("I do prefer Chocolate");
            else
                buttonHandleChocolate.setText("I do not prefer Chocolate");
            if(Luigi)
                buttonHandleLuigi.setText("I do prefer Luigi");
            else
                buttonHandleLuigi.setText("I do not prefer Luigi");

        }

        public void saveChocolate(Boolean c) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", c);
            // Commit the edits
            editor.commit();
        }
        public void saveLuigi(Boolean l) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", l);
            // Commit the edits
            editor.commit();
        }
    }


    @Override
    protected void onStop(){
        super.onStop();
        // Objects are from android.context.Context
        //Normally I'd put the edit commits here, but that's not true
    }

    // Clicks on Done
    public void userDone (View view) {
        // View is which widget
        boolean checked = ((CheckBox) view).isChecked();

        // Which checkbox was clicked
        switch(view.getId()) {
            case R.id.checkChocolate:
                setup instance1 = new setup();
                instance1.saveChocolate(checked);
                // No break; continue along
            case R.id.checkLuigi:
                setup instance2 = new setup();
                instance2.saveLuigi(checked);
                break;
        }
    }


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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Red parts of logcat:

06-02 20:49:57.245  25557-25557/? I/SDP.PUB_CRYPTOD﹕ Starting
06-02 20:49:57.245  25557-25557/? I/SDP.PUB_CRYPTOD﹕ Socket created with fd:-1
06-02 20:49:57.245  25557-25557/? E/SDP.PUB_CRYPTOD﹕ Failed to open the netlink socket with error: Protocol not supported
06-02 20:49:57.245  25557-25557/? E/SDP.PUB_CRYPTOD﹕ Exiting
06-02 20:49:59.995    2866-3012/? V/AlarmManager﹕ waitForAlarm result :8
06-02 20:50:02.280  25633-25633/? I/SDP.PUB_CRYPTOD﹕ Starting
06-02 20:50:02.280  25633-25633/? I/SDP.PUB_CRYPTOD﹕ Socket created with fd:-1
06-02 20:50:02.280  25633-25633/? E/SDP.PUB_CRYPTOD﹕ Failed to open the netlink socket with error: Protocol not supported
06-02 20:50:02.280  25633-25633/? E/SDP.PUB_CRYPTOD﹕ Exiting

Thanks for any help. I haven't seen this issue while prowling the internet so it might be excessively noob.

EDIT: Rewritten with the only onCreate in the larger MainActivity class

package gaga.sharedpreferences;

import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    public final class setup extends MainActivity {
        public void setup () {
            //Nothing to see here!
        }

        // Define the File of Prefs; created if nonexistent
        public static final String PREFS_NAME = "MyPrefsFile";

        // Start up
        public void onCreateSubclass() {
            // super.onCreate(state);

            // Restore preferences on Startup
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            boolean Chocolate = settings.getBoolean("checkChocolate", false);
            boolean Luigi = settings.getBoolean("checkLuigi", false);
            // Function set to Whatever
            // setSilent(silent);
            /* Note:
            * CheckedTextView and CheckBox::isChecked()
            * CheckBox::setChecked()
            * */
            CheckBox checkHandleChocolate = (CheckBox) findViewById(R.id.checkChocolate);
            CheckBox checkHandleLuigi = (CheckBox) findViewById(R.id.checkLuigi);

            // What was the preference? On Start set it to the bool it left off in
            checkHandleChocolate.setChecked(Chocolate);
            checkHandleLuigi.setChecked(Luigi);

            // Change report text on Start
            TextView buttonHandleChocolate = (TextView) findViewById(R.id.chocolate);
            TextView buttonHandleLuigi = (TextView) findViewById(R.id.luigi);

            if(Chocolate)
                buttonHandleChocolate.setText("I do prefer Chocolate");
            else
                buttonHandleChocolate.setText("I do not prefer Chocolate");
            if(Luigi)
                buttonHandleLuigi.setText("I do prefer Luigi");
            else
                buttonHandleLuigi.setText("I do not prefer Luigi");

        }

        public void saveChocolate(Boolean c) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", c);
            // Commit the edits
            editor.commit();
        }
        public void saveLuigi(Boolean l) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", l);
            // Commit the edits
            editor.commit();
        }
    }


    @Override
    protected void onStop(){
        super.onStop();
        // Objects are from android.context.Context
        //Normally I'd put the edit commits here, but that's not true
    }

    // Clicks on Done
    public void userDone (View view) {
        // View is which widget
        boolean checked = ((CheckBox) view).isChecked();

        // Which checkbox was clicked
        switch(view.getId()) {
            case R.id.checkChocolate:
                setup instance1 = new setup();
                instance1.saveChocolate(checked);
                // No break; continue along
            case R.id.checkLuigi:
                setup instance2 = new setup();
                instance2.saveLuigi(checked);
                break;
        }
    }


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

        setup startInstance = new setup();
        startInstance.onCreateSubclass();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

解决方案

In Android Studio you need create a Run Configuration in your project.

Go to this link to left run icon

And click on Edit Configuration, after in the windows configure like this:

And save it, for test click run icon.

阅读全文

相关推荐

最新文章