Java 为什么我的活动还没有开始?
我认为我的活动有问题,因为它可以很好地运行启动屏幕,但当它到达主页时,就会出现强制关闭错误。如果你能看到我的Java 为什么我的活动还没有开始?,java,android,android-manifest,Java,Android,Android Manifest,我认为我的活动有问题,因为它可以很好地运行启动屏幕,但当它到达主页时,就会出现强制关闭错误。如果你能看到我的home.java代码是否正确,我也很感激。我基本上想打开其他活动,然后按退出按钮退出应用程序 安卓清单 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.decrypter" android:versionCode="1" android:version
home.java
代码是否正确,我也很感激。我基本上想打开其他活动,然后按退出按钮退出应用程序
安卓清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.decrypter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
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=".Home"
android:label="@string/title_activity_home" >
<intent-filter>
<action android:name="com.example.decrypter.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
home.java
package com.example.decrypter;
import android.os.Bundle;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.AdapterView.OnItemSelectedListener;
public class Home extends Activity implements OnItemSelectedListener {
Button btn_start,btn_about,btn_exit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
btn_start = (Button) findViewById(R.id.btn_start);
btn_about = (Button) findViewById(R.id.btn_about);
btn_exit = (Button) findViewById(R.id.btn_exit);
btn_start.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
Intent start = new Intent(Home.this, MainPage.class);
Home.this.startActivity(start);
}
});
btn_about.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
Intent about = new Intent(Home.this, about.class);
Home.this.startActivity(about);
}
});
btn_exit.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.home, menu);
return true;
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
package com.example.decrypter;
导入android.os.Bundle;
导入android.app.Activity;
导入android.app.Application;
导入android.content.Intent;
导入android.view.Menu;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.AdapterView.OnItemSelectedListener;
公共类主扩展活动实现了MSelectedListener{
按钮btn_开始,btn_关于,btn_退出;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
btn_start=(按钮)findviewbyd(R.id.btn_start);
btn_about=(按钮)findviewbyd(R.id.btn_about);
btn_退出=(按钮)findViewById(R.id.btn_退出);
btn_start.setOnClickListener(新视图.OnClickListener()
{
公共void onClick(视图v){
意图开始=新意图(Home.this、MainPage.class);
Home.this.startActivity(开始);
}
});
btn_about.setOnClickListener(新视图.OnClickListener()
{
公共void onClick(视图v){
//TODO自动生成的方法存根
意向关于=新意向(Home.this,about.class);
Home.this.startActivity(关于);
}
});
btn_exit.setOnClickListener(新视图.OnClickListener()
{
公共void onClick(视图v){
//TODO自动生成的方法存根
系统出口(0);
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(R.layout.home,菜单);
返回true;
}
@凌驾
已选择公共视图(适配器视图arg0、视图arg1、内部arg2、,
长arg3){
//TODO自动生成的方法存根
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
}
String.xml
<string name="app_name">decrypter</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main_page">MainPage</string>
<string name="title_activity_home">Home</string>
<string name="prompt">- </string>
<string-array name="numbers">
<item >1</item>
<item >2</item>
<item>3</item>
<item >4</item>
<item>5</item>
<item >6</item>
<item >7</item>
<item >8</item>
<item>9</item>
</string-array>
解密程序
设置
主页
家
-
1.
2.
3.
4.
5.
6.
7.
8.
9
home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btn_about"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home" >
<Button
android:id="@+id/btn_start"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="183dp"
android:gravity="center"
android:text="Start" />
<Button
android:id="@+id/btn_about"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_start"
android:layout_below="@+id/btn_start"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="About me" />
<Button
android:id="@+id/btn_exit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Button01"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:gravity="center"
android:text="Exit" />
</RelativeLayout>
在您的main.java
中,无论是单击还是任何其他事件,您都必须为主活动调用开始活动。或者,如果希望首先加载“主活动”,则可以将“主活动”设为“主活动”,并删除其他主活动。将您的家庭活动转换为LAUNCHER
活动 您是否正在从splash对home活动调用startActivity()?发布您的logcat跟踪以查看errorwrite而不是Post日志。您应该发布splash活动的代码以及崩溃的logcat输出。其他问题(与崩溃无关)是:我看不到清单中定义的关于
活动的;你;你真的想在用户按下“开始”时启动另一个相同的活动吗?我确实尝试将Home.java作为主活动运行,但它不起作用Home.java有问题,因为我有另一个活动,当我在清单中将其设置为运行时,它起作用。是的,我确实将splash.java之后运行的活动更改为home.java,但是你的splash.java看起来怎么样?你是不是要开始一些家庭活动?