我是新来的android这是我的第一个演示程序。我正在尝试从一个页面导航到另一个页面。但我无法导航到另一个页面,我可能在主XML文件中有一个按钮,并舔它正在移动到另一个XML下一页。我有2个java类:1st MianAcitvity,nextpagejava。 2 XML:activity_main,下一页不幸的是,androiddemo(项目名称)已停止
我的代码:清单
<activity
android:name="com.example.androiddemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="nextpagejava" ></activity>
MainActivity.java
package com.example.androiddemo;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.drm.DrmStore.Action;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt = (Button)findViewById(R.id.bnt);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bnt:
Intent in = new Intent(this, nextpagejava.class);
startActivity(in);
break;
}
}
}
acitivity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/clicktxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
/>
<Button
android:id="@+id/bnt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Click Me"
/>
nextpage.xml
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I am i a next page..."
/>
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Back"
/>
nextpagejava.java
package com.example.androiddemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class nextpagejava extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt = (Button)findViewById(R.id.btn1);
bt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
我得到的消息说, “不幸的是,androiddemo已停止” 此消息作为一个弹出。
有人可以告诉我为什么这个错误即将到来,请告诉我从哪里可以找到逐行调试日志。
你可以发布错误日志,请......或者您必须从日志中标识自己... –
使用logcat检查堆栈跟踪并找出发生错误(异常)的位置。看看你是否能找到解决方案。如果不是,回来并提供包括堆栈跟踪在内的实际错误! – Veger
你可以在菜单栏中找到logcat - > WindowBar - > ShowView - > logcat –