6 Replies - 1001 Views - Last Post: 16 August 2012 - 05:16 PM

#1 ipratikgoyal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-August 12

id cannot be resolved

Posted 15 August 2012 - 08:46 AM

Hi, I've been trying the following code and getting two errors "R cannot be resolved". I also imported the package android.R; still didn't work, even cleaned and deleted R.java file but no success.

package com.linkifytextdemo;


import java.util.regex.Matcher;
import java.util.regex.Pattern;


import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.text.util.Linkify.MatchFilter;
import android.text.util.Linkify.TransformFilter;
import android.widget.TextView;

public class LinkifyTextDemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_linkify_text_demo);  //error

TextView textView = (TextView)findViewById(R.id.txtSampleTextView);  //error
textView.setText("This is a demo of custom text linkify, developed by @Pratik");

MatchFilter matchFilter = new MatchFilter() {
public final boolean acceptMatch(CharSequence s, int start, int end) {
// you can compare match over here
// return s.toString().equals("@Pratik");
return true;
}
};
TransformFilter transformFilter = new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return "www.google.com";
}
};

Pattern pattern = Pattern.compile("@Bharat");
String scheme = "http://";
Linkify.addLinks(textView, pattern, scheme, matchFilter, transformFilter);
}
}



Is This A Good Question/Topic? 0
  • +

Replies To: id cannot be resolved

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: id cannot be resolved

Posted 15 August 2012 - 09:06 AM

Moved to Android.
Was This Post Helpful? 0
  • +
  • -

#3 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 276
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: id cannot be resolved

Posted 15 August 2012 - 09:49 AM

There is most likely an error in one of your xml files that is preventing R.java from being generated. If I had to guess its probably in one of your layout files! Post your code for your layout file.
Was This Post Helpful? 0
  • +
  • -

#4 ipratikgoyal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-August 12

Re: id cannot be resolved

Posted 15 August 2012 - 09:58 AM

View PostH3R3T1C, on 15 August 2012 - 09:49 AM, said:

There is most likely an error in one of your xml files that is preventing R.java from being generated. If I had to guess its probably in one of your layout files! Post your code for your layout file.


R.java file is present. The error is in R.id.txtSampleTextView cannot be resolved.


<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" >

    <TextView
        android:id="@+id/txtSampleTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/title_activity_linkify_text_demo"
        tools:context=".LinkifyTextDemo" />
    
   
    

</RelativeLayout>


Was This Post Helpful? 0
  • +
  • -

#5 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 276
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: id cannot be resolved

Posted 15 August 2012 - 10:00 AM

try removing tools:context=".LinkifyTextDemo" from your layout file.
Was This Post Helpful? 0
  • +
  • -

#6 ipratikgoyal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-August 12

Re: id cannot be resolved

Posted 16 August 2012 - 05:19 AM

View PostH3R3T1C, on 15 August 2012 - 10:00 AM, said:

try removing tools:context=".LinkifyTextDemo" from your layout file.



Yes, i tried that still no success
Was This Post Helpful? 0
  • +
  • -

#7 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 276
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: id cannot be resolved

Posted 16 August 2012 - 05:16 PM

You need to make sure you import com.linkifytextdemo.R
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1