i'm just programming a password manager but every time I run it, it crashed in cause of NullPointerException. I checked the code but i'm a new developer. Someone here who knows why? :(
Code of MainActivity.java:
package de.lennartschoch.passwordmanager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
Button login;
EditText masterpassfield;
static String masterpass;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login = (Button) findViewById(R.id.login);
masterpass = "";
masterpassfield = (EditText) findViewById(R.id.masterpass);
if(masterpass.equals("")) {
Intent intent = new Intent(this,NewMasterpass.class);
startActivity(intent);
return;
}
login.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
if(masterpassfield.getText().toString().equals(masterpass)) {
Intent success = new Intent(view.getContext(), Passwords.class);
startActivityForResult(success, 0);
}
}});
}
#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;
}
}
Code of NewMasterpass.java:
package de.lennartschoch.passwordmanager;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class NewMasterpass extends Activity {
EditText masterpasscreate;
EditText repeat;
Button finish;
TextView mistake;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_masterpass);
masterpasscreate = (EditText) findViewById(R.id.masterpasscreate);
repeat = (EditText) findViewById(R.id.repeatcreate);
finish = (Button) findViewById(R.id.finish);
mistake = (TextView) findViewById(R.id.mistake);
finish.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
if(!masterpasscreate.getText().toString().equals(repeat.getText().toString())) {
mistake.setText("The passwords are different.");
mistake.setTextColor(Color.RED);
}
else if(masterpasscreate.getText().toString().equals("") || repeat.getText().toString().equals("")) {
mistake.setText("Both textfields must be filled in");
mistake.setTextColor(Color.RED);
}
else {
MainActivity.masterpass = masterpasscreate.getText().toString();
Intent myIntent = new Intent(view.getContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
}
}});
}
}
LogCat error:
01-20 17:17:52.629: D/AndroidRuntime(561): Shutting down VM
01-20 17:17:52.629: W/dalvikvm(561): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
01-20 17:17:52.639: E/AndroidRuntime(561): FATAL EXCEPTION: main
01-20 17:17:52.639: E/AndroidRuntime(561): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.MainActivit y}: java.lang.NullPointerException
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.ActivityThread.access$600(ActivityThread.java:122)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.os.Looper.loop(Looper.java:137)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-20 17:17:52.639: E/AndroidRuntime(561): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 17:17:52.639: E/AndroidRuntime(561): at java.lang.reflect.Method.invoke(Method.java:511)
01-20 17:17:52.639: E/AndroidRuntime(561): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-20 17:17:52.639: E/AndroidRuntime(561): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-20 17:17:52.639: E/AndroidRuntime(561): at dalvik.system.NativeStart.main(Native Method)
01-20 17:17:52.639: E/AndroidRuntime(561): Caused by: java.lang.NullPointerException
01-20 17:17:52.639: E/AndroidRuntime(561): at de.lennartschoch.passwordmanager.MainActivity.onCreate(MainActivity.java:26)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.Activity.performCreate(Activity.java:4465)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-20 17:17:52.639: E/AndroidRuntime(561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
01-20 17:17:52.639: E/AndroidRuntime(561): ... 11 more
01-20 17:17:57.129: I/Process(561): Sending signal. PID: 561 SIG: 9
01-20 17:21:37.499: D/AndroidRuntime(608): Shutting down VM
01-20 17:21:37.499: W/dalvikvm(608): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
01-20 17:21:37.511: E/AndroidRuntime(608): FATAL EXCEPTION: main
01-20 17:21:37.511: E/AndroidRuntime(608): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.NewMasterpass}; have you declared this activity in your AndroidManifest.xml?
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.ActivityThread.access$600(ActivityThread.java:122)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.os.Looper.loop(Looper.java:137)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-20 17:21:37.511: E/AndroidRuntime(608): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 17:21:37.511: E/AndroidRuntime(608): at java.lang.reflect.Method.invoke(Method.java:511)
01-20 17:21:37.511: E/AndroidRuntime(608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-20 17:21:37.511: E/AndroidRuntime(608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-20 17:21:37.511: E/AndroidRuntime(608): at dalvik.system.NativeStart.main(Native Method)
01-20 17:21:37.511: E/AndroidRuntime(608): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.NewMasterpass}; have you declared this activity in your AndroidManifest.xml?
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.Activity.startActivityForResult(Activity.java:3190)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.Activity.startActivity(Activity.java:3297)
01-20 17:21:37.511: E/AndroidRuntime(608): at de.lennartschoch.passwordmanager.MainActivity.onCreate(MainActivity.java:30)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.Activity.performCreate(Activity.java:4465)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-20 17:21:37.511: E/AndroidRuntime(608): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
01-20 17:21:37.511: E/AndroidRuntime(608): ... 11 more
01-20 17:22:30.769: D/AndroidRuntime(655): Shutting down VM
01-20 17:22:30.769: W/dalvikvm(655): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
01-20 17:22:30.779: E/AndroidRuntime(655): FATAL EXCEPTION: main
01-20 17:22:30.779: E/AndroidRuntime(655): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.NewMasterpass}; have you declared this activity in your AndroidManifest.xml?
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.ActivityThread.access$600(ActivityThread.java:122)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.os.Looper.loop(Looper.java:137)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-20 17:22:30.779: E/AndroidRuntime(655): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 17:22:30.779: E/AndroidRuntime(655): at java.lang.reflect.Method.invoke(Method.java:511)
01-20 17:22:30.779: E/AndroidRuntime(655): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-20 17:22:30.779: E/AndroidRuntime(655): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-20 17:22:30.779: E/AndroidRuntime(655): at dalvik.system.NativeStart.main(Native Method)
01-20 17:22:30.779: E/AndroidRuntime(655): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.NewMasterpass}; have you declared this activity in your AndroidManifest.xml?
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.Activity.startActivityForResult(Activity.java:3190)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.Activity.startActivity(Activity.java:3297)
01-20 17:22:30.779: E/AndroidRuntime(655): at de.lennartschoch.passwordmanager.MainActivity.onCreate(MainActivity.java:30)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.Activity.performCreate(Activity.java:4465)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-20 17:22:30.779: E/AndroidRuntime(655): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
01-20 17:22:30.779: E/AndroidRuntime(655): ... 11 more
01-20 17:22:33.180: I/Process(655): Sending signal. PID: 655 SIG: 9
It asks:
01-20 17:22:30.779: E/AndroidRuntime(655): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {de.lennartschoch.passwordmanager/de.lennartschoch.passwordmanager.NewMasterpass};
have you declared this activity in your AndroidManifest.xml?
Have you?
Declare the NewMasterPass activity in your manifest xml as clearly mentioned in the logcat!
Try to add this to your AndroidManifest.xml
<activity android:name="de.lennartschoch.passwordmanager.NewMasterpass" />
Related
I had tired to build an android application and I face a problem.
I post my java code, xml and error.
Can someone teach me why it happened and how to solve it? Thanks!
This is what the problem that I face...
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: FATAL EXCEPTION: main
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: Process: com.onemap.activities, PID: 21798
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.onemap.activities/com.onemap.activities.OneMap}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.TextView
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:156)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.os.Looper.loop(Looper.java:157)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5872)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.TextView
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:620)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at com.onemap.fragments.MainMenu.onCreateView(MainMenu.java:88)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1965)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1047)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1237)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1339)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2295)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:375)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:1997)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at com.onemap.activities.OneMap.onCreate(OneMap.java:58)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5312)
10-27 16:35:22.488 21798-21798/com.onemap.activities E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
Here is my java code and xml
OneMap.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.onemap);
AppUtilities.init(this);
pomPref = getSharedPreferences(POM_PREF, MODE_PRIVATE);
pomEditor = pomPref.edit();
favDB = new FavouritesDBHandler(AppUtilities.getContext());
this.mMapView = (MapView) findViewById(R.id.mMapView);
this.mMapView.setOnStatusChangedListener(OneMapStatusListener.getInstance());
this.scrollView = (SlidingMenu) findViewById(R.id.mScrollView);
View mainContent = this.scrollView.getMainContent();
OnClickListener clickListener = getClickListener();
OnLongClickListener longClickListener = getLongClickListener();
mainContent.findViewById(R.id.mScreenToggle).setOnClickListener(clickListener);
JewelContainer jewelContainer = (JewelContainer) mainContent.findViewById(R.id.jewel_container);
jewelContainer.setOnClickListener(clickListener);
jewelContainer.setOnLongClickListener(longClickListener);
this.mMapView.setOnSingleTapListener(getSingleTapListener());
this.mMapView.setOnLongPressListener(getLongPressListener());
this.mMapView.setCalloutClickListener(getClickListener());
this.mMapView.getCallout().setMaxWidth(550);
}
MainMenu.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.menu_main, container, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.arrowUp = (ImageView) view.findViewById(R.id.iv_arrow_up);
viewHolder.arrowDown = (ImageView) view.findViewById(R.id.iv_arrow_down);
ListView menuList = (ListView) view.findViewById(R.id.menu_list);
menuList.setOnItemClickListener(this);
menuList.setOnScrollListener(this);
menuList.setTag(viewHolder);
MenuItem[] arrayMenuItem = new MenuItem[5];
arrayMenuItem[0] = new MenuItem(0, "Services", R.mipmap.ic_menu_title_service);
arrayMenuItem[1] = new MenuItem(1, getString(R.string.get_directions), R.mipmap.ic_directions);
arrayMenuItem[2] = new MenuItem(2, getString(R.string.amenities), R.mipmap.ic_amenities);
arrayMenuItem[3] = new MenuItem(3, "Others", R.mipmap.ic_menu_title_other);
arrayMenuItem[4] = new MenuItem(4, getString(R.string.about), R.mipmap.ic_about);
menuList.setAdapter(new MenuAdapter(getActivity(), arrayMenuItem));
return view;
}
onemap.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.onemap.widgets.MapView
xmlns:callout="http://schemas.android.com/apk/res/com.onemap.activities"
android:id="#id/mMapView"
calloutStyle="#xml/callout_style"
initExtent="29454.233386372267 39831.55546813806 30038.01821247406 40758.313879574656"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
callout:layout="#layout/callout" />
<ProgressBar
android:id="#id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
<com.onemap.widgets.SlidingMenu
xmlns:menu="http://schemas.android.com/apk/res/com.onemap.activities"
android:id="#id/mScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
menu:main_content="#id/mainContainer"
menu:menu_content="#id/menuContainer"
menu:menu_handle="#id/handle"
menu:menu_marginRight="#dimen/menu_margin_r">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment
android:id="#id/menuContainer"
class="com.onemap.fragments.MainMenu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:tag="MainMenu"
tools:layout="#layout/menu_main" />
<include
android:id="#id/mainContainer"
layout="#layout/widgets" />
</LinearLayout>
</com.onemap.widgets.SlidingMenu>
</RelativeLayout>
menu_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#id/btnSearch"
style="#android:style/TextAppearance.Widget.EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/menu_item_margin"
android:background="#drawable/selector_edittext_search"
android:clickable="true"
android:drawableLeft="#mipmap/ic_search"
android:drawablePadding="#dimen/menu_item_icon_padding"
android:gravity="center_vertical"
android:text="#string/search"
android:textColor="#color/selector_edittext_search_text" />
<LinearLayout
android:id="#id/listFooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/menu_item_margin"
android:gravity="right">
<ImageView
android:id="#id/iv_arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:paddingRight="#dimen/menu_item_icon_padding"
android:src="#mipmap/ic_arrow_up_disabled" />
<ImageView
android:id="#id/iv_arrow_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:paddingLeft="#dimen/menu_item_icon_padding"
android:paddingRight="#dimen/menu_item_icon_padding"
android:src="#mipmap/ic_arrow_down_enabled" />
</LinearLayout>
<ListView
android:id="#id/menu_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/listFooter"
android:layout_below="#id/btnSearch"
android:divider="#null"
android:dividerHeight="0.0dip"
android:fadingEdgeLength="0.0dip" />
</RelativeLayout>
set #+id instead of #id.
android:id="#+id/btnSearch"
for more take it as a reference
I have some problems with my simple app in Android with Java code. I'm trying to set a RadioGroup that works like settings for color of buttons. When I start my app in Settings activity (Settings.java), it crashes.
package com.app.testing;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class Settings extends Main implements OnCheckedChangeListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.ButtonSettingsView);
int checkedRadioButton = radioGroup.getCheckedRadioButtonId();
switch (checkedRadioButton) {
case R.id.redbtn :
add.setBackgroundColor(21);
break;
case R.id.blubtn :
add.setBackgroundColor(58);
break;
case R.id.grebtn :
add.setBackgroundColor(13);
break;
}
Button back = (Button) findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
#Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
}
}
Log:
05-27 16:27:49.611: E/AndroidRuntime(4970): FATAL EXCEPTION: main
05-27 16:27:49.611: E/AndroidRuntime(4970): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.testing/com.app.testing.Settings}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.RadioGroup
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.os.Looper.loop(Looper.java:137)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-27 16:27:49.611: E/AndroidRuntime(4970): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 16:27:49.611: E/AndroidRuntime(4970): at java.lang.reflect.Method.invoke(Method.java:511)
05-27 16:27:49.611: E/AndroidRuntime(4970): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-27 16:27:49.611: E/AndroidRuntime(4970): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-27 16:27:49.611: E/AndroidRuntime(4970): at dalvik.system.NativeStart.main(Native Method)
05-27 16:27:49.611: E/AndroidRuntime(4970): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.RadioGroup
05-27 16:27:49.611: E/AndroidRuntime(4970): at com.app.testing.Settings.onCreate(Settings.java:16)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.Activity.performCreate(Activity.java:5104)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-27 16:27:49.611: E/AndroidRuntime(4970): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-27 16:27:49.611: E/AndroidRuntime(4970): ... 11 more
Thanks
It seems the problem is in this line
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.ButtonSettingsView);
May be you are trying to cast a TextView to RadioGroup. Check your xml. I am afraid that your id ButtonSettingsView is a textView
I think the LogCat says it all:
Check your XML layout file: is ButtonSettingsView actually a RadioGroup?
I'm not getting a direct error in Eclipse.. but when trying to run this on my phone it doesn't open the activity and then my phone resets. I might be using the array adapter wrong.. but here's my code files:
Java File
package creativecoders.periodictable;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class AM extends Activity {
private ListView amList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.am);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
#Override
public void onStart() {
super.onStart();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.AM, android.R.layout.simple_list_item_1);
amList.setAdapter(adapter);
}
public void onPause() {
super.onPause();
finish();
}
public void onStop() {
super.onStop();
finish();
}
public void onDestroy() {
super.onDestroy();
finish();
}
}
XML Layout File
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
String File
<string-array name="AM">
<item> ONE </item>
<item> TWO </item>
<item> THREE </item>
</string-array>
EDIT: Log file:
04-20 23:10:07.660: D/AndroidRuntime(284): Shutting down VM
04-20 23:10:07.660: W/dalvikvm(284): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-20 23:10:07.670: E/AndroidRuntime(284): FATAL EXCEPTION: main
04-20 23:10:07.670: E/AndroidRuntime(284): java.lang.RuntimeException: Unable to start activity ComponentInfo{creativecoders.periodictable/creativecoders.periodictable.AM}: java.lang.NullPointerException
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Looper.loop(Looper.java:123)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521)
04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-20 23:10:07.670: E/AndroidRuntime(284): at dalvik.system.NativeStart.main(Native Method)
04-20 23:10:07.670: E/AndroidRuntime(284): Caused by: java.lang.NullPointerException
04-20 23:10:07.670: E/AndroidRuntime(284): at creativecoders.periodictable.AM.onStart(AM.java:28)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Activity.performStart(Activity.java:3781)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
04-20 23:10:07.670: E/AndroidRuntime(284): ... 11 more
you did not initialize the ListView. in onCreate()
amList = (ListView)findViewById(R.id.listView1);
This is a food recipe application and I am just learning so if you could please help me rectify my error and explain, I will be so grateful. Thanks in advance
Main activity
package rice.recipe;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;
public class RiceActivity extends Activity {
private RiceRecipeDataSource ds;
private ListView recipelistview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rice);
ds=new RiceRecipeDataSource();
recipelistview=(ListView)findViewById(rice.recipe.R.id.listView1);
recipelistview.setAdapter(new RiceRecipeDataSourceAdapter(this,ds ));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.rice, menu);
return true;
}
}
ADAPTER code
package rice.recipe;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class RiceRecipeDataSourceAdapter extends BaseAdapter {
private Context mycontext;
private LayoutInflater myinflater;
private RiceRecipeDataSource mydatasource;
public RiceRecipeDataSourceAdapter(Context ctx,RiceRecipeDataSource ds)
{
mycontext=ctx;
mydatasource=ds;
myinflater=(LayoutInflater)mycontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return mydatasource.getDataSourceLength();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView thumbnail;
TextView name;
if (convertView==null)
convertView=myinflater.inflate(rice.recipe.R.layout.activity_rice, parent,false);
thumbnail=(ImageView)convertView.findViewById(rice.recipe.R.id.imageView1);
thumbnail.setImageResource(mydatasource.getPhotoPool().get(position));
name=(TextView)convertView.findViewById((rice.recipe.R.id.textView1));
name.setText(mydatasource.getDishesPool().get(position));
return convertView;
}
}
DATA SOURCE code
package rice.recipe;
import java.util.ArrayList;
public class RiceRecipeDataSource
{
private ArrayList<Integer> photoPool;
private ArrayList<Integer> descriptionPool;
private ArrayList<Integer> dishesPool;
public ArrayList<Integer> getPhotoPool()
{
return photoPool;
}
public ArrayList<Integer> getDescriptionPool()
{
return descriptionPool;
}
public ArrayList<Integer> getDishesPool()
{
return dishesPool;
}
public RiceRecipeDataSource()
{
photoPool=new ArrayList<Integer>();
descriptionPool=new ArrayList<Integer>();
dishesPool=new ArrayList<Integer>();
setupPhotopool();
setupDescriptionpool();
setupDishespool();
}
public void setupPhotopool()
{
photoPool.add(rice.recipe.R.drawable.jollofrice);
photoPool.add(rice.recipe.R.drawable.friedrice);
photoPool.add(rice.recipe.R.drawable.spaghetti);
photoPool.add(rice.recipe.R.drawable.coconutrice);
photoPool.add(rice.recipe.R.drawable.ricenbeans);
photoPool.add(rice.recipe.R.drawable.whiterice);
}
public void setupDishespool()
{
dishesPool.add(rice.recipe.R.string.jellof);
dishesPool.add(rice.recipe.R.string.fried_rice);
dishesPool.add(rice.recipe.R.string.spag);
dishesPool.add(rice.recipe.R.string.coconut);
dishesPool.add(rice.recipe.R.string.rice_beans);
dishesPool.add(rice.recipe.R.string.plain_rice);
}
public void setupDescriptionpool()
{
descriptionPool.add(rice.recipe.R.string.jellof_desc);
descriptionPool.add(rice.recipe.R.string.friedr_desc);
descriptionPool.add(rice.recipe.R.string.spag_desc);
descriptionPool.add(rice.recipe.R.string.coconut_desc);
}
public int getDataSourceLength()
{
return photoPool.size();
}
}
This is my LogCat
04-03 05:47:34.217: D/dalvikvm(865): GC_FOR_ALLOC freed 39K, 6% free 2657K/2816K, paused 78ms, total 83ms
04-03 05:47:34.237: I/dalvikvm-heap(865): Grow heap (frag case) to 3.783MB for 1127536-byte allocation
04-03 05:47:34.317: D/dalvikvm(865): GC_FOR_ALLOC freed 2K, 5% free 3756K/3920K, paused 80ms, total 80ms
04-03 05:47:34.421: D/dalvikvm(865): GC_CONCURRENT freed <1K, 5% free 3760K/3920K, paused 13ms+20ms, total 108ms
04-03 05:47:34.697: D/AndroidRuntime(865): Shutting down VM
04-03 05:47:34.697: W/dalvikvm(865): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-03 05:47:34.778: E/AndroidRuntime(865): FATAL EXCEPTION: main
04-03 05:47:34.778: E/AndroidRuntime(865): java.lang.NullPointerException
04-03 05:47:34.778: E/AndroidRuntime(865): at rice.recipe.RiceRecipeDataSourceAdapter.getView(RiceRecipeDataSourceAdapter.java:52)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.AbsListView.obtainView(AbsListView.java:2159)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.ListView.onMeasure(ListView.java:1158)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.View.measure(View.java:15518)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:666)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.View.measure(View.java:15518)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.View.measure(View.java:15518)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.View.measure(View.java:15518)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-03 05:47:34.778: E/AndroidRuntime(865): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.View.measure(View.java:15518)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.Choreographer.doFrame(Choreographer.java:532)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.os.Handler.handleCallback(Handler.java:725)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.os.Looper.loop(Looper.java:137)
04-03 05:47:34.778: E/AndroidRuntime(865): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-03 05:47:34.778: E/AndroidRuntime(865): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 05:47:34.778: E/AndroidRuntime(865): at java.lang.reflect.Method.invoke(Method.java:511)
04-03 05:47:34.778: E/AndroidRuntime(865): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-03 05:47:34.778: E/AndroidRuntime(865): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-03 05:47:34.778: E/AndroidRuntime(865): at dalvik.system.NativeStart.main(Native Method)
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rice.recipe"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="rice.recipe.RiceActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.main" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
after editing, new logcat
04-03 07:23:36.608: D/dalvikvm(933): GC_FOR_ALLOC freed 46K, 6% free 2657K/2824K, paused 175ms, total 179ms
04-03 07:23:36.631: I/dalvikvm-heap(933): Grow heap (frag case) to 3.783MB for 1127536-byte allocation
04-03 07:23:36.709: D/dalvikvm(933): GC_FOR_ALLOC freed 2K, 5% free 3756K/3928K, paused 75ms, total 75ms
04-03 07:23:36.858: D/dalvikvm(933): GC_CONCURRENT freed <1K, 4% free 3771K/3928K, paused 13ms+19ms, total 153ms
04-03 07:23:37.161: D/AndroidRuntime(933): Shutting down VM
04-03 07:23:37.161: W/dalvikvm(933): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-03 07:23:37.248: E/AndroidRuntime(933): FATAL EXCEPTION: main
04-03 07:23:37.248: E/AndroidRuntime(933): java.lang.NullPointerException
04-03 07:23:37.248: E/AndroidRuntime(933): at rice.recipe.RiceRecipeDataSourceAdapter.getView(RiceRecipeDataSourceAdapter.java:52)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.AbsListView.obtainView(AbsListView.java:2159)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.ListView.onMeasure(ListView.java:1158)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.View.measure(View.java:15518)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:666)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.View.measure(View.java:15518)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.View.measure(View.java:15518)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.View.measure(View.java:15518)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-03 07:23:37.248: E/AndroidRuntime(933): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.View.measure(View.java:15518)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.Choreographer.doFrame(Choreographer.java:532)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.os.Handler.handleCallback(Handler.java:725)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.os.Looper.loop(Looper.java:137)
04-03 07:23:37.248: E/AndroidRuntime(933): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-03 07:23:37.248: E/AndroidRuntime(933): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 07:23:37.248: E/AndroidRuntime(933): at java.lang.reflect.Method.invoke(Method.java:511)
04-03 07:23:37.248: E/AndroidRuntime(933): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-03 07:23:37.248: E/AndroidRuntime(933): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-03 07:23:37.248: E/AndroidRuntime(933): at dalvik.system.NativeStart.main(Native Method)
You are not following the Adapter customization properly. Check this . Your getView should be like the given code snippet. Can also check this
Here is the code I use to bring up the activity:
startActivity(new Intent(getApplicationContext(), Giveaway.class));
Here is the Activity that I am bringing up:
public class Giveaway extends Activity implements OnClickListener{
static SharedPreferences settings;
SharedPreferences.Editor prefEditor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.giveaway);
settings = getSharedPreferences("firsttime", 0);
LinearLayout facebook = (LinearLayout)findViewById(R.id.facebooklayout);
Button later = (Button)findViewById(R.id.later);
Button dontshowagain = (Button)findViewById(R.id.dontshowagain);
facebook.setOnClickListener(this);
later.setOnClickListener(this);
dontshowagain.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.facebooklayout:
Uri localuri = Uri.parse("http://www.facebook.com/pages/Bright-Design/366832480049386");
startActivity(new Intent("android.intent.action.VIEW", localuri));
break;
case R.id.later:
finish();
break;
case R.id.dontshowagain:
finish();
prefEditor = settings.edit();
prefEditor.putBoolean("showgiveaway", false);
prefEditor.commit();
break;
}
}
I have declared the Activity in my manifest folder:
<activity
android:name=".Giveaway"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait"/>
But I keep getting a java.lang.RuntimeException: Unable to start activity java.lang.NullPointerException error. Here is my logcat:
07-24 12:43:59.082: E/AndroidRuntime(7039): FATAL EXCEPTION: main
07-24 12:43:59.082: E/AndroidRuntime(7039): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brightdesign.blackops2/com.brightdesign.blackops2.Giveaway}: java.lang.NullPointerException
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.os.Looper.loop(Looper.java:123)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-24 12:43:59.082: E/AndroidRuntime(7039): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 12:43:59.082: E/AndroidRuntime(7039): at java.lang.reflect.Method.invoke(Method.java:521)
07-24 12:43:59.082: E/AndroidRuntime(7039): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-24 12:43:59.082: E/AndroidRuntime(7039): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-24 12:43:59.082: E/AndroidRuntime(7039): at dalvik.system.NativeStart.main(Native Method)
07-24 12:43:59.082: E/AndroidRuntime(7039): Caused by: java.lang.NullPointerException
07-24 12:43:59.082: E/AndroidRuntime(7039): at com.brightdesign.blackops2.Giveaway.onCreate(Giveaway.java:29)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
You need to post your layout code, but what is most likely happening is that one of these three lines is returning a null value:
LinearLayout facebook = (LinearLayout)findViewById(R.id.facebooklayout);
Button later = (Button)findViewById(R.id.later);
Button dontshowagain = (Button)findViewById(R.id.dontshowagain);
In the debugger step through those lines and if one is null, there is your problem because as soon as you try to set the on click listener it is going to fail.
Caused by: java.lang.NullPointerException
at com.brightdesign.blackops2.Giveaway.onCreate(Giveaway.java:29)
Tells us that there is a NullPointerException in Giveaway.onCreate(), specifically Giveaway.java line 29. Odds are facebook, later, and/or dontshowagain is really null. Do you have all three of these defined in giveaway.xml?
Try this...
1.
Intent i = new Intent(Your_Activity.this, Another_Activity.class);
startActivity(i);
2. This below lines points to the class and the lines which are null.
Class:
com.brightdesign.blackops2/com.brightdesign.blackops2.Giveaway}: java.lang.NullPointerException
Lines:
Please check the below four lines, i think you are getting null value here.
Uri localuri = Uri.parse("http://www.facebook.com/pages/Bright-Design/366832480049386");
LinearLayout facebook = (LinearLayout)findViewById(R.id.facebooklayout);
Button later = (Button)findViewById(R.id.later);
Button dontshowagain = (Button)findViewById(R.id.dontshowagain);