'cannot find symbol ActionBarActivity' following Android Development Tutorial?

前端 未结 2 1962
名媛妹妹
名媛妹妹 2021-01-15 05:43

So I am following this tutorial, using Sublime as a text editor and compiling everything from console.

All was working good, but when we came to the part where you

2条回答
  •  没有蜡笔的小新
    2021-01-15 06:13

    If you use Eclipse to add in DisplayMessageActivity.java then it derives from ActionBarActivity and adds in all the support code related to that for you.

    However if you are following the tutorial using commandline tools, then the ActionBarActivity stuff is not set up yet. They get to that in the next part of the tutorial.

    Instead, you can use the following code for DisplayMessageActivity.java:

    package com.example.yourname;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.content.Intent;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class DisplayMessageActivity extends Activity {
    
        @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);
    
            setContentView(textView);
    
        }
    }
    

    You will also need to add into MainActivity.java when you are doing the step "Start the Second Activity":

    import android.view.View;
    

提交回复
热议问题