-4

This is my java class. I googled it up and it appear that my xml codes have errors, but i just dont know where.

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


    button_pause = (ImageButton) findViewById(R.id.button_pause);
    button_play = (ImageButton) findViewById(R.id.button_play);
    button_refresh = (ImageButton) findViewById(R.id.button_refresh);
    button_replay = (ImageButton) findViewById(R.id.button_replay);
    volControl = (SeekBar)findViewById(R.id.volbar);
    txt_view = (TextView)findViewById(R.id.textView2);

I tried to find the error from my xml codes, but it seems fine to me, can anyone help me please?

My xml codes

      <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:background="@drawable/background"
     tools:context="${packageName}.${activityClass}" >


<TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/volbar"
        android:layout_centerHorizontal="true"
        android:text="Medium Text"
        android:textColor="#FFFFFF"
        android:textAppearance="?android:attr/textAppearanceMedium" />


        <SeekBar
        android:id="@+id/volbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_margin="10dp"
        android:layout_marginBottom="21dp" />


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp">

     <TextView
         android:id="@+id/textView1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"             
         android:layout_alignBottom="@+id/button_play"
         android:layout_alignParentLeft="true"
         android:gravity="center"
         android:scrollHorizontally="true"
         android:text="Android Streaming"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="#ffffff"
         android:textSize="45dp" />

    </LinearLayout>

    <ImageButton
        android:id="@+id/button_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/button_refresh"
        android:layout_toLeftOf="@+id/textView2"            
        android:src="@drawable/play" />

     <ImageButton
         android:id="@+id/button_replay"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignTop="@+id/button_refresh"
         android:layout_centerHorizontal="true"          
         android:src="@drawable/back" />

     <ImageButton
         android:id="@+id/button_pause"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignTop="@+id/button_replay"
         android:layout_toLeftOf="@+id/textView2"             
         android:src="@drawable/pause" />

     <ImageButton
         android:id="@+id/button_refresh"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_above="@+id/textView2"
         android:layout_marginBottom="70dp"
         android:layout_toRightOf="@+id/textView2"            
         android:src="@drawable/refresh" />


        </RelativeLayout>
  • Is there R.java in bin directory of your project ??? – Paras Mittal Jul 29 '14 at 06:12
  • i dont have any R.java project in bin directory @ParasMittal – heyholetsgobaby Jul 29 '14 at 06:14
  • Is there R.java in gen directory of your project? – Aman Singh Jul 29 '14 at 06:16
  • I dont have, maybe i accidentally deleted it, any chance that i can recover @AmanSingh – heyholetsgobaby Jul 29 '14 at 06:19
  • Your xml file seems ok to me.. Try deleting the xml files keeping backup of it. Comment any code that is using it. Build the project and see if the R.java is created in gen folder. – Paras Mittal Jul 29 '14 at 06:19
  • Is appcompat_v7 created? – Aman Singh Jul 29 '14 at 06:20
  • Try to clean and build your project again and please check problem window which show you actual error. – Haresh Chhelana Jul 29 '14 at 06:20
  • You stated you have error in XML. What is the error? There should be indicators for the error (maybe missing drawable... or anything). Also, R file is generated automatically if there is no error in resources. – Andrew T. Jul 29 '14 at 06:20
  • check your import - are you importing android.R ??!? if you do this, your 'lokal' R will not work... – Martin Frank Jul 29 '14 at 06:22
  • Nobody can solve your problem in air. Be specific what exactly your error is. If you are seeing any red mark. please add this in your question also... – Paras Mittal Jul 29 '14 at 06:22
  • Check the tool for indicators of errors. Eclipse and Android Studio should both flag problem areas. I suspect it is likely in your `textView1` definition in the layout as it is attempting to anchor itself to views which are outside of its container. Consider dropping the `LinearLayout` which is the parent of this `TextView`, it is serving no purpose. – Larry Schiefer Jul 29 '14 at 06:24
  • @LarrySchiefer There's no point removing linearLayout. Xml is fine. I have double checked it. The problem lies in some other area. – Paras Mittal Jul 29 '14 at 06:26
  • The LinearLayout is a waste in the overall layout, it serves no purpose as it hosts a single child and that child is set to `fillParent`. While it may seem insignificant, these types of wasteful layouts can cause more processing time and memory and should be removed. The layout parameters for the child are RelativeLayout.LayoutParameters, which is invalid. – Larry Schiefer Jul 29 '14 at 06:30
  • it seems like i dont have any r.java file in gen, i tried to recover it by cleaning the project, it didnt work. should i make a backup and copy paste everything back? – heyholetsgobaby Jul 29 '14 at 06:30
  • @LarrySchiefer I totally agree. But these are performance tips. The guy is not able to generate R.java. And he has no idea from where the error are coming. Event though the layout is waste but it is not preventing the R.java to gets generated. Let wait for the person to try something and tell if there;s actually a problem or he forget to build the project. – Paras Mittal Jul 29 '14 at 06:33
  • It's not just a performance tip - the layout parameter being used for that TextView is invalid. That in and of itself can cause problems with R.java being created. It's a simple change and not hard to make, there should be no issue with making it. While I agree with you that the performance impact is a long term thing to look at, the invalid layout in my opinion is not and should be resolved. It may not be *the* cause of the problem, but it is a problem. – Larry Schiefer Jul 29 '14 at 06:39

2 Answers2

0

Try this:

Project->RightClick->Properties->Android->is Library->Add->appcompat_v7->Ok->Apply->Ok
Aman Singh
  • 370
  • 1
  • 9
0

Here is something yo can try:

1) Project ->properties->Java Build Path->Click the Order And Export Tab and select the Android Version checkbox.

2)Than yo can rebuild the workspace (Properties - > Build Project)

You can check out this answer too : Android - R cannot be resolved to a variable

This worked for me on more than one occasion. Good Luck !

Community
  • 1
  • 1
Alex T
  • 163
  • 1
  • 9