2010-05-19 130 views
0

我有我的應用程序中的自定義對話框,我有一個問題,實現所需的行爲。我的對話框有4個按鈕。 (返回,有效,修改和恢復)。當用戶點擊修改或有效時,我想調用另一個活動。所以我使用意圖,但它崩潰。問題與自定義對話框Android

錯誤日誌:

05-19 13:29:21.495: ERROR/DEBUGTAG(974): 顯示java.lang.NullPointerException 05-19 13:29:21.495:ERROR/DEBUGTAG (974):
在 android.content.ComponentName(ComponentName.java:75) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):在 android.content.Intent(意向。 java:2551) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at 錯誤/調試(974):在 android.view.View.performClick(View.java: 2364) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):在 android.view.View.onTouchEvent(View.java:4179) 05-19 13:29:21.495: ERROR/DEBUGTAG (974):at android.widget.TextView.onTouchEvent(TextView.java:6540) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at android.view.View.dispatchTouchEvent(View。 java:3709) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-19 13:29:21.495: ERROR/DEBUGTAG(974) :at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884 ) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):在 com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent (PhoneWindow.java:1659) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 05- 19 13:29:21.495: ERROR/DEBUGTAG(974):at android.app.Dialog.dispatchTouchEvent(Dialog.java:643) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):在 android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 05-19 13:29:21.495: ERROR/DEBUGTAG(974 ):at android.os.Handler.dispatchMessage(Handler.java:99) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):at android.os.Looper.loop(Looper.java: 123) 05-19 13:29:21。495: ERROR/DEBUGTAG(974):在 android.app.ActivityThread.main(ActivityThread.java:4363) 05-19 13:29:21.495: ERROR/DEBUGTAG(974):在 java.lang中。方法.invokeNative(Native 方法)05-19 13:29:21.495: ERROR/DEBUGTAG(974):at java.lang.reflect.Method.invoke(Method.java:521) 05-19 13 :29:21.495: ERROR/DEBUGTAG(974):在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860) 05-19 13:29:21.495: ERROR/DEBUGTAG( 974):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 05-19 13: 29:21.495: ERROR/DEBUGTAG(974):在 dalvik.system.NativeStart.main(本地 法)

我的自定義對話框:

package com.android.booztermobile.services; 

import com.android.booztermobile.R; 

import android.app.Dialog; 
import android.content.Context; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.Button; 


public class MailDialog extends Dialog { 

    private Button btnValid; 
    private Button btnBack; 
    private Button btnRestore; 
    private Button btnModify; 
    private Context context; 


    public MailDialog(Context cont) { 
     super(cont); 
     context = cont; 
     } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Log.d("TestApp", "Dialog created"); 
      setContentView(R.layout.dialog_classement);  

      btnValid = (Button) findViewById(R.id.btnValidClassement); 
      btnBack = (Button) findViewById(R.id.btnBackClassement);  
      btnRestore = (Button) findViewById(R.id.btnRestoreClassement); 
      btnModify = (Button) findViewById(R.id.btnModifyClassement); 

    } 
} 

和活動(切,因爲太多長):

 //create dialog 
public void getMailInformations(View v, Context context){ 

    currentMail = (MailHeader) v.getTag(); 

    dial = new MailDialog(context); 

    dial.setTitle("Classement"); 
    dial.show(); 

    btnValidClassement = (Button) dial.findViewById(R.id.btnValidClassement); 
    btnValidClassement.setOnClickListener(this); 

} 

/**的onclick:*/

public void onClick(View view) { 

//THIS WORKS (Activity Button) 
    if (view == lblPreviousMails) { 

      positionList -= 20; 
      // create Intent 
      Intent defineIntentDisplayPreviousMails = new Intent(HeaderMailDisplayActivity.this, HeaderMailDisplayActivity.class); 

      //Create bundle to pass informations to the other activity 
      Bundle objetbundle = new Bundle(); 
      objetbundle.putString("positionList", String.valueOf(positionList)); 
      objetbundle.putStringArrayList("currentMails", seqnumList); 
      objetbundle.putString("uidh", uidh); 
      defineIntentDisplayPreviousMails.putExtras(objetbundle); 

      // call headermailDisplayActivity 
      HeaderMailDisplayActivity.this.startActivity(defineIntentDisplayPreviousMails); 

     } 

//THIS DOESN'T WORKS (Dialog Button) 
    if(view == btnValidClassement){ 

    try{ 

    ClassementHandlerCall classement = new    ClassementHandlerCall(); 
     boolean mailClassify = classement.classifyMail(AuthentificationActivity.uidh, 
     String.valueOf(currentMail.getSeqnum()), null, null); 

     dial.dismiss(); 

     if (mailClassify == true){ 

       //create Intent 
       Intent defineIntentClassifyMails = new Intent(MailClassificationActivity.this, HeaderMailDisplayActivity.class); 

       // Object that allows to pass person's uidh and positionList onto HeaderMailDisplayActivity 
       Bundle objetbundle = new Bundle(); 
       objetbundle.putString("uidh",uidh); 
       objetbundle.putString("positionList", String.valueOf(positionList)); 
       defineIntentClassifyMails.putExtras(objetbundle); 

       // call HeaderMailDisplayActivity 
       MailClassificationActivity.this.startActivity(defineIntentClassifyMails); 


     } 

    }catch(Exception e){ 
    // TODO Auto-generated catch block 
    Log.e("DEBUGTAG","Error occured", e); 
    e.printStackTrace(); 
    } 



    } 

} 
+0

請格式化您的代碼..感謝 – hara 2010-05-19 13:54:50

+0

是的,我試過了,但我把[code] [/ code],它似乎不起作用 – Nanis 2010-05-19 13:59:58

+0

閱讀此,以便您可以瞭解如何使用編輯器:http: //stackoverflow.com/editing-help – Cristian 2010-05-19 14:04:05

回答

0

根據堆棧跟蹤,它看起來像您呼叫的一些畸形參數的構造函數意向。

+0

是的,但哪一個?因爲我使用了兩次相同的意圖構造函數。一個工作(當它是一個活動按鈕),其他不工作(當它是一個對話按鈕) – Nanis 2010-05-20 06:50:00

+0

在代碼中,你已經添加了,只有一個構造函數。 – Karan 2010-05-20 08:58:25

+0

我還沒有添加所有的代碼,因爲它太長了 – Nanis 2010-05-20 09:59:45

0

開始從目的,你需要在清單XML添加此代碼

<activity android:name=".youractivityname" 
      android:configChanges="keyboardHidden|orientation" 
      android:label="@string/app_name"> 
</activity> 

文件的活動清單中的應用程序關閉標籤之前將代碼活動。
而在按鈕單擊事件的代碼是:

Intent myIntent = new Intent(v.getContext(), youractivity.class); 
startActivityForResult(myIntent, 1); 
+0

我的活動已在清單XML中聲明。當我的意圖不是對話按鈕時,我的意圖就起作用了。 – Nanis 2010-05-19 14:20:16