2016-04-03 8 views
-1

ボタンを開始しようとすると、配列の配列エラーが発生するbtnEdit、btnDelete、btnView問題が初期化されていることがわかっていますが、誰も助けてくれる?私は問題が初期化であることを知っているが、私は正確にどこに誰が助けることができるのかわからないのですか?java.lang.NullPointerException:null配列への書き込みを試みる

here is my code: 

package com.astro.famouspandit.Activities.Activity; 

import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.Switch; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.astro.famouspandit.Database.DatabaseHelper; 
import com.astro.famouspandit.R; 
import com.astro.famouspandit.datasets.ItemProfile; 

import java.util.ArrayList; 

import mehdi.sakout.fancybuttons.FancyButton; 

public class ProfleList extends AppCompatActivity implements View.OnClickListener{ 
    private TextView txtProfileName,txtProfileDate,txtProfileTime,txtProfileLocation; 
    private FancyButton[] btnEdit,btnDelete,btnView; 
    LinearLayout linearlist ; 
    long count; 

    DatabaseHelper mydb; 

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


     mydb = new DatabaseHelper(this); 
     count = mydb.getCount(); 
     Log.d("count", "onCreate: "+count); 

     if (count == 0){ 

     }else{ 
      ArrayList<ItemProfile> listprofile = mydb.profilelist(); 
      for (int i = 1; i < count+1; i++) { 
       ItemProfile itemProfile = listprofile.get(i-1); 


       linearlist = (LinearLayout)findViewById(R.id.layoutlist); 
       View[] myView = new View[i]; 

       LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       myView[i-1] = inflater.inflate(R.layout.profile_list, null); 

       txtProfileName = (TextView)myView[i-1].findViewById(R.id.txtName); 
       txtProfileDate = (TextView)myView[i-1].findViewById(R.id.txtDate); 
       txtProfileTime = (TextView)myView[i-1].findViewById(R.id.txtTime); 
       txtProfileLocation = (TextView)myView[i-1].findViewById(R.id.txtLocation); 

       btnEdit = new FancyButton[i]; 
       btnEdit = new FancyButton[i]; 
       btnEdit = new FancyButton[i]; 


       btnEdit[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_edtProfile); 
       btnDelete[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_deleteProfile); 
       btnView[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_viewProfile); 

       btnEdit[i].setOnClickListener(this); 
       btnDelete[i].setOnClickListener(this); 
       btnDelete[i].setOnClickListener(this); 


       String profileName = itemProfile.getProfileName(); 
       txtProfileName.setText(profileName); 
       Log.d("ProfileName", "onCreate: "+itemProfile.getProfileName()); 
       int dd = itemProfile.getDay(); 
       int mm = itemProfile.getMonth(); 
       int yy = itemProfile.getYear(); 
       txtProfileDate.setText(dd+"/"+mm+"/"+yy); 
       Log.d("Profiledate", "onCreate: "+itemProfile.getDay()+itemProfile.getMonth()+itemProfile.getYear()); 
       int hour = itemProfile.getHour(); 
       int min = itemProfile.getMinute(); 
       txtProfileTime.setText(hour+":"+min); 
       Log.d("ProfileTime", "onCreate: "+itemProfile.getHour()+itemProfile.getHour()); 
       String city = itemProfile.getCity(); 
       txtProfileLocation.setText(itemProfile.getCity()); 
       Log.d("citylocation,city", "onCreate: "+itemProfile.getCity()+","+city); 
       linearlist.addView(myView[i-1]); 


      } 


     } 


    } 

    @Override 
    public void onClick(View v) { 
     int index = 0; 
      for (int i = 0; i < count; i++) 
      { 
       if (btnEdit[i].getId() == v.getId()) 
       { 
        index = i; 
        Toast.makeText(ProfleList.this, "btnEdit"+index, Toast.LENGTH_SHORT).show(); 
        break; 
       }else 
       if (btnDelete[i].getId() == v.getId()) 
       { 
        index = i; 
        Toast.makeText(ProfleList.this, "btnDelete"+index, Toast.LENGTH_SHORT).show(); 
        break; 
       }else 
       if (btnView[i].getId() == v.getId()) 
       { 
        index = i; 
        Toast.makeText(ProfleList.this, "btnView"+index, Toast.LENGTH_SHORT).show(); 
        break; 
       } 
      } 

      // index is now the array index of the button that was clicked 

    } 
} 

答えて

2

変更この:それに

btnEdit = new FancyButton[i]; 
btnEdit = new FancyButton[i]; 
btnEdit = new FancyButton[i]; 


btnEdit[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_edtProfile); 
btnDelete[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_deleteProfile); 
btnView[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_viewProfile); 

btnEdit[i].setOnClickListener(this); 
btnDelete[i].setOnClickListener(this); 
btnDelete[i].setOnClickListener(this); 

:今のは私がどこIFでループの中にはnullオブジェクト参照で私にFancyButton.getIdを()」を与える

btnEdit = new FancyButton[i]; 
btnDelete= new FancyButton[i]; 
btnView= new FancyButton[i]; 


btnEdit[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_edtProfile); 
btnDelete[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_deleteProfile); 
btnView[i-1] = (FancyButton)myView[i-1].findViewById(R.id.btn_viewProfile); 

btnEdit[i].setOnClickListener(this); 
btnDelete[i].setOnClickListener(this); 
btnView[i].setOnClickListener(this); 
+0

idsを比較する – bipin

+0

実際には、ここで達成しようとしていることが得られません...レイアウトコードを追加できますか? – malrok44

+0

あなたは私に正解を与えて、今では私のコードが動作していますが、私はエラーが発生しました.FancyButton.getId()私はIDを比較しています – bipin

関連する問題