写了一个小程序,eclipse没有报错,警告都没有,放到手机上就总是显示已停止运行。这是代码:
MainActivity.java:
package redknot.com.example.redphone;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button buttonphone;
private Button buttontext; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonphone = (Button) findViewById(R.id.buttonphone);
buttontext = (Button) findViewById(R.id.buttontext);
buttonphone.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intentphone = new Intent(MainActivity.this,Phone.class);
startActivity(intentphone);
}
});
buttontext.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intenttext = new Intent(MainActivity.this,Text.class);
startActivity(intenttext);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/buttonphone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/gotophone"
/>
<Button
android:id="@+id/buttontext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/gototext"
/>
</LinearLayout>Android手机Eclipse
MainActivity.java:
package redknot.com.example.redphone;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button buttonphone;
private Button buttontext; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonphone = (Button) findViewById(R.id.buttonphone);
buttontext = (Button) findViewById(R.id.buttontext);
buttonphone.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intentphone = new Intent(MainActivity.this,Phone.class);
startActivity(intentphone);
}
});
buttontext.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intenttext = new Intent(MainActivity.this,Text.class);
startActivity(intenttext);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/buttonphone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/gotophone"
/>
<Button
android:id="@+id/buttontext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/gototext"
/>
</LinearLayout>Android手机Eclipse
解决方案 »
- android ndk开发:JNI中怎样引用so动态库中的函数
- android 使用BASE64Decoder and BASE64Encoder
- 关于调用notifyDataSetChanged更新ListView&ListActivity
- textview一行最后一个字隐掉一半
- android下载源码出错,求大神帮助
- 获取Activity的View
- 初学Fragments+ActionBar两个基础问题请教下
- service怎么向Activity传值
- 在android的一个java类源码中添加一个api函数供app使用,如何实现?
- 想学习android开发 企业都在用什么开发工具及开发工具配置安装步骤
- 求高人指点
- 在线请求大神帮助
你的两个activity在androidmanifest.xml里面声明了没