gpt4 book ai didi

Android - 单击图像按钮时崩溃

转载 作者:行者123 更新时间:2023-12-02 07:04:55 24 4
gpt4 key购买 nike

当我单击图像按钮时,我的应用程序崩溃了。它发生在模拟器和真实手机上。我用这里和其他一些论坛的一些线程检查了我的代码,但我找不到错误。我很高兴有任何解决方案!

MainActivity.class

public class MainActivity extends Activity {

public static final String PREFS_NAME = "MyPrefsFile";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

addListenerOnButton1();
addListenerOnButton2();
addListenerOnButton3();
addListenerOnButton4();
addListenerOnButton5();
addListenerOnButton6();
addListenerOnButton7();

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean dialogShown = settings.getBoolean("dialogShown", false);

if (!dialogShown) {
// AlertDialog code here
new AlertDialog.Builder(this).setTitle(R.string.alter_title).setMessage(R.string.alter_content).setNeutralButton(R.string.alter_button, null).show();


SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("dialogShown", true);
editor.commit();

}
}

public void addListenerOnButton1() {

ImageButton imgbutton1 = (ImageButton) findViewById(R.id.imageButton1);
imgbutton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

String url = "http://www.arcig.cz/bakalari/suplov.htm";

Intent myIntent = new Intent(MainActivity.this, WebviewActivity.class);
myIntent.putExtra("url", url);
startActivity(myIntent);
}
});

}

public void addListenerOnButton2() {

ImageButton imgbutton2 = (ImageButton) findViewById(R.id.imageButton2);
imgbutton2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

String url = "http://www.arcig.cz/bakalari/rozvrh.htm";

Intent myIntent = new Intent(MainActivity.this, WebviewActivity.class);
myIntent.putExtra("url", url);
startActivity(myIntent);
}
});
}

public void addListenerOnButton3() {

ImageButton imgbutton3 = (ImageButton) findViewById(R.id.imageButton3);
imgbutton3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

String url = "http://www.arcig.cz/bakaweb/login.aspx";

Intent myIntent = new Intent(MainActivity.this, WebviewActivity.class);
myIntent.putExtra("url", url);
startActivity(myIntent);
}
});
}

public void addListenerOnButton4() {

ImageButton imgbutton4 = (ImageButton) findViewById(R.id.imageButton4);
imgbutton4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

String url = "https://www.arcig.cz/roundcube/";

Intent myIntent = new Intent(MainActivity.this, WebviewActivity.class);
myIntent.putExtra("url", url);
startActivity(myIntent);
}
});
}

public void addListenerOnButton5() {

ImageButton imgbutton5 = (ImageButton) findViewById(R.id.imageButton5);
imgbutton5.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

String url = "http://www.arcig.cz/modules.php?op=modload&name=Web_Links&file=index&req=visit&lid=58";

Intent myIntent = new Intent(MainActivity.this, WebviewActivity.class);
myIntent.putExtra("url", url);
startActivity(myIntent);
}
});
}

public void addListenerOnButton6() {

ImageButton imgbutton6 = (ImageButton) findViewById(R.id.imageButton6);
imgbutton6.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

String url = "http://strav.nasejidelna.cz/0082/faces/login.jsp";

Intent myIntent = new Intent(MainActivity.this, WebviewActivity.class);
myIntent.putExtra("url", url);
startActivity(myIntent);
}
});
}

public void addListenerOnButton7() {

ImageButton imgButton7 = (ImageButton) findViewById(R.id.imageButton7);
imgButton7.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {

Intent myIntent = new Intent(MainActivity.this, HelpActivity.class);
MainActivity.this.startActivity(myIntent);

}

});

}

}

HelpActivity.class

public class HelpActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);

addListenerOnButtonHelp();

}

public void addListenerOnButtonHelp() {

Button buttonhelp = (Button) findViewById(R.id.buttonback);
buttonhelp.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {

Intent myIntent = new Intent(HelpActivity.this, MainActivity.class);
HelpActivity.this.startActivity(myIntent);

}

});
}

}

LogCat日志

09-08 21:05:48.173: E/AndroidRuntime(9781): FATAL EXCEPTION: main
09-08 21:05:48.173: E/AndroidRuntime(9781): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tona.arcig/com.tona.arcig.HelpActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.ActivityThread.access$600(ActivityThread.java:156)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.os.Looper.loop(Looper.java:153)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.ActivityThread.main(ActivityThread.java:5297)
09-08 21:05:48.173: E/AndroidRuntime(9781): at java.lang.reflect.Method.invokeNative(Native Method)
09-08 21:05:48.173: E/AndroidRuntime(9781): at java.lang.reflect.Method.invoke(Method.java:511)
09-08 21:05:48.173: E/AndroidRuntime(9781): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
09-08 21:05:48.173: E/AndroidRuntime(9781): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-08 21:05:48.173: E/AndroidRuntime(9781): at dalvik.system.NativeStart.main(Native Method)
09-08 21:05:48.173: E/AndroidRuntime(9781): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
09-08 21:05:48.173: E/AndroidRuntime(9781): at com.tona.arcig.HelpActivity.onCreate(HelpActivity.java:14)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.Activity.performCreate(Activity.java:5262)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
09-08 21:05:48.173: E/AndroidRuntime(9781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
09-08 21:05:48.173: E/AndroidRuntime(9781): ... 11 more
09-08 21:05:48.951: D/dalvikvm(9781): threadid=11: interp stack at 0x5ebab000

请帮忙。抱歉英语不好,我来自捷克代表。谢谢

最佳答案

线索就在 LogCat 输出中:

由以下原因引起:java.lang.IllegalStateException:您需要在此 Activity 中使用 Theme.AppCompat 主题(或后代主题)。

因此,对于从 ActionBarActivity 派生的 HelpActivity,您需要使用 Theme.AppCompat。

请阅读此处 - https://developer.android.com/training/basics/actionbar/styling.html 。打开你的Android Manifest,找到HelpActivity,添加android:theme="@android:style/Theme.AppCompat"表示深色主题,“Theme.AppCompat.Light”表示浅色主题。

关于Android - 单击图像按钮时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25731406/

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