Android studio SpellCheckerSession在实际设备中运行时出现nullpointerexception错误

Android studio SpellCheckerSession在实际设备中运行时出现nullpointerexception错误,android-studio,nullpointerexception,spell-checking,Android Studio,Nullpointerexception,Spell Checking,语句“mScs.getSuggestions(newtextinfo(without 2),1);”不断获取 在实际设备中运行时出现java.lang.NullPointerException,但它可以工作 在模拟器中运行良好 我能知道怎么修吗 MainActivity.java: public class MainActivity extends Activity implements SpellCheckerSession.SpellCheckerSessionListener {

语句
“mScs.getSuggestions(newtextinfo(without 2),1);”
不断获取

在实际设备中运行时出现java.lang.NullPointerException,但它可以工作 在模拟器中运行良好

我能知道怎么修吗

MainActivity.java:

public class MainActivity extends Activity implements SpellCheckerSession.SpellCheckerSessionListener {
            TextView tv1, tv2, tv3;
            Button b1;
            EditText et1;

            private SpellCheckerSession mScs;

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

                b1 = (Button) findViewById(R.id.btn1);
                tv1 = (TextView) findViewById(R.id.tv1);
                tv2 = (TextView) findViewById(R.id.tv2);
                tv3 = (TextView) findViewById(R.id.tv3);
                et1 = (EditText) findViewById(R.id.et1);

                final  String[][] T9 = {
                        /* 0 */ {"a", "b", "c"},
                        /* 1 */ {"d", "e", "f"},
                        /* 2 */ {"g", "h", "i"},
                        /* 3 */ {"j", "k", "l"},
                        /* 4 */ {"m", "n", "o"},
                        /* 5 */ {"p", "q", "r", "s"},
                        /* 6 */ {"t", "u", "v"},
                        /* 7 */ {"w", "x", "y", "z"}
                };
                final ArrayList<String> prevalue = new ArrayList<String>();
                final ArrayList<String> buff = new ArrayList<String>();
                b1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {


                            prevalue.clear();
                            buff.clear();
                            tv1.setText("");
                            tv2.setText("");
                            tv3.setText("");

                            for(int et = 0; et< et1.length(); et++) {
                                String subvalue = et1.getText().toString().substring(et, et + 1);
                                if(prevalue.size() !=0){
                                    buff.add(prevalue.toString());
                                    prevalue.clear();
                                }
                                for (int ii = 0; ii < T9[Integer.parseInt(subvalue)].length; ii++) {
                                    if(buff.size() != 0){
                                        String[] buffarray = buff.toString().split("\\s*,\\s*");
                                        for(int ba = 0; ba<buffarray.length; ba++){
                                            prevalue.add(buffarray[ba].toString() + T9[Integer.parseInt(subvalue)][ii].toString());
                                        }
                                    }else{
                                        prevalue.add(T9[Integer.parseInt(subvalue)][ii]);
                                    }
                                }
                                buff.clear();
                            }
                            tv1.append("prevalue size: " + prevalue.size() + '\n');
                            for(int lp = 0; lp < prevalue.size(); lp++){
                                String without1 = prevalue.get(lp).toString().replace("[", "");
                                String without2 = without1.replace("]", "");
                                tv1.append(without2 + '\n');

                                mScs.getSuggestions(new TextInfo(without2), 1);

                            }
                    }
                });
            }

            public void onResume() {
                super.onResume();
                final TextServicesManager tsm = (TextServicesManager)
                        getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
                ***mScs = tsm.newSpellCheckerSession(null, null, this, true);***

            }

            public void onPause() {
                super.onPause();
                if (mScs != null) {
                    mScs.close();
                }
            }

            public void onGetSuggestions(final SuggestionsInfo[] arg0) {
                final StringBuilder sb = new StringBuilder();

                for (int i = 0; i < arg0.length; ++i) {
                    final int len = arg0[i].getSuggestionsCount();
                    sb.append('\n');

                    for (int j = 0; j < len; ++j) {
                        sb.append(arg0[i].getSuggestionAt(j));
                    }
                    //sb.append(" (" + len + ")");
                }

                runOnUiThread(new Runnable() {
                    public void run() {
                        tv2.append(sb.toString());
                    }
                });
            }

            @Override
            public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] arg0) {
                // TODO Auto-generated method stub
            }

        }
公共类MainActivity扩展活动实现SpellCheckerSession.SpellCheckerSessionListener{ 文本视图tv1、tv2、tv3; 按钮b1; 编辑文本et1; 私人拼写检查会话mScs; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(按钮)findViewById(R.id.btn1); tv1=(TextView)findViewById(R.id.tv1); tv2=(TextView)findViewById(R.id.tv2); tv3=(TextView)findViewById(R.id.tv3); et1=(EditText)findViewById(R.id.et1); 最终字符串[][]T9={ /*0*/{“a”、“b”、“c”}, /*1*/{“d”、“e”、“f”}, /*2*/{“g”、“h”、“i”}, /*3*/{“j”、“k”、“l”}, /*4*/{“m”、“n”、“o”}, /*5*/{“p”、“q”、“r”、“s”}, /*6*/{“t”,“u”,“v”}, /*7*/{“w”、“x”、“y”、“z”} }; 最终ArrayList prevalue=新ArrayList(); 最终ArrayList buff=新ArrayList(); b1.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ prevalue.clear(); buff.clear(); tv1.setText(“”); tv2.setText(“”); tv3.setText(“”); 对于(int-et=0;et对于(int ba=0;b你知道问题是什么吗?那么告诉我。我也有同样的问题。你知道问题是什么吗?那么告诉我。我也有同样的问题。