2011-10-12 67 views
0

我的程序運行不正常,我不明白爲什麼,請介意幫忙嗎?儘管build沒有錯誤,但發生了強制停止?

package project.ernest; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 

public class Part1 extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 
    Intent DisclaimerHandler = new Intent(getBaseContext(), Part2.class); 
    { 
    Part1.this.startActivity(DisclaimerHandler); 
    } 
} 

我有2個.java文件,即Part1和Part2。 以及一個.xml文件名稱放置在佈局

我試圖運行它,但它給了我一個力量停止。

+0

你會介意在logcat中粘貼堆棧跟蹤嗎? – Farhan

+0

你在Logcat中遇到了什麼錯誤。 –

+0

抱歉,我是新的Logcat,我如何導航到那裏? – FreshMeat

回答

0

使用這樣的..

package project.ernest; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 

public class Part1 extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     final Button gs = (Button) findViewById(R.id.save); 
     gs.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      Intent i = new Intent(getBaseContext(), Part2.class);   
      Part1.this.startActivity(i);  
     } 
    });   
} 
+0

現在與您的代碼,我可以進入我的應用程序已經。 – FreshMeat

+0

但它失敗的時刻我點擊免責聲明 – FreshMeat

+0

這是我已經命名的按鈕之一 – FreshMeat

0

很難說沒有任何logcat中,但我會嘗試猜測。可能你忘了在你的Manifest文件中聲明你的Part2活動。希望我是對的。

+0

FreshMeat

+0

是正確的方法嗎? – FreshMeat

+0

@ user990571,name應該包含您的包名稱的全名,如com.google.android.SomeClass。 – Egor

相關問題