나는 안드로이드 스튜디오를 처음 사용하고 막 첫 번째 앱을 개발하기 시작했고 이전에 애플리케이션을 컴파일 할 수 있었지만 활동을 변경하기 위해 버튼에 코드를 추가하려고 시도했지만 주변을 둘러 보았지만 이유를 알 수 없습니다. ,하지만 실행하려고하면 8 개의 컴파일 오류가 발생하지만 이유를 알 수 없습니다!
내 코드는 다음과 같습니다.
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/btnEnter"
android:layout_gravity="center_horizontal"
android:layout_weight="0.40"
android:textSize="50dp"
android:onClick="onClick"/>
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
다음은 컴파일러 오류를 발생시키는 코드입니다.
Public class MainActivity extends ActionBarActivity {public final static String EXTRA_MESSAGE = "com.example.ben.learning.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.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);
}
버튼 btn = (버튼) findViewById (R.id.btnEnter); btn.btnEnter.setOnClickListener (new View.OnClickListener ()
{
public void onClick (View view){
Intent intent = new Intent
(MainActivity.this, LoginActivity.class);
MainActivity.this.startActivity(intent);
}
);
}
} ...And the errors:
Error:(60, 36) error: expected Error:(60, 37) error: illegal start of type Error:(60, 40) error: ')' expected Error:(60, 45) error: ';' expected Error:(60, 46) error: invalid method declaration; return type required Error:(64, 9) error: illegal start of expression Error:(64, 16) error: illegal start of expression Error:(64, 35) error: ';' expected Error:(70, 6) error: illegal start of type
Any insight would be great, I'm just going in circles trying to figure this out!
Cheers. :)
I changed the location of the button code to the onCreate method to solve the errors.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btnEnter);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent
(MainActivity.this, LoginActivity.class);
MainActivity.this.startActivity(intent);
}
});
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다