2016-11-07 156 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

不是为了我的缘故,但为了未来读者的缘故,请详细解释您做了什么,以及“同班同学”是什么。 –