优步noob编程,但已开始尝试使用教程(https://developer.android.com/training/basics/firstapp/starting-activity.html) ,但我已经遇到了几个道路块。我已经尝试过这个应用程序两次,并失败惨败。一个问题是viewGroup
系列一进入,就会一直从代码中消失。第二个问题是应用程序一开始就崩溃。我有第一个活动最初工作,但当按钮被点击时,应用程序会崩溃。我有黑社会干净/重建,但它根本没有帮助。我也尝试了其他基本信息,我可能喜欢编辑或删除代码的某些部分,但他们也没有帮助。所以在这个阶段,任何和所有的帮助将不胜感激!提前致谢!应用程序一直停止 - 无法启动
logcat的错误信息
06-14 20:56:40.335 25791-25791/com.example.jacqueline.myfirstapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jacqueline.myfirstapp, PID: 25791
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jacqueline.myfirstapp/com.example.jacqueline.myfirstapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2711)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2772)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1515)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:6217)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.jacqueline.myfirstapp.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2664)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2772)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1515)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:6217)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
主要活动 -
package com.example.jacqueline.myfirstapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.jacqueline.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**called when user taps the send button*/
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
public class EXTRA_MESSAGE {
}
}
它写 - 你需要指定应用程序的主题。在清单上:android:theme =“@ style/AppTheme” 引起:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代)。 – Dus