2014-04-02 33 views
1

我读过一些问题有关this..i've尝试他们建议所有的东西,但仍然,我有java的空指针.... 这里是我的主要代码ExpandableListView内弹出

public class DaftarAkun extends Activity { 
    TextView tekserror; 
    EditText password1; 
    EditText username; 
    EditText password2; 
    ImageButton buttonELVKelamin; 
    ImageButton buttonELVAktivitas; 
    // EditText email; 
    ExpandableListAdapter exListAdapterKelamin; 
    List<String> listDataHeaderKelamin; 
    HashMap<String, List<String>> listDataChildKelamin; 
    ExpandableListAdapter exListAdapterAktivitas; 
    List<String> listDataHeaderAktivitas; 
    HashMap<String, List<String>> listDataChildAktivitas; 
    Context thisContext = this; 


    protected void onCreate(Bundle savedInstance) { 
     super.onCreate(savedInstance); 
     setContentView(R.layout.daftar_akun); 
     buttonELVKelamin.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       ExpandableListView exListViewKelamin; 
       final Dialog dialog = new Dialog(thisContext); 
       dialog.setContentView(R.layout.pop_up_daftar_akun_elvkelamin); 
       dialog.setTitle("Jenis Kelamin"); 
       LayoutInflater li = (LayoutInflater) getBaseContext() 
         .getSystemService(LAYOUT_INFLATER_SERVICE); 
       View popupKelamin = li.inflate(
         R.layout.pop_up_daftar_akun_elvkelamin, null); 
       dialog.setContentView(v); 
       // get the listview 
       exListViewKelamin = (ExpandableListView) popupKelamin 
         .findViewById(R.id.exLVKelamin); 
       prepareListDataKelamin(); 

       exListAdapterKelamin = new com.ta.helper.ExpandableListAdapter(
         DaftarAkun.this, listDataHeaderKelamin, 
         listDataChildKelamin); 
       exListViewKelamin.setAdapter(exListAdapterKelamin); 
       exListViewKelamin 
         .setOnChildClickListener(new OnChildClickListener() { 

          @Override 
          public boolean onChildClick(
            ExpandableListView parent, View v, 
            int groupPosition, int childPosition, 
            long id) { 
           // TODO Auto-generated method stub 
           return false; 
          } 
         }); 
       WindowManager.LayoutParams params = dialog.getWindow() 
         .getAttributes(); 
       params.gravity = Gravity.TOP | Gravity.LEFT; 
       params.y = 80; 
       dialog.getWindow().setAttributes(params); 
       // dialog width and height. 
       dialog.getWindow().setLayout(
         ViewGroup.LayoutParams.MATCH_PARENT, 
         ViewGroup.LayoutParams.WRAP_CONTENT); 

      } 

      private void prepareListDataKelamin() { 
       listDataHeaderKelamin = new ArrayList<String>(); 
       listDataChildKelamin = new HashMap<String, List<String>>(); 

       // Adding child data 
       listDataHeaderKelamin.add("Jenis Kelamin"); 
       // Adding child data 
       List<String> kelamin = new ArrayList<String>(); 
       kelamin.add("Pria"); 
       kelamin.add("Wanita"); 
       listDataChildKelamin.put(listDataHeaderKelamin.get(0), kelamin);// Header, 
                       // Child 
                       // data 

      } 
     }); 

这里是我的主要XML

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#99cc00" 
    android:scrollbarSize="1dp" > 


     <ImageButton 
      android:id="@+id/buttonLVKelamin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="9dp" 
      android:layout_marginLeft="26.5dp" 
      android:layout_marginRight="25dp" 
      android:layout_marginTop="9dp" 
      android:background="#00000000" 
      android:src="@drawable/registrasi_hdpi_24" /> 


     <ImageButton 
      android:id="@+id/buttonLVAktivitas" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="15dp" 
      android:layout_marginLeft="26.5dp" 
      android:layout_marginRight="25dp" 
      android:layout_marginTop="9dp" 
      android:background="#00000000" 
      android:src="@drawable/registrasi_hdpi_24" /> 


</ScrollView> 

,这里是我的弹出式XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ExpandableListView 
     android:id="@+id/exLVKelamin" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 
    </ExpandableListView> 

</LinearLayout> 

希望有人注意到我的F我会修复它

回答

0

buttonELVKelamin永远不会初始化,因此当您设置您的点击侦听器时,它是null

+0

什么是白痴我!谢谢soooo很多家伙...:D – melandragem

+0

发生在我们最好的:) – dharms

+0

但嘿...我不想弹出..我点击了按钮,没有任何反应 – melandragem