Skip to main content

App crashes when you click several times



In my app the first screen is a list and when you click once it goes ok but if,my mistake or something, you click two or more times before it loads the application crashes. I've been doing a little research but I didn't found anything. I post my code:







@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.firstscreen);

// Set title

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,

R.layout.mainheader);



// Get Arguments

Bundle extras = getIntent().getExtras();

if (extras != null) {

app = extras.getString("app");

}



//Set simulation date

TextView date = (TextView) findViewById(R.id.date);

date.setText(convertDateToString());

// set the list adapter: ListView myList =

ListView lv = (ListView) findViewById(R.id.list);

DataBaseAccess ddbb = new DataBaseAccess();

//Download the data from a database

lv.setAdapter(new MyAdapter(this, R.layout.listitem, myLines,

flowAlarm, precAlarm));

lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() {



public void onItemClick(AdapterView<?> parent, View view,

int position, long id) {

Intent i = new Intent(Main.this, ShowGraph.class);

String[] obj = list.split(";");

i.putExtra("object name", obj[position]);

i.putExtra("app name", app);

i.putExtra("app list", list);

startActivity(i);



}

});



// Set buttons clickable

Button exit = (Button) findViewById(R.id.exit);

exit.setOnClickListener(this);

Button calendar = (Button) findViewById(R.id.calendar);

calendar.setOnClickListener(this);

}







Does anyone knows why?





My LogCat:







02-29 13:51:27.975: E/AndroidRuntime(9082): FATAL EXCEPTION: main

02-29 13:51:27.975: E/AndroidRuntime(9082): java.lang.NullPointerException

02-29 13:51:27.975: E/AndroidRuntime(9082):at org.achartengine.chart.XYChart.toRealPoint(XYChart.java:699)

02-29 13:51:27.975: E/AndroidRuntime(9082):at org.achartengine.tools.Pan.apply(Pan.java:64)

02-29 13:51:27.975: E/AndroidRuntime(9082):at org.achartengine.TouchHandler.handleTouch(TouchHandler.java:106)

02-29 13:51:27.975: E/AndroidRuntime(9082):at org.achartengine.GraphicalView.onTouchEvent(GraphicalView.java:284)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.view.View.dispatchTouchEvent(View.java:3952)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1034)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1034)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1034)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1034)

02-29 13:51:27.975: E/AndroidRuntime(9082): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1034)

02-29 13:51:27.975: E/AndroidRuntime(9082): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1034)

02-29 13:51:27.975: E/AndroidRuntime(9082): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1711)

02-29 13:51:27.975: E/AndroidRuntime(9082): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1145)

02-29 13:51:27.975: E/AndroidRuntime(9082): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)

02-29 13:51:27.975: E/AndroidRuntime(9082):at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1695)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2217)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.view.ViewRoot.handleMessage(ViewRoot.java:1901)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.os.Handler.dispatchMessage(Handler.java:99)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.os.Looper.loop(Looper.java:130)

02-29 13:51:27.975: E/AndroidRuntime(9082):at android.app.ActivityThread.main(ActivityThread.java:3701)

02-29 13:51:27.975: E/AndroidRuntime(9082):at java.lang.reflect.Method.invokeNative(Native Method)

02-29 13:51:27.975: E/AndroidRuntime(9082):at java.lang.reflect.Method.invoke(Method.java:507)

02-29 13:51:27.975: E/AndroidRuntime(9082):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)

02-29 13:51:27.975: E/AndroidRuntime(9082):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)

02-29 13:51:27.975: E/AndroidRuntime(9082):at dalvik.system.NativeStart.main(Native Method)







The ShowGraph activity oncreate:







@Override

public void onCreate(Bundle savedInstanceState) {



super.onCreate(savedInstanceState);



// Get arguments

Bundle extras = getIntent().getExtras();

if (extras != null) {

object = extras.getString("object name");

app = extras.getString("app name");

list = extras.getString("app list");

}

// Set title

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,

R.layout.headermenu);

// Download the info from the database



downloadInfo(app, object);



// set the button listeners

listeners();

//Set checkbox listeners

setCheckListeners();



// Drag Meteo

vg = (RelativeLayout) findViewById(R.id.graph);

vg.setOnTouchListener(new View.OnTouchListener() {

RelativeLayout vg1 = (RelativeLayout) findViewById(R.id.graph1);



public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction()) {

case MotionEvent.ACTION_MOVE:

// int x = (int) event.getX() - offset_x;

int y = (int) event.getY() - offset_y;

int w = getWindowManager().getDefaultDisplay().getWidth();

int h = vg.getHeight() - 40;

if (y < 0)

y = 0;

if (y > h)

y = h;

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(

new ViewGroup.MarginLayoutParams(

RelativeLayout.LayoutParams.FILL_PARENT,

RelativeLayout.LayoutParams.WRAP_CONTENT));

lp.setMargins(0, y, 0, 0);

selected_item.setLayoutParams(lp);

int height = vg1.getHeight();

RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(

new ViewGroup.MarginLayoutParams(

RelativeLayout.LayoutParams.FILL_PARENT,

RelativeLayout.LayoutParams.WRAP_CONTENT));

lp2.setMargins(0, 0, 0, Math.abs(vg.getHeight() - y));

// lp2.height = y-height;

vg1.setLayoutParams(lp2);

break;

default:

break;

}

return true;

}

});

RelativeLayout img = (RelativeLayout) findViewById(R.id.vg);

img.setOnTouchListener(new View.OnTouchListener() {



public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

offset_x = (int) event.getX();

offset_y = (int) event.getY();

selected_item = v;

break;

default:

break;

}

return false;

}

});

}







I tried with the AsyncTask as I read here but is not working:





Android: Disable ListView once clicked?


Comments

  1. In ShowGraph:

    if (extras != null) {
    object = extras.getString("object name");
    app = extras.getString("app name");
    list = extras.getString("app list");
    }


    If your extras is null, then your app is null too. So problem can be there

    downloadInfo(app, object); //NullPointerException


    ALSO

    1) Note that onCreate() called once (only for first click). It's better to move your "get Intent" part to onStart() method.

    2) Use debbuging tools or try to hide your code with comments block by block, to find where is NullPointerException exactly.

    /*Like this
    downloadInfo(app, object);
    */

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex