简单的问题是,为什么会发生这种情况?
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.maxiesnax.gavinisms2.gavinisms2.R;
public class GavinFragment extends Fragment {
;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_gavin, container,
false);
// Inflate the layout for this fragment
return rootView;
final MediaPlayer aahMP = MediaPlayer.create(getActivity(), R.raw.aaah);
Button play_aaah = (Button) getActivity().findViewById(R.id.play_ahhh);
play_aaah.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
aahMP.start();
}
});
}
}这是我的代码片段,其中包含要播放的aah.mp3按钮。错误发生在
(R.id.play_ahhh);特别是在play_ahhh已经定义好的情况下。
<resources>
<string name="app_name">Gavinisms</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_settings">Settings</string>
<string name="play_ahhh">Ahhh"</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>发布于 2017-04-11 09:59:33
在下面一行中,删除文本内的双引号,
<string name="play_ahhh">Ahhh"</string更改为,
<string name="play_ahhh">Ahhh</stringhttps://stackoverflow.com/questions/43335481
复制相似问题