2017-06-15 66 views
-2

嗨,大家好,我只是想要求助於我的應用程序,它的強制每當我選擇一個id就停止,它顯示錯誤在我的字符串中,但我沒有看到任何錯誤,告訴我這個錯誤出現在「final String user = etinput.getText()。toString();」。這裏是我的代碼選擇選定的ID時,應用程序強制停止

ArrayList<Messages> list; 
MessageDatabase mydb; 
MessageAdapter adapter = null; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_list_message); 
    listv = (ListView) findViewById(R.id.lv); 
    registerForContextMenu(listv); 
    add = (FloatingActionButton) findViewById(R.id.fabadd); 
    fbnew = (FloatingActionButton) findViewById(R.id.fabnew); 
    fbedit = (FloatingActionButton) findViewById(R.id.fabedit); 
    fbdelete = (FloatingActionButton) findViewById(R.id.fabdelete); 
    add = (FloatingActionButton) findViewById(R.id.fabadd); 
    backlist = (ImageButton) findViewById(R.id.imgbacklist); 

    rotateplus = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fabplus); 
    clockplus = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fabplusclose); 
    fabopen = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_open); 
    fabclose = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_close); 


    add.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
     if(open){ 

      add.startAnimation(clockplus); 
      fbnew.startAnimation(fabclose); 
      fbedit.startAnimation(fabclose); 
      fbdelete.startAnimation(fabclose); 
      fbnew.setClickable(false); 
      fbedit.setClickable(false); 
      fbdelete.setClickable(false); 

      open = false; 
     } 
     else{ 
      add.startAnimation(rotateplus); 
      fbnew.startAnimation(fabopen); 
      fbedit.startAnimation(fabopen); 
      fbdelete.startAnimation(fabopen); 
      fbnew.setClickable(true); 
      fbedit.setClickable(true); 
      fbdelete.setClickable(true); 

      open = true; 

      fbnew.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        Intent i = new Intent(ListMessage.this,AddActivity.class); 
        startActivity(i); 
        finish(); 
       } 

      }); 
      fbdelete.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 

        alert(); 

       } 
      }); 
      fbedit.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        LayoutInflater lay = getLayoutInflater(); 
        viewlayout = lay.inflate(R.layout.input, (ViewGroup) findViewById(R.id.layoutinput)); 
        AlertDialog.Builder b = new AlertDialog.Builder(ListMessage.this); 
        b.setTitle("Enter the MSG ID you want to edit"); 
        b.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialogInterface, int i) { 

          EditText etinput = (EditText) findViewById(R.id.edtinput); 



          Intent a = new Intent(ListMessage.this,UpdateActivity.class); 

          startActivity(a); 
          finish(); 

         } 
        }); 
        b.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialogInterface, int i) { 
          dialogInterface.cancel(); 
         } 
        }); 
        b.setView(viewlayout); 
        AlertDialog alert = b.create(); 
        alert.show(); 

       } 
      }); 
     } 
     } 
    }); 


    backlist.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      finish(); 
     } 
    }); 

    mydb = new MessageDatabase(this, "MDB.sqlite", null, 1); 

    list = new ArrayList<Messages>(); 
    adapter = new MessageAdapter(this, R.layout.messages, list); 
    listv.setAdapter(adapter); 


    Cursor cursor = SecondActivity.mydb.getData("SELECT * FROM MDB "); 
    list.clear(); 
    while (cursor.moveToNext()) { 


     int id = cursor.getInt(0); 


     String frm = cursor.getString(1); 
     String to = cursor.getString(2); 

     String msg = cursor.getString(3); 

     list.add(new Messages(id, frm, to, msg)); 

    } 
    adapter.notifyDataSetChanged(); 

} 





private void editt() { 



} 


private void alert() { 

    LayoutInflater lay = getLayoutInflater(); 
    viewlayout = lay.inflate(R.layout.input, (ViewGroup) findViewById(R.id.layoutinput)); 
    EditText etinput = (EditText) findViewById(R.id.edtinput); 
    final String user = etinput.getText().toString(); 

    AlertDialog.Builder b = new AlertDialog.Builder(ListMessage.this); 
    b.setTitle("Enter the MSG ID you want to delete"); 
    b.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialogInterface, int i) { 

      Integer rows = mydb.deleteData(user); 
      if (rows > 0) { 
       Toast.makeText(getApplicationContext(), "Done...", Toast.LENGTH_LONG).show(); 
       Intent a = new Intent(ListMessage.this,ListMessage.class); 
       startActivity(a); 
       finish(); 

      } else { 
       Toast.makeText(getApplicationContext(), "Delete Failed...", Toast.LENGTH_LONG).show(); 
      } 


     } 
    }); 
      b.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialogInterface, int i) { 
        dialogInterface.cancel(); 
       } 
      }); 
    b.setView(viewlayout); 

    AlertDialog alert = b.create(); 
    alert.show(); 

} 

And here is my logcat

+1

後在這個問題你完全崩潰logcat的一個EditText。 –

+0

最有可能您的etinput爲空。發佈您的XML文件。可能你想要viewLayout.findViewById(R.id.input) – X3Btel

回答

0

把你

EditText etinput = (EditText) findViewById(R.id.edtinput); 

在OnCreate並使其所有的類訪問。

或者如果它是從另一種觀點認爲

EditText etinput = (EditText) view.findViewById(R.id.edtinput); 
相關問題