JSON:Android . lang。RuntimeException:无法启动活动组件信息。

时间:2023-01-24 20:53:12

I have a class that works until I try to use JSONFunkcije class. (remove comments)

在尝试使用JSONFunkcije类之前,我有一个类。(删除评论)

TaksiDetalji.java:

TaksiDetalji.java:

public class TaksiDetalji extends Activity {

String id;
String ime;
 JSONFunkcije podatak;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.taksi_detalji);
    Intent i = getIntent();

    // getting id
    id = i.getStringExtra("id");
   podatak =  = new JSONFunkcije(id);
   List<String> sluzbice = new ArrayList<String>();
   sluzbice = podatak.DetaljiSluzbe();
   //EditText editText = (EditText)findViewById(R.id.editText1);
   //Iterator <String> it = sluzbice.iterator();
   //ime = it.next();
    //editText.setText("ime");
}

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

     }

When I remove comments I get the following error: (Unfortunately, Oceni Taksi has stopped = no layout loaded)

当我删除注释时,我得到了以下错误:(不幸的是,Oceni Taksi已经停止=没有布局加载)

09-26 21:29:26.258: E/AndroidRuntime(5815): FATAL EXCEPTION: main
09-26 21:29:26.258: E/AndroidRuntime(5815): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ocenitaksi/com.example.ocenitaksi.TaksiDetalji}: java.util.NoSuchElementException
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.os.Looper.loop(Looper.java:137)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.ActivityThread.main(ActivityThread.java:5041)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at java.lang.reflect.Method.invokeNative(Native Method)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at java.lang.reflect.Method.invoke(Method.java:511)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at dalvik.system.NativeStart.main(Native Method)
09-26 21:29:26.258: E/AndroidRuntime(5815): Caused by: java.util.NoSuchElementException
09-26 21:29:26.258: E/AndroidRuntime(5815):     at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:572)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at com.example.ocenitaksi.TaksiDetalji.onCreate(TaksiDetalji.java:32)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.Activity.performCreate(Activity.java:5104)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-26 21:29:26.258: E/AndroidRuntime(5815):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-26 21:29:26.258: E/AndroidRuntime(5815):     ... 11 more

JSONfunkcije.java

JSONfunkcije.java

package com.example.ocenitaksi;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JSONFunkcije {
    List<String> niz;

    private String ime_sluzbe;
    private String id_taksiste;


    //konstruktori
    public JSONFunkcije(String ime_sluzbe , String id_taksiste){
        this.ime_sluzbe=ime_sluzbe;
        this.id_taksiste=id_taksiste;
    }
    public JSONFunkcije(String ime_sluzbe){
        this.ime_sluzbe=ime_sluzbe;
    }


    //parser za zahteve
    JSONParser jParser = new JSONParser();
    JSONArray products = null;  

    //adrese
    private static String sluzbe = "http://android.yunews.net/sluzbe.php";
    private static String detalji_sluzba = "http://android.yunews.net/detalji_sluzba.php";
    private static String detalji_taksiste = "http://android.yunews.net/detalji_taksiste.php";  

    //JSON TAGOVI
    private static final String TAG_NAME = "ime";
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_PRODUCTS = "products";
    private static final String TAG_BROJ = "broj";
    private static final String TAG_GLASOVI ="glasovi";
    private static final String TAG_TEKST = "tekst";
    private static final String TAG_OCENA = "ocena";
    private static final String TAG_KOMENTARI="komentari";


    protected List<String>  ListaSluzbi (){
        niz=new ArrayList<String>();

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        JSONObject json = jParser.makeHttpRequest(sluzbe, "GET", params);

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // products found
                // Getting Array of Products
                products = json.getJSONArray(TAG_PRODUCTS);

                // looping through All Products
                int i=0;

                for ( i = 0; i < products.length(); i++) {
                    JSONObject c = products.getJSONObject(i);                   
                    niz.add(c.getString(TAG_NAME));
                }
            }
        }
        catch (JSONException e) {
            e.printStackTrace();
        }

        return niz;

    }

    protected List<String> DetaljiSluzbe (){

        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("ime",ime_sluzbe));

        JSONObject json = jParser.makeHttpRequest(detalji_sluzba,"POST", params);

        params=new ArrayList<NameValuePair>();

        //json=jParser.makeHttpRequest(detalji_sluzba,"GET", params);

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // products found
                // Getting Array of Products
                products = json.getJSONArray(TAG_PRODUCTS);

                // looping through All Products
                int i=0;

                for ( i = 0; i < products.length(); i++) {
                    JSONObject c = products.getJSONObject(i);                   
                    niz.add(c.getString(TAG_NAME));
                    niz.add(c.getString(TAG_BROJ));
                    niz.add(c.getString(TAG_GLASOVI));
                    niz.add(c.getString(TAG_OCENA));
                    niz.add(c.getString(TAG_TEKST));
                }


            }
        }
        catch (JSONException e) {
            e.printStackTrace();
        }
        return niz;

    }


    protected List<String> DetaljiTaksiste (){
        niz=new ArrayList<String>();

        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("sluzba",ime_sluzbe));
        params.add(new BasicNameValuePair("taksista",id_taksiste));

        JSONObject json = jParser.makeHttpRequest(detalji_sluzba,"POST", params);
        params=new ArrayList<NameValuePair>();

        //json=jParser.makeHttpRequest(detalji_taksiste,"GET", params);

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // products found
                // Getting Array of Products
                products = json.getJSONArray(TAG_PRODUCTS);

                // looping through All Products
                int i=0;

                for ( i = 0; i < products.length(); i++) {
                    JSONObject c = products.getJSONObject(i);
                    niz.add(c.getString(TAG_OCENA));
                    niz.add(c.getString(TAG_GLASOVI));
                    niz.add(c.getString(TAG_KOMENTARI));
                }

            }
        }
        catch (JSONException e) {
            e.printStackTrace();
        }

        return niz;
    }

}

I think that the problem in JSON and I am sure that the problem is in the JSONfunkcije.java but I can't find anything.

我认为JSON的问题,我确信问题在于JSONfunkcije。java,但我什么也找不到。

Tnx, Djomla

Tnx,Djomla

1 个解决方案

#1


2  

The problem is in JSONFunkcije.java in DetaljiSluzba().

问题在于JSONFunkcije。java在DetaljiSluzba()。

I forgot to put niz=new ArrayList<String>();

我忘记输入niz=new ArrayList ();

Now works. Tnx.

现在工作。Tnx。

#1


2  

The problem is in JSONFunkcije.java in DetaljiSluzba().

问题在于JSONFunkcije。java在DetaljiSluzba()。

I forgot to put niz=new ArrayList<String>();

我忘记输入niz=new ArrayList ();

Now works. Tnx.

现在工作。Tnx。