0
This is my xml code R file is not generating please tell me where is the error and why R file is not generating

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#333333"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<TextView
    android:id="@+id/SongName"
    android:layout_width="wrap_content"
    android:text="@string/songName"
    android:layout_height="wrap_content"/>


<ImageView
    android:id="@+id/s_mp3Image"
    android:layout_width="match_parent"
    android:layout_height="200dp"
     android:padding="30dp"
     android:contentDescription="@string/music"
    android:src="@drawable/music"
    android:background="#ffffff"
    android:layout_margin="30dp" />

<TextView
   android:id="@+id/songDuration"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/songDuration"
    android:layout_gravity="center"/>

<SeekBar
    android:id="@+id/s_seekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="30dp"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/s_media_rew"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="14dp"
        android:onClick="rewind"
        android:contentDescription="@string/ic_media_rew"
        android:src="@android:drawable/ic_media_rew" />

    <ImageButton
        android:id="@+id/s_media_pause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="14dp"
        android:onClick="pause"
        android:contentDescription="@string/media_pause"
        android:src="@android:drawable/ic_media_pause" />

    <ImageButton
        android:id="@+id/s_media_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="14dp"
        android:onClick="play"
        android:contentDescription="@string/ic_media_play"
        android:src="@android:drawable/ic_media_play" />

    <ImageButton
        android:id="@+id/s_media_ff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="14dp"
        android:onClick="forward"
        android:contentDescription="@string/ic_media_ff"
        android:src="@android:drawable/ic_media_ff" />
</LinearLayout>

and this is my java code

package com.example.androidmediaplayer;


import java.util.concurrent.TimeUnit;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.VideoView;

public class  MainActivity extends Activity {

private MediaPlayer mediaPlayer;
public TextView songName, duration;
private double timeElapsed = 0, finalTime = 0;
private int forwardTime = 2000, backwardTime = 2000;
private Handler durationHandler = new Handler();
private SeekBar seekbar;


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

    //set the layout of the Activity
    setContentView(R.layout.activity_list_item);   //here R file has problem

    //initialize views
    initializeViews();
}

public void initializeViews(){
    songName=(TextView)findViewById(R.id.SongName);    //here R file has problem
    mediaPlayer = MediaPlayer.create(this, R.raw.sample);  //here
       finalTime = mediaPlayer.getDuration();
       duration = (TextView) findViewById(R.id.songDuration);  //here
       seekbar = (SeekBar) findViewById(R.id.s_seekBar); //here
       songName.setText("Sample_Song.mp3");
                 seekbar.setMax((int) finalTime);
    seekbar.setClickable(false);
}

// play mp3 song
public void play(View view) {
    mediaPlayer = new MediaPlayer();
    mediaPlayer.start();
    timeElapsed = mediaPlayer.getCurrentPosition();
    seekbar.setProgress((int) timeElapsed);
    durationHandler.postDelayed(updateSeekBarTime, 100);
}

//handler to change seekBarTime
@SuppressLint("NewApi")
private Runnable updateSeekBarTime = new Runnable() {

    @SuppressLint("NewApi")
    public void run() {
        //get current position
        timeElapsed = mediaPlayer.getCurrentPosition();
        //set seekBar progress
        seekbar.setProgress((int) timeElapsed);
        //set time remaining
        double timeRemaining = finalTime - timeElapsed;
                    duration.setText(String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes((long) timeRemaining), TimeUnit.MILLISECONDS.toSeconds((long) timeRemaining) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) timeRemaining))));


        //repeat yourself that again in 100 milliseconds
        durationHandler.postDelayed(this, 100);
    }
};

// pause mp3 song
public void pause(View view) {
    mediaPlayer.pause();
}

// go forward at forwardTime seconds
public void forward(View view) {
    //check if we can go forward at forwardTime seconds before song 
    if ((timeElapsed + forwardTime) <= finalTime) {
        timeElapsed = timeElapsed + forwardTime;

        //seek to the exact second of the track
        mediaPlayer.seekTo((int) timeElapsed);
    }
}

// go backwards at backwardTime seconds
public void rewind(View view) {
    //check if we can go back at backwardTime seconds after song starts
    if ((timeElapsed - backwardTime) > 0) {
        timeElapsed = timeElapsed - backwardTime;

        //seek to the exact second of the track
        mediaPlayer.seekTo((int) timeElapsed);
    }
}

}

This is my code R file is not generating please tell me where is the error and why R file is not generating This is my xml code R file is not generating please tell me where is the error and why R file is not generating This is my xml code R file is not generating please tell me where is the error and why R file is not generating This is my xml code R file is not generating please tell me where is the error and why R file is not generating

Cesar
  • 7
  • 3

2 Answers2

1

You should try cleaning your project !!

varunkr
  • 5,364
  • 11
  • 50
  • 99
0

Try Clean your Project.

OR

Restart Eclipse.

Or

Check with All XML Resources you have used. Is their any missing things in your XML.

This case mostly happens when you have Something wrong with your XML Resources you are using.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58