2012-01-10 12 views
3

2つのテキストビューと2つのボタンで表示されるダイアログをコーディングしました。 私はその問題についてもグーグルで調べましたが、私の問題を数学的に調べたものは見つかりませんでした。 は、ここではいくつかのコードです:ボタンとonClickリスナーのダイアログで例外がスローされる

case R.id.open: 

      openDialog=new Dialog(this); 
      openDialog.setContentView(R.layout.open_dialog); 

      openDialog.setTitle(head); 
      openDialog.setCancelable(true); 

    Button open_cancel=(Button)findViewById(R.id.open_cancel); 
      open_cancel.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       openDialog.cancel(); 
      } 
     }); 

が、私はボタンが付いたダイアログアップを表示することはできません。 私は問題がないこれらの行せずに、それを呼び出す場合:

Button open_cancel=(Button)findViewById(R.id.open_cancel); 
      open_cancel.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       openDialog.cancel(); 
      } 
     }); 

これはXMLファイルです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/open_dialog" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="10dp" 
     >  
    <EditText android:id="@+id/open_head" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:text="ojfpojew ojr pojr"    
       /> 
    <EditText android:id="@+id/open_note" 
       android:layout_width="fill_parent" 
       android:text="oijpojepojpotjpotejpe ojtpojtpo ewpoj tpojt pp jpojtpoj etpoj poj poj t" 
       android:layout_height="150dp"    
       /> 
    <Button android:id="@+id/open_edit" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="edit" 
      /> 
    <Button android:id="@+id/open_cancel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="cancel" 
      />  
</LinearLayout> 

この作品ではない、なぜ私は本当に理解していない... ここでエラーがありますそれは場合に役立ちます、ログ:

01-05 16:43:51.004: D/dalvikvm(2336): GC freed 1010 objects/70136 bytes in 75ms 
01-05 16:43:51.204: D/dalvikvm(2336): GC freed 91 objects/3664 bytes in 53ms 
01-05 16:43:51.494: D/dalvikvm(2336): GC freed 132 objects/6240 bytes in 62ms 
01-05 16:43:51.674: D/dalvikvm(2336): GC freed 58 objects/2312 bytes in 56ms 
01-05 16:43:51.944: D/dalvikvm(2336): GC freed 147 objects/9128 bytes in 63ms 
01-05 16:43:52.383: D/ViewFlipper(2336): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false 
01-05 16:44:00.973: D/dalvikvm(2336): GC freed 25495 objects/1393728 bytes in 88ms 
01-05 16:44:02.644: D/dalvikvm(2336): GC freed 45722 objects/2044568 bytes in 102ms 
01-05 16:44:04.424: I/Resources(2336): Loaded time zone names for en in 1591ms. 
01-05 16:44:06.834: D/dalvikvm(2336): GC freed 36788 objects/1674624 bytes in 102ms 
01-05 16:44:11.243: D/AndroidRuntime(2336): Shutting down VM 
01-05 16:44:11.263: W/dalvikvm(2336): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 
01-05 16:44:11.263: E/AndroidRuntime(2336): Uncaught handler: thread main exiting due to uncaught exception 
01-05 16:44:11.273: E/AndroidRuntime(2336): java.lang.NullPointerException 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at producteev.push.Producteev_pushActivity.onContextItemSelected(Producteev_pushActivity.java:247) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.app.Activity.onMenuItemSelected(Activity.java:2174) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2731) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:129) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:884) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.widget.AdapterView.performItemClick(AdapterView.java:284) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.widget.ListView.performItemClick(ListView.java) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.os.Handler.handleCallback(Handler.java:587) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.os.Handler.dispatchMessage(Handler.java:92) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.os.Looper.loop(Looper.java:123) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at java.lang.reflect.Method.invoke(Method.java:521) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
01-05 16:44:11.273: E/AndroidRuntime(2336):  at dalvik.system.NativeStart.main(Native Method) 
01-05 16:44:11.293: I/dalvikvm(2336): threadid=7: reacting to signal 3 
01-05 16:44:11.323: I/dalvikvm(2336): Wrote stack trace to '/data/anr/traces.txt' 
01-05 16:44:13.383: I/Process(2336): Sending signal. PID: 2336 SIG: 9 
+1

私は全てのもの(特にLogCat)を提供したので、私は投票しました。 –

+0

あなたのコードのどの行が 'Producteev_pushActivity.java:247'です。 – Ronnie

+0

これはボタンをインスタンス化した行です。すべての返信のおかげで – Florian

答えて

3

はこれを試してみてください、

Button open_cancel=(Button)openDialog.findViewById(R.id.open_cancel); 
関連する問題