-6

I am a beginner in android development.
I am using parse.com for retrieving data from server and listview to display data in activity homepage.
However, when I open my app, it crashes.

I have initialized everything correctly but still somehow it doesn't work.
For seccurity reasons, I have removed parse.initialize(keys) from this code.

package com.example.sangram.nearbyapp;

import android.app.Activity;
import android.app.ListActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.FindCallback;

import com.parse.Parse;
import com.parse.ParseException;

import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;

import java.util.List;


public class HomepageActivity extends ListActivity {
    protected List<ParseObject> mprofessional;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_homepage);

        ParseUser currentUser = ParseUser.getCurrentUser();
        if(currentUser!=null)
        {
            //show user homepage
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Professionals");
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> professional, ParseException e) {
                    if(e==null)
                    {
                        //success
                        mprofessional = professional;
                        ProfessionalAdaptor adaptor = new ProfessionalAdaptor(getListView().getContext(),mprofessional);
                        setListAdapter(adaptor);
                    }
                    else
                    {
                        //there is a problem
                    }
                }
            });
        }
        else
        {    
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

professionaladapter.java

package com.example.sangram.nearbyapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.parse.Parse;
import com.parse.ParseObject;

import java.util.List;

/**
 * Created by SANGRAM on 12/04/2015.
 */
public class ProfessionalAdaptor extends ArrayAdapter <ParseObject> {
    protected Context mcontext;
    protected List<ParseObject> mProfessionals;

    public ProfessionalAdaptor(Context context, List<ParseObject> professionals )
    {
        super(context, R.layout.homepagecustomlayout, professionals );
        mcontext= context;
        mProfessionals=professionals;
    }

    public View getView(final  int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        if(convertView==null)
        {
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.homepagecustomlayout, null);
            holder = new ViewHolder();
            holder.namehomepage = (TextView) convertView.findViewById(R.id.userhp);
            holder.prohomepage = (TextView) convertView.findViewById(R.id.prohp);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }

        ParseObject statusObject =  mProfessionals.get(position);
        String pname = statusObject.getString("Name");
        holder.namehomepage.setText(pname);

        String ppro = statusObject.getString("Profession");
        holder.prohomepage.setText(ppro);
        return  convertView;
    }

    public static class ViewHolder
    {
        TextView namehomepage; // name of professional from parse database
        TextView prohomepage; // name of profession from parse
    }
}

manifest

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.example.sangram.nearbyapp" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".HomepageActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".RegisterActivity"
            android:label="@string/title_activity_login" >
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login" >
        </activity>

    </application>

</manifest>

Logcat

04-15 12:52:22.287 1784-1784/com.example.sangram.nearbyapp E/ResourceType﹕ Style contains key with bad entry: 0x01010479 04-15 12:52:32.707 1784-1784/com.example.sangram.nearbyapp E/ResourceType﹕ Style contains key with bad entry: 0x01010479 04-15 12:52:32.757 1784-1784/com.example.sangram.nearbyapp E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sangram.nearbyapp/com.example.sangram.nearbyapp.HomepageActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ListActivity.onContentChanged(ListActivity.java:243) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273) at android.app.Activity.setContentView(Activity.java:1881) at com.example.sangram.nearbyapp.HomepageActivity.onCreate(HomepageActivity.java:26) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)             at android.app.ActivityThread.access$600(ActivityThread.java:141)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)             at android.os.Handler.dispatchMessage(Handler.java:99)             at android.os.Looper.loop(Looper.java:137)             at android.app.ActivityThread.main(ActivityThread.java:5039)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:511)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)             at dalvik.system.NativeStart.main(Native Method) 04-15 12:53:18.019 1865-1865/com.example.sangram.nearbyapp E/ResourceType﹕ Style contains key with bad entry: 0x01010479

Daniel Puiu
  • 962
  • 6
  • 21
  • 29
Sangram Barge
  • 1,611
  • 2
  • 13
  • 8
  • 4
    and Where is your logcat? – M D Apr 14 '15 at 07:23
  • my app was not working it was crashing so i uninstalled from emulator i am not able to locate logcat now – Sangram Barge Apr 14 '15 at 07:25
  • 2
    You have to post your logcat,otherwise none can help you. – Soham Apr 14 '15 at 07:28
  • Ok I am trying to rebuild project I will post logcat if my app will show up in emulator – Sangram Barge Apr 14 '15 at 07:32
  • 1
    Here's tutorial for you, how to view logs in [Android Studio](https://developer.android.com/tools/debugging/debugging-studio.html#systemLogView) and [Eclipse](http://developer.android.com/tools/debugging/ddms.html#running) – VadymVL Apr 14 '15 at 07:45
  • possible duplicate of [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – 2Dee Apr 14 '15 at 08:19
  • I have added a log cat help would be appreciated – Sangram Barge Apr 15 '15 at 13:00

1 Answers1

0

Check your activity_homepage.xml layout. Since your using a ListActivity it must have a ListView with id 'list'.

BUT don't add the + before id , the list view should have this id:

    android:id="@android:id/list"
Leonardo C
  • 276
  • 2
  • 5
  • Thanks for replying bro i tried it but it didnt work – Sangram Barge Apr 17 '15 at 15:25
  • Just to check can you post the relevant part of R.layout.activity_homepage? Your logcat says 'Your content must have a ListView whose id attribute is 'android.R.id.list' at ...' , I would imagine there is a problem with the list in the xml – Leonardo C Apr 17 '15 at 17:35