写了一个小程序,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多媒体信息mms模块开发相关的书
- eclipse调试出现Source not found
- android模拟器如何测试多点触控呢?
- assets里有4个文件夹,这4个文件夹里存有txt文件, 怎么打开txt文件
- webview加载本地文字网络图片时出现的问题
- WebView空间使用flash插件播放视频问题
- 使用Socket连接读取数据,总是在read(byte)方法这一行报错
- org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 文件提前结束
- Fresco不能自适应高度吗?
- TableView怎么取消单击选中事件
- 求高人指点
- 在线请求大神帮助
你的两个activity在androidmanifest.xml里面声明了没