2016-11-07 119 views
0
public void onClick(View v) { 
    Toast.makeText(MainActivity.this,"You taped!",Toast.LENGTH_SHORT).show(); 
    try { 
     startActivity(new Intent(MainActivity.this, FuelChoiceActivity.class)); 
    }catch (Exception e){ 
     System.out.println(e); 
    } 
} 

這是我的代碼。我已將新的活動添加到我的manifest.xml中。 try/catch塊沒有返回任何示例。當我按下按鈕時,執行並顯示吐司,但頁面不變。這個onClickListener在一個適配器方法'getView'中,所以它可以通過適配器生成的任何按鈕來獲得。我嘗試了其他事件,他們工作!唯一沒有的是去新的活動。意圖不開始新的活動

這裏是我的日誌當我調試,並點擊一個按鈕:


D/AbsListView: reportScrollStateChange: newState = 0, mLastScrollState = 0, mOnScrollListener = null, mScrollY = 0, mTouchMode = -1, mFirstPosition = 0 
V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0 
D/ActivityThread: ACT-AM_ON_PAUSE_CALLED ActivityRecord{2c1d62f0 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} 
D/ActivityThread: ACT-PAUSE_ACTIVITY handled : 1/[email protected] 
D/AbsListView: onWindowFocusChanged: hasWindowFocus=false, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} 
D/OpenGLRenderer: Flushing caches (mode 0) 
D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) 
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0 
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1 
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3 
D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) 
D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) 
V/ActivityThread: Handling launch of ActivityRecord{1ff7b407 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}} 
V/ActivityThread: ActivityRecord{1ff7b407 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}: [email protected], appName=com.example.stamatis.redhotpepper, pkg=com.example.stamatis.redhotpepper, comp={com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}, dir=/data/app/com.example.stamatis.redhotpepper-1/base.apk 
D/ActivityThread: ACT-LAUNCH_ACTIVITY handled : 0/ActivityRecord{1ff7b407 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}} 
D/ActivityThread: ACT-PAUSE_ACTIVITY_FINISHING handled : 0/[email protected] 
V/ActivityThread: Performing resume of ActivityRecord{2c1d62f0 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} 
D/ActivityThread: ACT-AM_ON_RESUME_CALLED ActivityRecord{2c1d62f0 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} 
V/ActivityThread: Resume ActivityRecord{2c1d62f0 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} started activity: false, hideForNow: false, finished: false 
V/ActivityThread: Resuming ActivityRecord{2c1d62f0 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} with isForward=true 
V/PhoneWindow: DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{dfe4562 com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{1d6eaa25 V.E..... R.....I. 0,0-480,782} 
V/ActivityThread: Scheduling idle handler for ActivityRecord{2c1d62f0 [email protected] {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} 
D/ActivityThread: ACT-RESUME_ACTIVITY handled : 1/[email protected] 
D/AbsListView: onWindowFocusChanged: hasWindowFocus=true, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} 
V/InputMethodManager: onWindowFocus: com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} softInputMode=272 first=false flags=#1810100 
D/ActivityThread: ACT-DESTROY_ACTIVITY handled : 1/[email protected] 
D/OpenGLRenderer: Flushing caches (mode 0) 
D/OpenGLRenderer: Flushing caches (mode 0) 
D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) 

感謝您的閱讀和你的時間。我會欣賞想法。

+1

您是否在FuelChoiceActivity的onCreate中獲得了任何記錄器 –

+0

如果我們對FuelChoiceActivity有訪問權限,我們可以更好地瞭解這個問題 – nandsito

+0

FuelChoiceActivity只有基本的onCreate和東西。如果我將它作爲主要工具啓動它。唯一的區別是我的主要活動擴展了Activity,FuelChoiceActivity擴展了AppCompatActivity。第二個沒有日誌 –

回答

-1

我的主要活動來延長活動

public class MainActivity extends Activity 

在該活動中我試圖轉移到另一個,它正在擴大AppCombatActivity類。

public class FuelChoiceActivity extends AppCombatActivity 

所以語法和一切都是正確的。所以我改變了FuelChoiceActivity(活動我希望在移動)擴展到:

public class FuelChoiceActivity extends Activity 

好像你不能移動到另一個活動,如果他們兩個不延長同一類。

+0

不是爲了我的緣故,但爲了未來讀者的緣故,請詳細解釋您做了什麼,以及「同班同學」是什麼。 –