Null Exception RelativeLayout
- by theblixguy
I am trying to remove objects from my relative layout and replace the background with another image but I get a java.lang.NullPointerException on this line:
RelativeLayout ths = (RelativeLayout)findViewById(R.layout.activity_main);
Below is my code:
package com.ssrij.qrmag;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize animations
Animation a = new TranslateAnimation(1000,0,0,0);
Animation a1 = new TranslateAnimation(1000,0,0,0);
Animation a2 = new TranslateAnimation(1000,0,0,0);
Animation a3 = new TranslateAnimation(1000,0,0,0);
// Set animation durations (ms)
a.setDuration(1200);
a1.setDuration(1400);
a2.setDuration(1600);
a3.setDuration(1800);
// Get a reference to the objects we want to apply the animation to
final TextView v = (TextView)findViewById(R.id.textView1);
final TextView v1 = (TextView)findViewById(R.id.textView2);
final TextView v2 = (TextView)findViewById(R.id.TextView3);
final Button v3 = (Button)findViewById(R.id.tap_scan);
// Clear existing animations, just in case...
v.clearAnimation();
v1.clearAnimation();
v2.clearAnimation();
v3.clearAnimation();
// Start animating
v.startAnimation(a);
v1.startAnimation(a1);
v2.startAnimation(a2);
v3.startAnimation(a3);
a1.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
v.setVisibility(View.INVISIBLE);
v1.setVisibility(View.INVISIBLE);
v2.setVisibility(View.INVISIBLE);
v3.setVisibility(View.INVISIBLE);
RelativeLayout ths = (RelativeLayout)findViewById(R.layout.activity_main);
ths.setBackgroundResource(R.drawable.blurbg);
}
});
}
public void ScanQr(View v) {
// Open the QR Scan page
Intent a = new Intent(MainActivity.this, ScanActivity.class);
startActivity(a);
}
}
Is there anything that I am doing wrong?