Java – symbol class intent not found

I am a novice in Android development and Java and XML coding

But I'm learning this tutorial:

http://www.steventrigg.com/activities-and-the-action-bar-create-an-alarm-clock-in-android-tutorial-part-1/#comment -296

Then I encountered this error when using intent The word "intent" under the switch turns red and the error "cannot find symbol class intent" appears

Can someone explain to me what happened and how to solve the problem?

This is me at alarmlistactivity The last part of the code under Java

@Override

public boolean onOptionsItemSelected(MenuItem item) {

   int id = item.getItemId();
   if (id == R.id.action_settings) {
       return true;
   }

   switch (item.getItemId()) {
       case R.id.action_add_new_alarm: {
           Intent intent = new Intent(this,AlarmDetailsActivity.class);

            startActivity(intent);
            break;
        }
    }
    return super.onOptionsItemSelected(item);
}

Solution

Look at your alarmlistactivity again and check the import statement at the top and make sure it contains the following lines:

import android.content.Intent;

If you're going to use anything that doesn't belong to Java Lang package's pre - existing classes, which must usually be imported For example, Android intent is a pre built class written by the Android development team that allows notification of other applications / activities If you want to use intent, you must import a package containing intent

When you write a new intent (), the compiler will see that you are requesting to construct a new object, but because the object is in Java Lang package, so you need to know where to find the blueprint object to build the object The import statement is the location of the blueprint

I looked at the tutorial, and in the way of an experienced programmer, the author seems to have covered up some basic but still important things, such as the import statement that makes his sample code work

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>