Reputation: 65
New to Android Dev and this site. I created an app and basics were working. I added a sound button and it worked. I created a new app for earlier version of android and accidently dragged my Main Activity file to the new app instead of copying it. When I dragged it back, it said my imports were not used. Now the sound, which I had to do an 'import' statement for, does not work. Heres the code.
package com.offthericta.wiferemote;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.offthericta.wiferemote.R;
import com.offthericta.wiferemote.R.id;
import com.offthericta.wiferemote.R.layout;
import com.offthericta.wiferemote.R.menu;
import com.offthericta.wiferemote.R.raw;
public class MainActivity extends Activity {
private static final String TAG = "MyActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v(TAG, "Initializing sounds...");
final MediaPlayer mp = MediaPlayer.create(this, R.raw.blah);
Button Button03 = (Button)this.findViewById(R.id.Button03);
Button03.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "Playing sound...");
mp.start();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View v){}
public void disclaimerBTN (View v){
Toast.makeText(this, "FAILED: The remote object is not responding to this command",Toast.LENGTH_LONG).show();
}
}
Upvotes: 1
Views: 65
Reputation: 109247
I think your main concern is these statements..
import com.offthericta.wiferemote.R;
import com.offthericta.wiferemote.R.id;
import com.offthericta.wiferemote.R.layout;
import com.offthericta.wiferemote.R.menu;
import com.offthericta.wiferemote.R.raw;
You are accessing other Application Package's resources in your current Application Package.
Just Use your current Application's Resource File.
Remove above import statements add necessary resources in your current project's resource directory. And compile and Run again..
Upvotes: 2