gpt4 book ai didi

java - R 无法解析为 eclipse android 中的变量

转载 作者:行者123 更新时间:2023-12-01 09:58:17 26 4
gpt4 key购买 nike

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>

这是我的java代码

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

}

这是我的代码 R 文件未生成请告诉我错误在哪里以及为什么 R 文件未生成 这是我的 xml 代码 R 文件没有生成,请告诉我错误在哪里,为什么 R 文件没有生成 这是我的 xml 代码 R 文件没有生成,请告诉我错误在哪里,为什么 R 文件没有生成 这是我的 xml 代码 R 文件没有生成,请告诉我错误在哪里以及为什么 R 文件没有生成

最佳答案

你应该尝试清理你的项目!!

关于java - R 无法解析为 eclipse android 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37022318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com