2015-01-05 6 views
20

Google에서이 자습서를 따라 Android Studio로 나만의 Android 앱을 만들려고합니다. 나는이 페이지의 4 단계를 수행 할 때하지만이 코드에서Android Studio 오류 : '보기'기호를 해결할 수 없습니다.

public class MainActivity extends ActionBarActivity { 
    /** Called when the user clicks the Send button */ 
    public void sendMessage(View view) { <--- (This line ends up with the error) 
     // Do something in response to button 
    } 

    @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.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(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

무슨 잘못 :

Cannot resolve symbol 'View' 

이 내 코드가 순간에 모습입니다 : http://developer.android.com/training/basics/firstapp/starting-activity.html 안드로이드 Studio는이 오류와 함께 끝 ? 나는 자바에서 경험하지 못했고 다른 질문을 한 후에도 나는 여전히 올바른 해결책을 찾을 수 없었다.

도와 주셔서 감사합니다.

+0

프로젝트를 청소하고 작동하는지 확인 – 2Dee

+0

당신의 수입을 제시해주십시오. –

+0

@ 2dee 수입 물을 어떻게 보여줄 수 있습니까? (이 프로그램/자바 입문) – Stefan

답변

41

View 용 가져 오기 문이 누락 된 것 같습니다. (나는이 질문을 발견 그 이유는) 코드

import android.view.View; 
+0

오류 메시지가 사라졌지만 지금 실행하려고하면 내 콘솔에 7 개의 새로운 오류가 발생합니다. 오류 : (6, 35) 오류 : 기호 클래스를 찾을 수 없습니다. ActionBarActivity 오류 : (13, 29) 오류 : 기호 클래스를 찾을 수 없습니다. 번들 오류 : (20, 40) 오류 : 기호 클래스를 찾을 수 없습니다. 메뉴 오류 : (27, 42) 오류 : 기호 클래스를 찾을 수 없습니다. MenuItem 오류 : (14, 9) 오류 : 기호 변수 super를 찾을 수 없습니다. 오류 : (15, 9) 오류 : 기호 메서드를 찾을 수 없습니다. 오류 : (12, 5) 오류 : 메서드가 오버 헤드가 없거나 상위 유형의 메서드를 구현하지 않습니다. – Stefan

+0

은 필요한 클래스를 가져옵니다. android studio에서 Ctrl + Alt + O를 눌러 클래스를 가져올 수 있습니다. – BeingMIAkashs

+0

Ctrl + Alt + O는 "실행"버튼으로 선택할 수있는 2 개의 파일 디렉토리가있는 팝업을 제공합니다. 실행 버튼을 눌렀을 때 뭔가하는 것처럼 보이지 않습니까? – Stefan

3

나도 같은 튜토리얼을하고 같은 문제로 실행하고있는 다음 가져 오기를 추가합니다.

나는 그들이 "텐트를 구축"이라는 다음 단락에서이 문제를 설명 참조 :

Android Studio will display Cannot resolve symbol errors because this code references classes that are not imported. You can solve some of these with Android Studio's "import class" functionality by pressing Alt + Enter (or Option + Return on Mac). Your imports should end up as the following:

import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText;

* https://developer.android.com/training/basics/firstapp/starting-activity.html#BuildIntent

관련 문제