更新:我已经按照下面的建议做了几乎一切,但仍然出现了这个错误(请参见新的logcat文件)。不过这个错误和之前不同,所以我不知道该怎么修复。 好吧,我是个初学者,所以我真的不知道发生了什么。当我尝试在模拟器中运行这个应用程序时,它只是显示“很遗憾,这个应用程序已停止运行”。我已经搜索了所有类似的问题,但还没有找到答案。顺便说一句,这不是一个完成的应用程序,甚至还没有开始,但我想在继续之前先让它运行起来。以下是logcat文件。
error opening trace file: No such file or directory (2)
08-19 06:09:04.579: D/AndroidRuntime(1006): Shutting down VM
08-19 06:09:04.599: W/dalvikvm(1006): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0x7f080001 type #0x12 is not valid
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2103)
at android.content.res.Resources.getLayout(Resources.java:852)
at android.view.MenuInflater.inflate(MenuInflater.java:107)
at com.nickymilton.testbasebal3.MainActivity.onCreateOptionsMenu(MainActivity.java:22)
at android.app.Activity.onCreatePanelMenu(Activity.java:2476)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2913)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
现在这里是activity_main.xml。
<?xml version="1.0" encoding="utf-8"?>
<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:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="@string/EnterHome"
android:textColor="@color/White" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="@string/home_team"
android:layout_below="@id/textView1"
android:shadowColor="@color/ICSBlue" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="@string/EnterAway"
android:textColor="@color/White" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="@string/away_team"
android:shadowColor="@color/ICSBlue" />
<Button
android:id="@+id/button3"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:layout_below="@id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="@string/Enter" />
<Button
android:id="@+id/button2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@id/button3"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="@string/Skip" />
</RelativeLayout>
现在是activity_display_message.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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".DisplayMessageActivity" />
</RelativeLayout>
这里是mainActivity.java文件
package com.nickymilton.testbasebal3;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.nickymilton.Testbasebal3.MESSAGE";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText1);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
然后是第二个活动DisplayMessageActivity.java。
package com.nickymilton.testbasebal3;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
public class DisplayMessageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
}
最后是主清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nickymilton.testbasebal3"
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=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="@string/title_activity_display_message" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.nickymilton.testbasebal3.MainActivity" />
</activity>
</application>
</manifest>
所以,这就是问题所在。请有人帮忙,谢谢!