1

I dont know whats wrong but every time i want to put the string element in 1. class from my class koca android gives me error.

Plese help me cause i dont know what to do...

Thanks for your ansewers

    package com.klemenjezakon.koceSLO;

import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class KocaInter extends ListActivity {

    int n = 2;
    koca koce[] = new koca[n];
    ArrayList<String> kocee = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        inicjalizacijaKoc();

        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, kocee));
    }

    private void inicjalizacijaKoc() {
        // TODO Auto-generated method stub

            koce[0].ime = "Nekaj";
            kocee.add(koce[0].ime);
            koce[1].ime="Nekaj";
            kocee.add(koce[1].ime);

    }

    protected void onListItemClick(ListView lv, View v, int position, long id) {
        super.onListItemClick(lv, v, position, id);

        startActivity(new Intent("android.intent.action.KocaInter"));
    }

}

and clas koca:

    package com.klemenjezakon.koceSLO;

public class koca {

    String ime,visina,odprtost,predel,drustvo,oskrbnik,telefon,gms,telefonPD,email,splet,naslov,kategorija,lezisca,jedilnica,cenik,opis,razgled,zanimivejseTure,prehodDoKoc,vzponiNaVrhove;

}
1
  • 1
    First please put proper title with your question. Second post Logcat entries. Commented Jan 20, 2013 at 9:50

2 Answers 2

3

The koce[] array is initialized to a empty koca array filled with nulls. You first need to create a koca object before you can access or modify its fields.

        // Create an instance and store it in the array
        koce[0] = new koca();
        // Retrieve the instance and set a field
        koce[0].ime = "Nekaj";
        // Retrieve the field
        kocee.add(koce[0].ime);

Although I have to agree with @KKD: first acquire some debugging information and (attempt to) debug it yourself first. Your code should have thrown a NullPointerException where you access koce[0].ime since koce[0] was still null.

Sign up to request clarification or add additional context in comments.

Comments

0

you didn't put any value in koce[] array so koce[0] returns null therefore koce[0].ime rises exception

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.