having error "Unfortunately you ### application has stopped" - java

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

Related

Fragment in java error [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
Help me to resolve this bug. This is the logcat and fragment java code. I want to make tab layout. In the tab layout, i want to fill a different java logic. But, i dont know must place the code. Please help me
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: FATAL EXCEPTION: main
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: Process: com.prakosoft.physhics.calculator, PID: 27113
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at info.androidhive.materialtabs.fragments.OneFragment.onCreateView(OneFragment.java:39)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.View.measure(View.java:17637)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:664)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:731)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.View.measure(View.java:17637)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.View.measure(View.java:17637)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.View.measure(View.java:17637)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.View.measure(View.java:17637)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.View.measure(View.java:17637)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2618)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.View.measure(View.java:17637)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2019)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1177)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1383)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1065)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5901)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:580)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:550)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.os.Looper.loop(Looper.java:211)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5389)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
04-03 12:17:10.478 27113-27113/com.prakosoft.physhics.calculator E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
This is fragment java code
public OneFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
b = (EditText) getView().findViewById(R.id.b);
i = (EditText) getView().findViewById(R.id.i);
l = (EditText) getView().findViewById(R.id.l);
hasil = (TextView) getView().findViewById(R.id.hasil);
hitung = (Button) getView().findViewById(R.id.hitung);
spinner = (Spinner) getView().findViewById(R.id.spinner);
List<String> list = new ArrayList<String>();
list.add("");
list.add("0");
list.add("1/2");
list.add("1/2√2");
list.add("1/2√3");
list.add("1");
hitung.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String be = b.getText().toString().trim();
String ii = i.getText().toString().trim();
String el = l.getText().toString().trim();
String text = spinner.getSelectedItem().toString();
if (spinner.getSelectedItem().toString().equals("1")) {
if (b.getText().toString().equals("") || i.getText().toString().equals("") || l.getText().toString().equals("")) {
Toast.makeText(getActivity().getApplicationContext(), "Isi terlebih dahulu", Toast.LENGTH_SHORT).show();
} else {
Integer bee = Integer.parseInt(be);
Integer iii = Integer.parseInt(ii);
Integer eel = Integer.parseInt(el);
Integer tekss = Integer.parseInt(text);
Integer gaya = (bee * iii * eel) * tekss;
hasil.setText("Gaya Lorentz = " + gaya);
}
} else if (spinner.getSelectedItem().toString().equals("1/2")) {
if (b.getText().toString().equals("") || i.getText().toString().equals("") || l.getText().toString().equals("")) {
Toast.makeText(getActivity().getApplicationContext(), "Isi terlebih dahulu", Toast.LENGTH_SHORT).show();
} else {
Integer bee = Integer.parseInt(be);
Integer iii = Integer.parseInt(ii);
Integer eel = Integer.parseInt(el);
Integer gaya = (bee * iii * eel) / 2;
hasil.setText("Gaya Lorentz = " + gaya);
}
} else if (spinner.getSelectedItem().toString().equals("1/2√2")) {
if (b.getText().toString().equals("") || i.getText().toString().equals("") || l.getText().toString().equals("")) {
Toast.makeText(getActivity().getApplicationContext(), "Isi terlebih dahulu", Toast.LENGTH_SHORT).show();
} else {
Integer bee = Integer.parseInt(be);
Integer iii = Integer.parseInt(ii);
Integer eel = Integer.parseInt(el);
double akar = Math.sqrt(2);
Integer gaya = (bee * iii * eel) / 2;
double hasilakar = gaya * akar;
hasil.setText("Gaya Lorentz = " + hasilakar);
}
} else if (spinner.getSelectedItem().toString().equals("1/2√3")) {
if (b.getText().toString().equals("") || i.getText().toString().equals("") || l.getText().toString().equals("")) {
Toast.makeText(getActivity().getApplicationContext(), "Isi terlebih dahulu", Toast.LENGTH_SHORT).show();
} else {
Integer bee = Integer.parseInt(be);
Integer iii = Integer.parseInt(ii);
Integer eel = Integer.parseInt(el);
double akar = Math.sqrt(3);
Integer gaya = (bee * iii * eel) / 2;
double hasilakar = gaya * akar;
hasil.setText("Gaya Lorentz = " + hasilakar);
}
} else if (spinner.getSelectedItem().toString().equals("0")) {
if (b.getText().toString().equals("") || i.getText().toString().equals("") || l.getText().toString().equals("")) {
Toast.makeText(getActivity().getApplicationContext(), "Isi terlebih dahulu", Toast.LENGTH_SHORT).show();
} else {
hasil.setText("Gaya Lorentz = 0");
}
} else if (spinner.getSelectedItem().toString().equals("")) {
Toast.makeText(getActivity().getApplicationContext(), "Pilih sin θ", Toast.LENGTH_SHORT).show();
}
}
});
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
return view;
}
getView()
written in lines
b = (EditText) getView().findViewById(R.id.b);
is returning NULL, rather than this use this code
b = (EditText) view.findViewById(R.id.b);

Couldn't parse the HTML tags from live site in android

We are working on a power shut down app in android domain for a particular region.so we need the live update details from the URL.so we need to get the HTML tags from the live site.we got nothing.
For example in this app we get a title from the live URL and put it in a text view
the code comes here.We are using JSOUP to get the values.
package com.example.poweralert.app;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Documented;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import android.app.ProgressDialog;
import android.provider.DocumentsContract;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Intent;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Document;
public class PrimaryActivity extends ActionBarActivity {
private RadioGroup radioOptionGroup;
private RadioButton radiooptiobtn;
private Button btnDisplay;
/*public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getAssets().open("locate.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_primary);
String title=null;
Document document;
try {
document= Jsoup.connect("https://www.facebook.com/")
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get();
title=document.title();
TextView text=(TextView)findViewById(R.id.textView);
text.setText(title);
} catch (Exception e) {
e.printStackTrace();
Log.d("tag","document");
}
/*List<String> formList= new ArrayList<String>();
try {
JSONObject jSONObject = new JSONObject(loadJSONFromAsset());
JSONArray jsonArray = jSONObject.getJSONArray("Manali");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo_inside = jsonArray.getJSONObject(i);
if (jo_inside.has("location")) {
formList.add(jo_inside.getString("location"));
}
}
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, formList));
} catch (JSONException e) {
e.printStackTrace();
}*/
Button button= (Button) findViewById(R.id.btndis);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
}
how to show the live URL site title in text view.the above code shows nothing.
myHtml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:text="html text"
android:layout_below="#+id/searchView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="85dp"
android:layout_marginTop="50dp" />
</RelativeLayout>
also got this in log cat when running the app
04-03 12:29:11.123 26083-26083/com.example.ipower.app D/dalvikvm﹕ Zygote::ForkAndSpecialize : 0
04-03 12:29:11.124 26083-26083/com.example.ipower.app D/dalvikvm﹕ zygote get new systemTid : 26083
04-03 12:29:11.124 26083-26083/com.example.ipower.app D/dalvikvm﹕ Late-enabling CheckJNI
04-03 12:29:11.127 26083-26083/com.example.ipower.app D/jdwp﹕ prepping for JDWP over ADB
04-03 12:29:11.127 26083-26083/com.example.ipower.app D/jdwp﹕ ADB transport startup
04-03 12:29:11.127 26083-26086/com.example.ipower.app D/dalvikvm﹕ Elevating priority from 0 to -8
04-03 12:29:11.127 26083-26087/com.example.ipower.app D/jdwp﹕ JDWP: thread running
04-03 12:29:11.130 26083-26087/com.example.ipower.app D/jdwp﹕ acceptConnection
04-03 12:29:11.130 26083-26087/com.example.ipower.app D/jdwp﹕ trying to receive file descriptor from ADB
04-03 12:29:11.143 26083-26087/com.example.ipower.app D/jdwp﹕ received file descriptor 40 from ADB
04-03 12:29:11.144 26083-26083/com.example.ipower.app D/dalvikvm﹕ zygote get thread init done
04-03 12:29:11.148 26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.148 26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.148 26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000024, flags=0x0, dataLen=0x8
04-03 12:29:11.162 26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.162 26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x17, id=0x40000025, flags=0x0, dataLen=0xC
04-03 12:29:11.170 26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.170 26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000026, flags=0x0, dataLen=0x8
04-03 12:29:11.176 26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.176 26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000027, flags=0x0, dataLen=0x8
04-03 12:29:11.715 26083-26083/com.example.ipower.app D/jdwp﹕ sendBufferedRequest : len=0x3D
04-03 12:29:12.295 26083-26083/com.example.ipower.app D/jdwp﹕ sendBufferedRequest : len=0x47
04-03 12:29:12.464 26083-26083/com.example.ipower.app W/asset﹕ AssetManager-->addDefaultAssets CIP path not exsit!
04-03 12:29:13.130 26083-26083/com.example.ipower.app W/System.err﹕ android.os.NetworkOnMainThreadException
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
04-03 12:29:13.139 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at com.example.ipower.app.MainActivity.onCreate(MainActivity.java:29)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5122)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
04-03 12:29:13.140 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
04-03 12:29:13.141 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.access$600(ActivityThread.java:162)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:107)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Looper.loop(Looper.java:194)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5371)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:525)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
04-03 12:29:13.142 26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-03 12:29:13.143 26083-26083/com.example.ipower.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
04-03 12:29:13.143 26083-26083/com.example.ipower.app I/System.out﹕ [CDS] fix other exception in HttpUrlConnection
04-03 12:29:13.143 26083-26083/com.example.ipower.app W/System.err﹕ java.io.IOException
04-03 12:29:13.143 26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:87)
04-03 12:29:13.143 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
04-03 12:29:13.143 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at com.example.ipower.app.MainActivity.onCreate(MainActivity.java:29)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5122)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.access$600(ActivityThread.java:162)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:107)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Looper.loop(Looper.java:194)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5371)
04-03 12:29:13.144 26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
04-03 12:29:13.145 26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:525)
04-03 12:29:13.145 26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
04-03 12:29:13.145 26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-03 12:29:13.145 26083-26083/com.example.ipower.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
04-03 12:29:13.171 26083-26083/com.example.ipower.app V/PhoneWindow﹕ DecorView setVisiblity: visibility = 4
04-03 12:29:14.790 26083-26083/com.example.ipower.app V/PhoneWindow﹕ DecorView setVisiblity: visibility = 0
04-03 12:29:14.919 26083-26083/com.example.ipower.app D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
04-03 12:29:14.936 26083-26083/com.example.ipower.app D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
04-03 12:29:14.941 26083-26083/com.example.ipower.app D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
04-03 12:29:15.013 26083-26083/com.example.ipower.app D/OpenGLRenderer﹕ Enabling debug mode 0

Text Watcher android in on create

I have been trying to use textwatcher.
i called the function addTextChangedListener(this) , from onCreate but the application crashed because of this command.
please help .
private EditText txt1;
private EditText txt2;
private EditText txt3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
txt1 = (EditText) findViewById(R.id.signup_username);
txt2 = (EditText) findViewById(R.id.signup_password);
txt3 = (EditText) findViewById(R.id.signup_email);
txt1.addTextChangedListener(this);
txt2.addTextChangedListener(this);
txt3.addTextChangedListener(this);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
And :
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
View view = getCurrentFocus();
int id = view.getId();
if (id == R.id.signup_username) {
String username = ((EditText) view).getText().toString();
for (int i = 0; i < username.length(); i++) {
if (username.charAt(i) < 'a' || username.charAt(i) > 'z') {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
break;
}
else {
Toast.makeText(getApplicationContext(), "Murad", Toast.LENGTH_SHORT).show();
break;
}
}
}
else {
Toast.makeText(getApplicationContext(), "Oren", Toast.LENGTH_SHORT).show();
}
}
}
log:
04-03 11:37:22.684: D/skia(23439): new locale en-Latn-GB
04-03 11:37:22.854: D/libEGL(23439): loaded /vendor/lib/egl/libEGL_adreno.so
04-03 11:37:22.854: D/libEGL(23439): loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
04-03 11:37:22.864: D/libEGL(23439): loaded /vendor/lib/egl/libGLESv2_adreno.so
04-03 11:37:22.864: I/Adreno-EGL(23439): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build: (CL4169980)
04-03 11:37:22.864: I/Adreno-EGL(23439): OpenGL ES Shader Compiler Version: 17.01.10.SPL
04-03 11:37:22.864: I/Adreno-EGL(23439): Build Date: 09/26/13 Thu
04-03 11:37:22.864: I/Adreno-EGL(23439): Local Branch:
04-03 11:37:22.864: I/Adreno-EGL(23439): Remote Branch:
04-03 11:37:22.864: I/Adreno-EGL(23439): Local Patches:
04-03 11:37:22.864: I/Adreno-EGL(23439): Reconstruct Branch:
04-03 11:37:22.914: D/OpenGLRenderer(23439): Enabling debug mode 0
04-03 11:37:39.971: D/AndroidRuntime(23439): Shutting down VM
04-03 11:37:39.971: W/dalvikvm(23439): threadid=1: thread exiting with uncaught exception (group=0x41b2b898)
04-03 11:37:39.981: E/AndroidRuntime(23439): FATAL EXCEPTION: main
04-03 11:37:39.981: E/AndroidRuntime(23439): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.poca2/com.example.poca2.RegisterActivity}: java.lang.NullPointerException
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.ActivityThread.access$700(ActivityThread.java:159)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.os.Looper.loop(Looper.java:137)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.ActivityThread.main(ActivityThread.java:5419)
04-03 11:37:39.981: E/AndroidRuntime(23439): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 11:37:39.981: E/AndroidRuntime(23439): at java.lang.reflect.Method.invoke(Method.java:525)
04-03 11:37:39.981: E/AndroidRuntime(23439): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-03 11:37:39.981: E/AndroidRuntime(23439): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-03 11:37:39.981: E/AndroidRuntime(23439): at dalvik.system.NativeStart.main(Native Method)
04-03 11:37:39.981: E/AndroidRuntime(23439): Caused by: java.lang.NullPointerException
04-03 11:37:39.981: E/AndroidRuntime(23439): at com.example.poca2.RegisterActivity.onCreate(RegisterActivity.java:33)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.Activity.performCreate(Activity.java:5372)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
04-03 11:37:39.981: E/AndroidRuntime(23439): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
04-03 11:37:39.981: E/AndroidRuntime(23439): ... 11 more
04-03 11:37:44.545: D/skia(23761): new locale en-Latn-GB
04-03 11:37:44.776: D/libEGL(23761): loaded /vendor/lib/egl/libEGL_adreno.so
04-03 11:37:44.786: D/libEGL(23761): loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
04-03 11:37:44.786: D/libEGL(23761): loaded /vendor/lib/egl/libGLESv2_adreno.so
04-03 11:37:44.786: I/Adreno-EGL(23761): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build: (CL4169980)
04-03 11:37:44.786: I/Adreno-EGL(23761): OpenGL ES Shader Compiler Version: 17.01.10.SPL
04-03 11:37:44.786: I/Adreno-EGL(23761): Build Date: 09/26/13 Thu
04-03 11:37:44.786: I/Adreno-EGL(23761): Local Branch:
04-03 11:37:44.786: I/Adreno-EGL(23761): Remote Branch:
04-03 11:37:44.786: I/Adreno-EGL(23761): Local Patches:
04-03 11:37:44.786: I/Adreno-EGL(23761): Reconstruct Branch:
04-03 11:37:44.836: D/OpenGLRenderer(23761): Enabling debug mode 0
04-03 11:37:48.069: D/AndroidRuntime(23761): Shutting down VM
04-03 11:37:48.069: W/dalvikvm(23761): threadid=1: thread exiting with uncaught exception (group=0x41b2b898)
04-03 11:37:48.069: E/AndroidRuntime(23761): FATAL EXCEPTION: main
04-03 11:37:48.069: E/AndroidRuntime(23761): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.poca2/com.example.poca2.RegisterActivity}: java.lang.NullPointerException
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.ActivityThread.access$700(ActivityThread.java:159)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.os.Looper.loop(Looper.java:137)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.ActivityThread.main(ActivityThread.java:5419)
04-03 11:37:48.069: E/AndroidRuntime(23761): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 11:37:48.069: E/AndroidRuntime(23761): at java.lang.reflect.Method.invoke(Method.java:525)
04-03 11:37:48.069: E/AndroidRuntime(23761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-03 11:37:48.069: E/AndroidRuntime(23761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-03 11:37:48.069: E/AndroidRuntime(23761): at dalvik.system.NativeStart.main(Native Method)
04-03 11:37:48.069: E/AndroidRuntime(23761): Caused by: java.lang.NullPointerException
04-03 11:37:48.069: E/AndroidRuntime(23761): at com.example.poca2.RegisterActivity.onCreate(RegisterActivity.java:33)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.Activity.performCreate(Activity.java:5372)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
04-03 11:37:48.069: E/AndroidRuntime(23761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
04-03 11:37:48.069: E/AndroidRuntime(23761): ... 11 more
04-03 11:37:54.265: I/Process(23761): Sending signal. PID: 23761 SIG: 9
edit:
private EditText txt1;
private EditText txt2;
private EditText txt3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
txt1 = (EditText) findViewById(R.id.signup_username);
txt2 = (EditText) findViewById(R.id.signup_password);
txt3 = (EditText) findViewById(R.id.signup_email);
txt1.addTextChangedListener(new CustomTextWatcher(txt1, getApplicationContext()));
txt2.addTextChangedListener(new CustomTextWatcher(txt2, getApplicationContext()));
txt3.addTextChangedListener(new CustomTextWatcher(txt3, getApplicationContext()));
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
class CustomTextWatcher implements TextWatcher {
EditText m;
Context c;
public CustomTextWatcher (EditText e, Context context) {
m = e;
c = context;
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
int id = m.getId();
if (id == R.id.signup_username) {
String username = ((EditText) m).getText().toString();
for (int i = 0; i < username.length(); i++) {
if (username.charAt(i) < 'a' || username.charAt(i) > 'z') {
Toast.makeText(c, "Error", Toast.LENGTH_SHORT).show();
break;
}
else {
Toast.makeText(c, "Murad", Toast.LENGTH_SHORT).show();
break;
}
}
}
else {
Toast.makeText(c, "Oren", Toast.LENGTH_SHORT).show();
}
}
}
here is the edited edition.
Your EditTexts are not in the activity_register layout but in the fragment and thus cannot be found with findViewById() after inflating only the activity_register layout. This causes the NPE when you're attempting to invoke a method on a null reference.
Move the findViewById() and addTextChangedListener() code to the fragment's onCreateView() where you're actually inflating the view that contains the edittexts.

Null pointer exception error android

Null pointer exception error in my fragment class. I use tab activity in my program, list view is located in fragment xml file. code:
package com.example.timetracker;
import ///
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener, LoaderCallbacks<Cursor> {
private static String TAG = "MainActivity";
private static final int CM_DELETE_ID = 1;
private static final int RESET_STOPWATCH = 2;
static ListView lvData;
static DB db;
static SimpleCursorAdapter scAdapter;
static Activity act;
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
//create my tabs...
}
}
//some code...
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
if(position == 0){
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
if (position == 1)
{
Fragment fragment2 = new DummySectionFragment2();
Bundle args = new Bundle();
args.putInt(DummySectionFragment2.ARG_SECTION_NUMBER, position + 2);
fragment2.setArguments(args);
return fragment2;
}
return null;
}
#Override
public int getCount() {
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
}
return null;
}
}
public static class DummySectionFragment extends Fragment{
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
View v;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_tracker,
container, false);
v = inflater.inflate(R.layout.activity_statistic,
container, false);
createList();
return rootView;
}
public void createList(){
db = new DB(act);Log.d(TAG, "1");
db.open();Log.d(TAG, "2");
String[] from = new String[] {DB.COLUMN_NAME, DB.COLUMN_TIME };Log.d(TAG, "3");
int[] to = new int[] { R.id.tvTextName, R.id.tvText_time};Log.d(TAG, "4");
scAdapter = new SimpleCursorAdapter(act, R.layout.item, null, from, to, 0);Log.d(TAG, "5");
lvData = (ListView) v.findViewById(R.id.lvData);Log.d(TAG, "6 ");
//after thap i have error
lvData.setAdapter(scAdapter);Log.d(TAG, "7");
}
}
public static class DummySectionFragment2 extends Fragment implements LoaderCallbacks<Cursor> {
//some code....
}
#Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLoaderReset(Loader<Cursor> arg0) {
// TODO Auto-generated method stub
}
}
//Data base class
static class MyCursorLoader extends CursorLoader {
DB db;
public MyCursorLoader(Context context, DB db) {
super(context);
this.db = db;
}
#Override
public Cursor loadInBackground() {
Cursor cursor = db.getAllData();
return cursor;
}
}
}
Don't working code "lvData.setAdapter(scAdapter);Log.d(TAG, "7");" logs:
04-03 20:11:54.830: D/dalvikvm(1684): GC_FOR_ALLOC freed 97K, 6% free 2883K/3040K, paused 9ms, total 9ms
04-03 20:11:54.850: D/MainActivity(1684): 1
04-03 20:11:54.850: D/Data Base(1684): Открытие Подключения
04-03 20:11:54.858: D/Data Base(1684): Подключение открыто
04-03 20:11:54.858: D/MainActivity(1684): 2
04-03 20:11:54.858: D/MainActivity(1684): 3
04-03 20:11:54.858: D/MainActivity(1684): 4
04-03 20:11:54.858: D/MainActivity(1684): 6
04-03 20:11:54.858: D/MainActivity(1684): 5
04-03 20:11:54.858: D/AndroidRuntime(1684): Shutting down VM
04-03 20:11:54.858: W/dalvikvm(1684): threadid=1: thread exiting with uncaught exception (group=0xa4c41648)
04-03 20:11:54.858: E/AndroidRuntime(1684): FATAL EXCEPTION: main
04-03 20:11:54.858: E/AndroidRuntime(1684): java.lang.NullPointerException
04-03 20:11:54.858: E/AndroidRuntime(1684): at com.example.timetracker.MainActivity$DummySectionFragment.createList(MainActivity.java:200)
04-03 20:11:54.858: E/AndroidRuntime(1684): at com.example.timetracker.MainActivity$DummySectionFragment.onCreateView(MainActivity.java:187)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.View.measure(View.java:15848)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.View.measure(View.java:15848)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
04-03 20:11:54.858: E/AndroidRuntime(1684): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:302)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.View.measure(View.java:15848)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-03 20:11:54.858: E/AndroidRuntime(1684): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.View.measure(View.java:15848)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.Choreographer.doFrame(Choreographer.java:532)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.os.Handler.handleCallback(Handler.java:730)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.os.Looper.loop(Looper.java:137)
04-03 20:11:54.858: E/AndroidRuntime(1684): at android.app.ActivityThread.main(ActivityThread.java:5103)
04-03 20:11:54.858: E/AndroidRuntime(1684): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 20:11:54.858: E/AndroidRuntime(1684): at java.lang.reflect.Method.invoke(Method.java:525)
04-03 20:11:54.858: E/AndroidRuntime(1684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
04-03 20:11:54.858: E/AndroidRuntime(1684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-03 20:11:54.858: E/AndroidRuntime(1684): at dalvik.system.NativeStart.main(Native Method)
Your call to v.findViewById(R.id.lvData); is returning null. This would seem to be because you haven't put any views into the structure called v. You are then trying to use the null on the line below, and that is what causes the exception.

Adding to ListView from and EditView input

I have seen these questions and tried all the answers. Can anyone tell me what I am doing wrong here?
I have all the declarations on top, then I have my arrayadapter, then I have my enter button with onClick but when I try to input anything as soon as I click the button it crashes.
Code:
//create a list
final ListView shotList = (ListView) findViewById(R.id.shotList);
String[] values = new String[] { "6/10/13 (Attack)", "4/25/13 (Dr. Apt.)", "3/4/13 (Attack)" };
Button enterButton = (Button)findViewById(R.id.enterButt);
final EditText editText = (EditText)findViewById(R.id.enterText);
final String input = editText.getText().toString();
final ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < values.length; ++i) {
list.add(values[i]);
}
final StableArrayAdapter adapter = new StableArrayAdapter(this,
android.R.layout.simple_list_item_1, list);
shotList.setAdapter(adapter);
//add data to list via enter button
enterButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
list.add(input);
adapter.notifyDataSetChanged();
//list.add(new String(editText.getText().toString()));
}
});
////////////////////////////////////////////////////////////////////////////////////
//array adapter
private class StableArrayAdapter extends ArrayAdapter<String> {
HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
public StableArrayAdapter(Context context, int textViewResourceId,
List<String> objects) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
#Override
public long getItemId(int position) {
String item = getItem(position);
return mIdMap.get(item);
}
#Override
public boolean hasStableIds() {
return true;
}
}
}
Logcat:
06-28 19:24:52.149: D/AndroidRuntime(29515): Shutting down VM
06-28 19:24:52.149: W/dalvikvm(29515): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-28 19:24:52.239: E/AndroidRuntime(29515): FATAL EXCEPTION: main
06-28 19:24:52.239: E/AndroidRuntime(29515): java.lang.NullPointerException
06-28 19:24:52.239: E/AndroidRuntime(29515): at com.asthmaassistant.ShotActivity$StableArrayAdapter.getItemId(ShotActivity.java:104)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.AbsListView.obtainView(AbsListView.java:2180)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.ListView.onMeasure(ListView.java:1158)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.View.measure(View.java:15518)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.View.measure(View.java:15518)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.View.measure(View.java:15518)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.View.measure(View.java:15518)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-28 19:24:52.239: E/AndroidRuntime(29515): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.View.measure(View.java:15518)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.Choreographer.doFrame(Choreographer.java:532)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.os.Handler.handleCallback(Handler.java:725)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.os.Handler.dispatchMessage(Handler.java:92)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.os.Looper.loop(Looper.java:137)
06-28 19:24:52.239: E/AndroidRuntime(29515): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-28 19:24:52.239: E/AndroidRuntime(29515): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 19:24:52.239: E/AndroidRuntime(29515): at java.lang.reflect.Method.invoke(Method.java:511)
06-28 19:24:52.239: E/AndroidRuntime(29515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-28 19:24:52.239: E/AndroidRuntime(29515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-28 19:24:52.239: E/AndroidRuntime(29515): at dalvik.system.NativeStart.main(Native Method)
06-28 19:24:55.409: I/Process(29515): Sending signal. PID: 29515 SIG: 9
06-28 19:24:57.329: E/Trace(29543): error opening trace file: No such file or directory (2)
06-28 19:24:58.129: D/dalvikvm(29543): GC_FOR_ALLOC freed 71K, 8% free 2498K/2692K, paused 77ms, total 82ms
06-28 19:24:58.161: I/dalvikvm-heap(29543): Grow heap (frag case) to 3.470MB for 960016-byte allocation
06-28 19:24:58.309: D/dalvikvm(29543): GC_FOR_ALLOC freed 2K, 6% free 3433K/3632K, paused 146ms, total 146ms
06-28 19:24:58.439: D/dalvikvm(29543): GC_CONCURRENT freed <1K, 6% free 3433K/3632K, paused 16ms+19ms, total 132ms
06-28 19:24:59.479: I/Choreographer(29543): Skipped 49 frames! The application may be doing too much work on its main thread.
06-28 19:24:59.609: D/gralloc_goldfish(29543): Emulator without GPU emulation detected.
LOGCAT:
06-30 19:25:34.192: E/AndroidRuntime(9478): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131230742, class android.widget.ListView) with Adapter(class com.asthmaassistant.StableArrayAdapter)]
You "input" variable is null when you are clicking the button , you are storing data into that variable inside onCreate , actually you should do it inside onClick method .
put your
String input = editText.getText().toString();
code inside onClick method.
I think the problem is the way how you store the ids , you have to pass the newly added items id to your adapter .You get ids only when constructor of your adapter gets called .
You are getting null pointer because after adding new item , you constructor is not being called and hence id for newly added item could not be found.

Categories