I am trying to create a test app for a library I am creating. When my library is called, it creates an intent and starts an activity.
intent = new Intent(getApplicationContext(), video_on_load.class);
myLib.this.startActivity(intent);
My program it seems my program is crashing on creating the new Intent. I tried to why this would happen, and I saw that in my app I have to had the activity to the AndroidManafest, so I added the following line to my manifest:
activity android:name="com.example.myLib.video_on_load"></activity>
However my app is still crashing with the message “Unfortunately, TestApp has stopped.” I am unsure how to continue. I am fairly new to android programming, so it may be something simple I missed. Let me know if you need any other information that would be useful in debugging this problem.
My video_on_load class is as follows:
public class video_on_load extends Activity {
private RelativeLayout layout;
private ProgressBar progressBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_on_load);
layout = (RelativeLayout) findViewById(R.id.video_onLoad_layout);
progressBar = (ProgressBar) findViewById(R.id.video_onLoad_progress);
}
Edit:
Relevent LogCat:
12-28 17:53:23.824: E/AndroidRuntime(25042): java.lang.NullPointerException
12-28 17:53:23.824: E/AndroidRuntime(25042): at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
12-28 17:53:23.824: E/AndroidRuntime(25042): at android.content.ComponentName.<init>(ComponentName.java:75)
12-28 17:53:23.824: E/AndroidRuntime(25042): at android.content.Intent.<init>(Intent.java:3491)
video_on_load.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/video_onLoad_layout" >
<ProgressBar android:id="@+id/video_onLoad_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Large" />
</RelativeLayout>
Thank you
Change
into:
As long as you are putting this code somewhere in an Activity, you should be good to go. Note, a An application is has a context, and Application has Activities, and Activities also have a Context. Try reading some documentation on Activities and Context’s to get a better understanding.
Your error message shows that something is null in your call, and that it is related to getApplicationContext(). Good luck