第一个Android App错误

时间:2014-09-24 23:28:03

标签: android runtime-error

我正在研究Android教程,当我去运行我的程序时,它给了我一个错误,说"不幸的是,First App已停止"。我无法弄清楚原因。

这是我的错误logcat:

09-24 23:17:04.970: E/libEGL(49): called unimplemented OpenGL ES API
09-24 23:17:04.970: E/libEGL(49): called unimplemented OpenGL ES API
09-24 23:17:04.970: E/libEGL(49): called unimplemented OpenGL ES API
09-24 23:17:04.970: E/libEGL(49): called unimplemented OpenGL ES API
09-24 23:17:04.970: E/SurfaceFlinger(49): glCheckFramebufferStatusOES error 1189403997
09-24 23:17:04.970: E/SurfaceFlinger(49): got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot
09-24 23:17:04.980: E/libEGL(49): called unimplemented OpenGL ES API
09-24 23:17:04.980: E/libEGL(49): called unimplemented OpenGL ES API
09-24 23:17:05.280: E/AndroidRuntime(691): FATAL EXCEPTION: main
09-24 23:17:05.280: E/AndroidRuntime(691): Process: com.example.myfirstapp, PID: 691
09-24 23:17:05.280: E/AndroidRuntime(691): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.os.Handler.dispatchMessage(Handler.java:102)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.os.Looper.loop(Looper.java:136)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.ActivityThread.main(ActivityThread.java:5026)
09-24 23:17:05.280: E/AndroidRuntime(691):  at java.lang.reflect.Method.invokeNative(Native Method)
09-24 23:17:05.280: E/AndroidRuntime(691):  at java.lang.reflect.Method.invoke(Method.java:515)
09-24 23:17:05.280: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
09-24 23:17:05.280: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-24 23:17:05.280: E/AndroidRuntime(691):  at dalvik.system.NativeStart.main(Native Method)
09-24 23:17:05.280: E/AndroidRuntime(691): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
09-24 23:17:05.280: E/AndroidRuntime(691):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
09-24 23:17:05.280: E/AndroidRuntime(691):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
09-24 23:17:05.280: E/AndroidRuntime(691):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
09-24 23:17:05.280: E/AndroidRuntime(691):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.Activity.setContentView(Activity.java:1930)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
09-24 23:17:05.280: E/AndroidRuntime(691):  at com.example.myfirstapp.MainActivity.onCreate(MainActivity.java:14)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.Activity.performCreate(Activity.java:5242)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-24 23:17:05.280: E/AndroidRuntime(691):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
09-24 23:17:05.280: E/AndroidRuntime(691):  ... 11 more
09-24 23:17:53.570: E/RecyclerView(451): No adapter attached; skipping layout
09-24 23:17:54.710: E/libsuspend(335): Error writing to /sys/power/wakeup_count: Invalid argument
: E/(): Device disconnected

这是我的主要活动:

package com.example.myfirstapp;

import android.content.Intent;
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.EditText;

public class MainActivity extends ActionBarActivity {
  public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";@
  Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  }


  @
  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);
    }
    /** Called when the user clicks the Send button */
  public void sendMessage(View view) {
    Intent intent = new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
  }
}

这是DisplayMessageActivity:

package com.example.myfirstapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.widget.TextView;

public class DisplayMessageActivity extends ActionBarActivity {

    @Override
    protected 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);

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

不确定是否还需要其他任何东西。

1 个答案:

答案 0 :(得分:0)

您可以在日志中看到错误是:

09-24 23:17:05.280: E/AndroidRuntime(691): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: android.util.AndroidRuntimeException: **You cannot combine swipe dismissal and the action bar.**

您无法将滑动解除与操作栏结合使用。

消除其中一项功能,它将会运行。

干杯!