errors please help

+1 srinivas r · September 9, 2015
these are my errors


Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac
C:\Users\vinay\AndroidStudioProjects\Alison\app\src\main\java\com\romala\alison\MainActivity.java
Error:(45, 63) error: method getId in class View cannot be applied to given types;
required: no arguments
found: int
reason: actual and formal argument lists differ in length
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 5.405 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console




main_activity.java
package com.romala.alison;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RelativeLayout;
import android.widget.Button;
import android.graphics.Color;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


RelativeLayout romalasLayout = new RelativeLayout(this);
romalasLayout.setBackgroundColor(Color.BLUE);

//Button
Button redButton = new Button(this);
redButton.setText("Log In");
redButton.setBackgroundColor(Color.RED);
//username input
EditText username = new EditText(this);

redButton.setId(1);
username.setId(2);

RelativeLayout.LayoutParams buttonDetails = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);

RelativeLayout.LayoutParams usernameDetails = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);

//Give rules to position widget

usernameDetails.addRule(RelativeLayout.ABOVE,redButton.getId(1));
usernameDetails.addRule(RelativeLayout.CENTER_HORIZONTAL);
usernameDetails.setMargins(0,0,0,50);

buttonDetails.addRule(RelativeLayout.CENTER_HORIZONTAL);
buttonDetails.addRule(RelativeLayout.CENTER_VERTICAL);




// Add widget to Layout(button is now a child of Layout)
romalasLayout.addView(redButton,buttonDetails);
romalasLayout.addView(username,usernameDetails);

//set this activities contents/display to this view
setContentView(romalasLayout);

}

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




activity_mail.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</RelativeLayout>






please help me what's wrog with this code

Post a Reply

Replies

Oldest  Newest  Rating
0 Ajay Antony · November 21, 2015
usernameDetails.addRule(RelativeLayout.ABOVE,redButton.getId(1)); -here is the error
usernameDetails.addRule(RelativeLayout.ABOVE,redButton.getId()); - remove the 1
  • 1

Java / Android Development

107,254 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator