gpt4 book ai didi

java - super.onCreate(savedInstanceState) 错误

转载 作者:行者123 更新时间:2023-11-30 08:54:13 25 4
gpt4 key购买 nike

我为我们的学校项目启动了一个应用程序,当我快完成时,我在 genymotion 模拟器上执行了该程序并输入了以下代码:

package com.example.user.timetableapp;

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

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


public class MainActivity extends ActionBarActivity {

Button btn1,btn2,btn3;
boolean f;
Intent go;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
f=fileExistance("day1.txt");
String text="";
String s;

btn1= (Button) findViewById(R.id.btn1);
btn2= (Button) findViewById(R.id.btn2);
btn3= (Button) findViewById(R.id.btn3);
if(f==false)
for(int i=1;i<7;i++) {
try {
s="day"+i+".txt";
FileOutputStream fos = openFileOutput(s, MODE_PRIVATE);
try {
fos.write(text.getBytes());
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
public boolean fileExistance(String fname){
File file = getBaseContext().getFileStreamPath(fname);
return file.exists();
}

public void go(View v){
go=new Intent(this,ChooseDay.class);
startActivity(go);
}
public void credits(View v){
go=new Intent(this,Credits.class);
startActivity(go);
}

public void howto(View v){
go=new Intent(this,Instructions.class);
startActivity(go);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.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();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

}

这是错误:

04-08 09:38:02.561    1724-1724/com.example.user.timetableapp I/art﹕ Late-enabling -Xcheck:jni
04-08 09:38:02.871 1724-1724/com.example.user.timetableapp D/AndroidRuntime﹕ Shutting down VM
04-08 09:38:02.874 1724-1724/com.example.user.timetableapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.user.timetableapp, PID: 1724
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.timetableapp/com.example.user.timetableapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.example.user.timetableapp.MainActivity.onCreate(MainActivity.java:27)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

可能的解决方案是什么?我是初学者,所以我不明白这些错误是什么意思。另外,为什么android studio认为我手机的API是19时是1?我也可以解决这个问题吗?

最佳答案

您正在尝试使用它找不到的主题。您可以使用以下行将其添加到您的 Android Manifest 文件中。

android:theme="@style/Theme.AppCompat.Light"

关于java - super.onCreate(savedInstanceState) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29516994/

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