我是新手,我只是创建一个简单的Android应用程序,其中有2个按钮可以在点击时将您带到不同的页面,具有不同的功能。
然而,我的应用程序在启动时崩溃,只是说
不幸的是[app name]已停止
我不明白
由于我几乎没有对我的 MainActivity.java 进行任何更改,代码似乎编写得很好,eclipse显示没有错误......请帮忙吗?我在Stack周围搜索过,但是找不到任何特定的东西......
这是我的MainActivity.java:
package com.example.helper;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**Called upon when the user clicks the 'Abbreviations' button*/
public void listDefinitions (View view){
Intent intent = new Intent(this, ListDefinitions.class);
startActivity(intent);
}
/**Called upon when the user clicks the 'Assistant' button*/
public void openAssistant (View view){
Intent intent = new Intent(this, Assistant.class);
startActivity(intent);
}
}
这是我的activity_main.xml:
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.legittest.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="@string/intro_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="21.5sp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="@string/module_selection"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/definitions_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="34dp"
android:layout_marginTop="111dp"
android:text="@string/definitions"
android:onClick="listDefinitions" />
<Button
android:id="@+id/assistant_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/definitions_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="@string/assistant"
android:onClick="openAssistant" />
<TextView
android:id="@+id/definitions_explainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/definitions_button"
android:layout_centerHorizontal="true"
android:text="@string/definitions_info"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/greycolor" />
<TextView
android:id="@+id/pa_explainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/definitions_explainer"
android:layout_below="@+id/assistant_button"
android:text="@string/assistant_info"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/greycolor" />
</RelativeLayout>
我的ListDefinitions.java&amp;此时,Assistant.java没有受到影响。
我的宣言:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.theocratichelper"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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=".ListDefinitions"
android:label="@string/title_activity_list_definitions"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
<activity
android:name=".PreachAssistant"
android:label="@string/title_activity_preach_assistant"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
</application>
</manifest>
答案 0 :(得分:1)
这是你的清单,用这个替换清单中的“最后”活动:
<activity
android:name=".Assistant"
android:label="@string/title_activity_preach_assistant"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
您的班级名称是助理,而不是我认为的PreachAssistant。
答案 1 :(得分:0)
只需替换Android Manifest中的最后一个活动。
<activity
android:name=".Assistant"
android:label="@string/title_activity_preach_assistant"
</activity>