I am a beginner with android, so bear my lack of knowledge
I am working on a project, which has been working fine, when after few small changes it started giving me a RuntimeException unable to instantiate activity ComponentInfo{com.id11298775.exercise5/com.id11298775.excercise5.MainActivity}: java.lang.NullPointerException
. I have reverted the small changes, which were in an adapter but still I cannot run the app.
Here is my catLog:
I have tried to figure out what is wrong with my main activity for quite a long time but to me everything seems fine, so I guess I am missing something
This is my MainActivity
class:
package com.id11298775.exercise5;
// import statements are here
public class MainActivity extends Activity {
private final String URI = getString(R.string.URI);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the subject name
EditText subjectName = (EditText) findViewById(R.id.activity_main_subjectname_et);
// associate editText with the context menu
subjectName.setOnCreateContextMenuListener(this);
}
/**
* Inflate the menu this adds items to the action bar
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/**
* code that executes according to the menu item that is clicked
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// click help
case R.id.help:
help();
return true;
// click exit
case R.id.exit:
finish();
default:
return super.onOptionsItemSelected(item);
}
}
/**
* when help is clicked this method will display a page related to the
* subject number that is entered If no subject name is entered display the
* general page of subjects of the handbook
*/
public void help() {
EditText subjectNumber = (EditText) findViewById(R.id.activity_main_subjectnumber_et);
String number = subjectNumber.getText().toString();
String url = URI + number;
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
/**
* Inflate the context menu
*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
/**
* code that executes according to the context menu item that is selected
*/
@Override
public boolean onContextItemSelected(MenuItem item) {
EditText nameEd = (EditText) findViewById(R.id.activity_main_subjectname_et);
switch (item.getItemId()) {
// capitalize is selected
case R.id.contextmenu_capitalize:
String subjectName = nameEd.getText().toString();
String upperCase = subjectName.toUpperCase();
nameEd.setText(upperCase);
return true;
// clear is selected
case R.id.contextmenu_clear:
nameEd.setText("");
return true;
default:
return super.onContextItemSelected(item);
}
}
/**
* methdo called when showList button is clicked
* @param v
*/
public void showListButtonClicked(View v) {
Intent intent = new Intent(MainActivity.this, SubjectList.class);
startActivity(intent);
}
}
and this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.id11298775.exercise5"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.id11298775.exercise5.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.id11298775.exercise5.SubjectList"></activity>
</application>
</manifest>
Anybody is keen to help me please? Thank you for sharing your knowledge..