Yuva Raj
Yuva Raj

Reputation: 3881

Defining text view to the corresponding id in android?

Found the solution : Declared textview in the oncreateOptionMenu instead of Oncreate method.

Problem : It generates an Multiple marker error when i define text view for the corresponding id.

TwitterSearchActivity.java

package com.example.twittersearchactivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class TwitterSearchActivity extends Activity {

TextView tweet;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_twitter_search);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.twitter_search, menu);
    return true;
}
tweet=(TextView)findViewById(R.id.tweet_txt);

}

activity_twitter_search.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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TwitterSearchActivity" >

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


<TextView
android:id="@+id/intro_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textStyle="italic"
android:text="@string/intro"
/>

<EditText
    android:id="@+id/search_edit"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:hint="@string/hint"
    android:layout_below="@+id/intro_txt"
    android:padding="10dp"
    android:background="#ffff66"
    android:layout_margin="5dp"
/>

<Button
android:id="@+id/search_btn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/search_label"
android:layout_below="@+id/search_edit"
android:onClick="searchTwitter"
android:layout_margin="5dp"
/>
<ScrollView

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/search_btn">


<TextView
android:id="@+id/tweet_txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:padding="10dp"
android:background="#330000"
android:textColor="#ffffff"
android:layout_margin="5dp"
android:text="@string/placeholder"
android:freezesText="true"
/>
</ScrollView>
</RelativeLayout>

Error

Multiple markers at this line
- Syntax error on token ".", ... expected
- Syntax error, insert ";" to complete FieldDeclaration
- Syntax error on token "tweet", VariableDeclaratorId expected after this token
- Return type for the method is missing
- Syntax error, insert "}" to complete ClassBody

Upvotes: 0

Views: 344

Answers (2)

Opiatefuchs
Opiatefuchs

Reputation: 9870

Your Button and Your ScrollView got the same id : search_btn. Don´t know if this is the issue for Your problem, but should be fixed

Upvotes: 0

Ken Wolf
Ken Wolf

Reputation: 23269

Put

tweet=(TextView)findViewById(R.id.tweet_txt);

within your onCreate() method.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_twitter_search);
    tweet=(TextView)findViewById(R.id.tweet_txt);
}

Upvotes: 2

Related Questions