gpt4 book ai didi

Android应用程序不断崩溃

转载 作者:行者123 更新时间:2023-12-03 17:29:23 27 4
gpt4 key购买 nike

我是初学者,我正在使用treehouse来学习android开发。在我制作的两个应用程序中,从今天开始都崩溃了。我不确定为什么会发生这种情况,因为我一直在遵循他们的所有指示。

主要的:

package com.example.personalityidentifier;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

private Personality mPersonality = new Personality();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewById(R.id.button1);

getAnswerButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
String answer = mPersonality.getAPersonality();

// Update label with dynamic answer
answerLabel.setText(answer);
}
});
}


@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);
}
}

安卓 list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.personalityidentifier"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.personalityidentifier.MainActivity"
android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>

日志猫:
07-10 10:47:22.870: D/AndroidRuntime(886): Shutting down VM
07-10 10:47:22.870: W/dalvikvm(886): threadid=1: thread exiting with uncaught exception (group=0xb1a78ba8)
07-10 10:47:22.940: E/AndroidRuntime(886): FATAL EXCEPTION: main
07-10 10:47:22.940: E/AndroidRuntime(886): Process: com.example.personalityidentifier, PID: 886
07-10 10:47:22.940: E/AndroidRuntime(886): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.personalityidentifier/com.example.personalityidentifier.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.os.Handler.dispatchMessage(Handler.java:102)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.os.Looper.loop(Looper.java:136)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-10 10:47:22.940: E/AndroidRuntime(886): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 10:47:22.940: E/AndroidRuntime(886): at java.lang.reflect.Method.invoke(Method.java:515)
07-10 10:47:22.940: E/AndroidRuntime(886): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-10 10:47:22.940: E/AndroidRuntime(886): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-10 10:47:22.940: E/AndroidRuntime(886): at dalvik.system.NativeStart.main(Native Method)
07-10 10:47:22.940: E/AndroidRuntime(886): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
07-10 10:47:22.940: E/AndroidRuntime(886): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
07-10 10:47:22.940: E/AndroidRuntime(886): at com.example.personalityidentifier.MainActivity.onCreate(MainActivity.java:16)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.Activity.performCreate(Activity.java:5231)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-10 10:47:22.940: E/AndroidRuntime(886): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-10 10:47:22.940: E/AndroidRuntime(886): ... 11 more
07-10 10:47:26.170: I/Process(886): Sending signal. PID: 886 SIG: 9

最佳答案

在黑暗中拍摄,删除 TextView 中的 Final。看看这是否有效。

关于Android应用程序不断崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24669050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com