Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Fluue
Jan 2, 2008
I'm building a simple app that queries my site, gets the json response, then displays data in a view. I'm having trouble grasping how to pass data to a view, though. I'll be taking several fields from each response, and I assume I need to use a listview.

Does anyone have a guide that helped you understand passing data to views?

Adbot
ADBOT LOVES YOU

Fluue
Jan 2, 2008

Volmarias posted:

What kind of data are you displaying? Listviews are meant for lists, and you'll want an adapter to use them properly. Is it sufficient to just have a plain old TextView? If so, then it's as simple as calling setText.

I'm making an app "clone" of my website http://randompokemongenerator.com

I'm assuming ListView is best because I'm looping rows (up to 6 max). I have a JSON response page setup that I'll use to take url GET values in the app based on user selections (same as on the website).

Fluue
Jan 2, 2008
Hey everyone,

I'm working on a little hobby project just to learn my way around Android. I have a quick question about onClickListener, though.

My app takes in user input, sends the input to a php script, then the script returns some JSON and the app parses/displays the information.

I have my app taking data/sending to server/getting data and parsing in my main activity.. is this the wrong way to be doing it if users will press a button to initiate the data transfer? Right now my button and onClickListener don't seem to do anything.

Should I be using intents instead? (not really looking to do that right now, but I will if it's the only way).

Here's my code for the onCreate method

code:
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //setup image loader
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).build();
        ImageLoader.getInstance().init(config);

        //input vars
        final Spinner numPoke = (Spinner) findViewById(R.id.SpinnerNumPokemon);
        final Spinner dexRegion = (Spinner) findViewById(R.id.SpinnerRegion);
        final Spinner pokeType = (Spinner) findViewById(R.id.SpinnerType);
        final ToggleButton incNFE = (ToggleButton) findViewById(R.id.toggleNFE);
        final ToggleButton incLegendary = (ToggleButton) findViewById(R.id.toggleLegendary);
        Button generateGo = (Button)findViewById(R.id.buttonGo);

        generateGo.setOnClickListener(new View.OnClickListener(){
            public void onClick(View view){
                /**
                 * Begin setting the values from out input
                 */
                String mNumPoke = numPoke.getSelectedItem().toString();
                String mDexRegion = dexRegion.getSelectedItem().toString();
                String mPokeType = pokeType.getSelectedItem().toString();
                if(incNFE.isChecked()){
                    String mNFE = "2";
                } else {
                    String mNFE = "1";
                }
                if(incLegendary.isChecked()){
                    String mLegendary = "2";
                } else {
                    String mLegendary = "1";
                }
                //end setting values from input

		//this is the async task I'm trying to call
             LoadPokemon generateThePokemon = new LoadPokemon();
                generateThePokemon.execute();
            }
        });

        //hashmap for list
        pokemonList = new ArrayList<HashMap<String, String>>();


    }

Fluue fucked around with this message at 02:57 on Jul 5, 2013

Fluue
Jan 2, 2008
I'm having a lot of trouble getting a ListView working. I've tried using two different adapters (LazyAdapter and then a custom SimpleAdapter)

My app takes JSON data and then parses it into a listview (simple enough). But I'm also using the ImageLoader library from nostra13 ( https://github.com/nostra13/Android-Universal-Image-Loader ) to take a dynamically generated URL and download an image.

I'm getting NullPointerExceptions, and just now got this when using the custom SimpleAdapter:

code:
07-27 18:56:22.321: ERROR/AndroidRuntime(28133): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dsgunter.randompokemongenerator/
com.dsgunter.randompokemongenerator.Results}: 
java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2132)
        at android.app.ActivityThread.access$600(ActivityThread.java:139)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5021)
        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:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at com.dsgunter.randompokemongenerator.Results.onCreate(Results.java:51)
        at android.app.Activity.performCreate(Activity.java:5058)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
I'll attach the code that's giving me grief below:
https://gist.github.com/verkaufer/985a7f4e0f145a729e0b (Results.Java)
https://gist.github.com/verkaufer/28ae68336f8b698affec (MyAdapter.java - the new adapter that generated the above error)
https://gist.github.com/verkaufer/63d9764dc80c2fa09d10 (LazyAdapter.java - old adapter that I was using but pokeman on line 72 always remained null)

Should I keep using my LazyAdapter? I tried the other one because I was stumped on why pokeman wasn't populating (even using breakpoints, it stayed null the entire time).

Fluue
Jan 2, 2008
Whoops! I must have deleted that line when refactoring..

I'm still receiving the same error though. I tried a solution provided on StackOverflow (changing my activity name for Results.java to .Results in AndroidManifest.xml) but that still results in the same error and app crash. Is there a specific debug method I should look at to determine where things are going wrong?

