2012-09-18 21 views
4

我有一個已發佈的應用程序,它得到了一些奇怪的用戶反饋。因此,對於堆棧跟蹤,在嘗試調用Toastshow()方法時出現了一個膨脹錯誤。堆棧如下:調用Toast時發生未知的膨脹錯誤

android.view.InflateException: Binary XML file line #21: Error inflating class <unknown> 
at android.view.LayoutInflater.createView(LayoutInflater.java:596) 
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:457) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:391) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:347) 
at android.widget.Toast.makeText(Toast.java:247) 
at my.app.name.Launcher$ActionDecider.onPostExecute(Launcher.java:155) 

和在線155我的吐司的節目()只是一個共同的呼聲:

Toast.makeText(LauncherAct.getContext(), "Some random string here", Toast.LENGTH_SHORT).show(); 

有誰知道它可能是什麼想法?

+3

似乎與你的asynctask中的上下文有關。你有正確的上下文嗎?您可以使用asynctask的構造函數將活動的上下文傳遞給asynctask。然後使用asynctask類中的局部變量作爲上下文。 – VendettaDroid

+0

不,我的環境沒問題。它遵循在Android博客上定義的良好實踐的建議,以避免內存泄漏(這是一個返回給定Activity上下文的靜態getContext方法)。該方法總是返回在Activity onCreate上初始化的上下文,所以它應該沒問題... – Alesqui

+0

@Alesqui你曾經找到過這個問題的解決方案嗎? –

回答

0

我有同樣的問題。突然,我的Toast調用開始出現這個錯誤Binary XML file line #21: Error inflating class。我用相同的方法再次調用我的方法,直到從網絡提供商處獲得所需的gps值。當我移除回憶時,問題就消失了。我沒有得到他們之間的關係,但工作。

public void getLocation() 
{ 
    if(gps.canGetLocation()) 
    { 
     latitude = gps.latitude; 
     longitude = gps.longitude; 
     if((latitude < 0) || (longitude < 0)) 
     { 
      Toast.makeText(CharityGPS.this, "Konumunuz saptanıyor lütfen bekleyiniz.", Toast.LENGTH_SHORT).show(); 
      getLocation(); //recalling is here. when I remove it, problem has gone. 
     } 
     else 
     { 

      ... 
     } 
} 

希望這會有所幫助。