Fluue
Jan 2, 2008
My app is doing something odd with JSON parsing when adding my JSON items to an ArrayList<HashMap<String, String>>.

I'm getting a nullpointer exception (see below) when I look at my app's logcat, and I think it has something to do with this.

code:
DEBUG/Pokemon Output:(2848): > [{"type2":"fire","type1":"dark","real_pokemon_id":"229","name":"Houndoom"}]
05-13 22:17:37.977: DEBUG/Pokemon Output post mapping:(2848): > [{type2=fire, real_pokemon_id=229, 
sprite_url=actualurlhere, type1=dark, name=Houndoom}]
05-13 22:17:38.008: INFO/ActivityManager(702): START {flg=0x10000000 cmp=com.dsgunter.randompokemongenerator/.Results (has extras)
 u=0} 
from pid 2848
05-13 22:17:38.158: DEBUG/Pokemon Output After Intent Passing:(2848): > [{type2=fire, real_pokemon_id=229, 
sprite_url=actualurlhere, type1=dark, name=Houndoom}]
05-13 22:17:38.188: ERROR/AndroidRuntime(2848): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{/com.dsgunter.randompokemongenerator.Results}:

java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2132)
        at android.app.ActivityThread.access$600(ActivityThread.java:139)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5021)
        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:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at com.dsgunter.randompokemongenerator.Results.onCreate(Results.java:53)
        at android.app.Activity.performCreate(Activity.java:5058)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
        ... 11 more
Pay special attention to the DEBUG/Pokemon Output and DEBUG/Pokemon Output post mapping. Is this supposed to be happening?

I'm puzzled where I'm getting a nullpointer when trying to start Results.java from an intent..

For my full code, see here: https://gist.github.com/verkaufer/ee6f244097d80e00fabb

Fluue
Jan 2, 2008

kitten smoothie posted:

In Results' onCreate method:

This isn't the resource ID for a ListView. It's not even a resource ID for a view at all, which is why it's returning null. That is why your list.setAdapter call is blowing up.

code:
list = (ListView) findViewById(R.layout.list_generated_pokemon);

I have a custom adapter setup because I have a defined row layout (Therefore I have a listview and a row xml file)

I am using a (probably lovely) adapter called LazyAdapter from a tutorial site just so I can get a hang of using an adapter. If I got my resource IDs correct, the adapter should just take in ArrayList<HashMap<string, string>> right?

Relevant code, including my views: https://gist.github.com/verkaufer/578af362176847e29970

Googling for transferring an ArrayList<HashMap<>> data type into a ListView has been fruitless so far. If there's a tutorial I'm overlooking (and I've looked at Vogella), please direct me to it.

Fluue
Jan 2, 2008

Evil_Greven posted:

Here's how I setup a ListView for an app of mine (snipped for relevant parts):
Java code:
	ArrayAdapter<Spanned> adapter = null;
	ArrayList<Spanned> spannedList = new ArrayList<Spanned>();
	//snip
	Quake q = new Quake(getIntent().getStringExtra("Quake" + i));
	//snip loops and poo poo
	//adapter = new ArrayAdapter<Quake>(this,
	//        android.R.layout.simple_list_item_1, quakeList);
	spannedList.add(q.toSpanned());
	adapter = new ArrayAdapter<Spanned>(this,
	            android.R.layout.simple_list_item_1, spannedList);
	setListAdapter(adapter);
I did this only because I needed to color the text in the ListView via html encoding. q.Spanned() returns type Spanned. You can just set the ArrayAdapter<whateverClass> and skip the spannedList stuff, too. This is how I used to have it (ArrayAdapter<Quake> and ArrayList<Quake>) prior to this implementation. It's slightly weird like this; my layout is actually called "@android:id/list" yet it gets referenced by simple_list_item_1. Some weirdness with Android.
So you're skipping a custom implementation and just using ArrayAdapter?

Fluue
Jan 2, 2008
So my app got suspended from the market after submitting it. It's apparently because of Impersonation and Intellectual Property infringement (for Pokemon). When I look up "Pokemon" in the Play Store I get at least 20 other apps that use the Pokeball, the name, or a combination of both. I am definitely not trying to pass off my app as official.. so what's Google's beef?

Has anyone had success appealing an app suspension?

Adbot
ADBOT LOVES YOU

Fluue
Jan 2, 2008

Tunga posted:

What, exactly, does your app do?

It allows users to generate/display a team of 6 Pokémon. It's basically just an information app.. There are other Pokémon apps that have way more information and do more than mine. I'm not sure why it got banned.

It's basically an app implementation of this: http://wyncorporation.com/pokemon

Fluue fucked around with this message at 19:22 on May 18, 2014

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply