Trouble with ArrayList [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a trouble in my app retrieving my data from parse.com
I just wanted to recover data from website in an ArrayList made with a custom class, for using later in my app
Here is code but I can't test it on my emulator because my app crashes on boot, despite I don't have coding errors
PS: I'm very new in android coding, so any help is well accepted!
final int duration = Toast.LENGTH_SHORT;
ParseQuery<ParseObject> queryP = ParseQuery.getQuery("Menu");
queryP.orderByAscending("Id");
queryP.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> MenuList, ParseException e) {
int Id_c;
String Image_c;
String Name_c;
String Description_c;
String Type_c;
Double Cost_c;
ArrayList<Plate> FullMenu = new ArrayList<Plate>();
Plate plate;
if (e == null) {
for (ParseObject plate_o : MenuList) {
Id_c = plate_o.getInt("Id");
Image_c = plate_o.getString("Image");
Name_c = plate_o.getString("Name");
Description_c = plate_o.getString("Description");
Type_c = plate_o.getString("Type");
Cost_c = plate_o.getDouble("Cost");
String text = Name_c;
Toast toast = Toast.makeText(getApplicationContext(), text, duration);
toast.show();
FullMenu.add(Id_c, new Plate(Id_c, Image_c, Name_c, Description_c, Type_c, Cost_c));
plate = FullMenu.get(Id_c);
if (plate.getId() % 5 == 0) {
text = plate.getName();
toast = Toast.makeText(getApplicationContext(), text, duration);
toast.show();
}
}
}
else {
String text = "The get request failed.";
Toast toast = Toast.makeText(getApplicationContext(), text, duration);
toast.show();
}
}
});
And here is my logcat
01-02 19:18:58.916 4406-4406/mycompany.restaurantapp I/art: Not late-enabling -Xcheck:jni (already on)
01-02 19:18:58.916 4406-4406/mycompany.restaurantapp I/art: Late-enabling JIT
01-02 19:18:58.918 4406-4406/mycompany.restaurantapp I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
01-02 19:18:58.962 4406-4406/mycompany.restaurantapp W/System: ClassLoader referenced unknown path: /data/app/mycompany.restaurantapp-2/lib/x86
01-02 19:18:59.401 4406-4438/mycompany.restaurantapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-02 19:18:59.446 4406-4406/mycompany.restaurantapp D/: HostConnection::get() New Host Connection established 0xa335d700, tid 4406
01-02 19:18:59.542 4406-4438/mycompany.restaurantapp D/: HostConnection::get() New Host Connection established 0xa335d8d0, tid 4438
01-02 19:18:59.556 4406-4438/mycompany.restaurantapp I/OpenGLRenderer: Initialized EGL, version 1.4
01-02 19:18:59.703 4406-4438/mycompany.restaurantapp W/EGL_emulation: eglSurfaceAttrib not implemented
01-02 19:18:59.704 4406-4438/mycompany.restaurantapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad79f160, error=EGL_SUCCESS
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp D/AndroidRuntime: Shutting down VM
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: FATAL EXCEPTION: main
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: Process: mycompany.restaurantapp, PID: 4406
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at java.util.ArrayList.add(ArrayList.java:147)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at mycompany.restaurantapp.MainActivity$1.done(MainActivity.java:91)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at mycompany.restaurantapp.MainActivity$1.done(MainActivity.java:69)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-02 19:19:04.799 4406-4406/mycompany.restaurantapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-02 19:19:11.067 4406-4406/? I/Process: Sending signal. PID: 4406 SIG: 9

FullMenu.add(Id_c, new Plate(Id_c, Image_c, Name_c, Description_c, Type_c, Cost_c));
The wrong line. You're trying to add the element to empty ArrayList at certain position. Try to make it like this
FullMenu.add(new Plate(Id_c, Image_c, Name_c, Description_c, Type_c, Cost_c));
If you want to have an access by id as key you should use Map structure.

Related

Calculator App : The app shuts down after I click on a (sign)button

I cant figure out where I went wrong with my code. Every time I press a button my apps shuts down unless I add a try and catch. As soon as I enter the two numbers and add the sign, the results should print out, but instead the app is just shutting down. Here is my LogCat and code. BTW I'm new to java & android studio, so excuse my mistakes.
public class MainActivity extends AppCompatActivity {
Button btnAdd, btnSubtract,btnMultiply, btnDivide;
TextView textResults, textSigns;
EditText firstnumber, secondnumber;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstnumber = (EditText) findViewById(R.id.firstnumber);
secondnumber =(EditText) findViewById(R.id.secondnumber);
textResults = (TextView) findViewById(R.id.results);
textSigns = (TextView) findViewById(R.id.invisible_signs);
btnAdd = (Button) findViewById(R.id.Add);
btnDivide = (Button) findViewById(R.id.divide);
btnMultiply =(Button) findViewById(R.id.Multiply);
btnSubtract =(Button) findViewById(R.id.Subtract);
final String number1 = firstnumber.getText().toString();
final String number2 = secondnumber.getText().toString();
btnDivide.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {int divide = Integer.parseInt(number1) / Integer.parseInt(number2);
textResults.setText(number1 + " / " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + divide);}
catch(Exception e){
Toast.makeText(getApplicationContext(), "Cannot Divide These Numbers", Toast.LENGTH_SHORT).show();
}
}
});
btnMultiply.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int multiply = Integer.parseInt(number1) * Integer.parseInt(number2);
textResults.setText(number1 + " * " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + multiply);
}
});
btnAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int addition = Integer.parseInt(number1) + Integer.parseInt(number2);
textResults.setText(number1 + " + " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + addition);
}
});
btnSubtract.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int subtract = Integer.parseInt(number1) - Integer.parseInt(number2);
textResults.setText(number1 + " - " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + subtract);
}
});
}
}
.
Logcat:
0-25 16:12:28.330 1860-1860/com.squarespace.atpublishing.calculatorapp I/art: Not late-enabling -Xcheck:jni (already on)
10-25 16:12:28.640 1860-1867/com.squarespace.atpublishing.calculatorapp E/art: Failed writing handshake bytes (-1 of 14): Broken pipe
10-25 16:12:28.640 1860-1867/com.squarespace.atpublishing.calculatorapp I/art: Debugger is no longer active
10-25 16:12:29.680 1860-1872/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 20ms
10-25 16:12:29.680 1860-1872/com.squarespace.atpublishing.calculatorapp I/art: Background partial concurrent mark sweep GC freed 371(64KB) AllocSpace objects, 0(0B) LOS objects, 47% free, 556KB/1068KB, paused 20ms total 280ms
10-25 16:12:30.370 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 40ms
10-25 16:12:30.620 1860-1900/com.squarespace.atpublishing.calculatorapp D/OpenGLRenderer: Render dirty regions requested: true
10-25 16:12:30.690 1860-1860/com.squarespace.atpublishing.calculatorapp D/: HostConnection::get() New Host Connection established 0x7fc39eccf580, tid 1860
10-25 16:12:30.690 1860-1860/com.squarespace.atpublishing.calculatorapp D/Atlas: Validating map...
10-25 16:12:30.870 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 100ms
10-25 16:12:30.890 1860-1872/com.squarespace.atpublishing.calculatorapp I/art: Background sticky concurrent mark sweep GC freed 824(47KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 919KB/1068KB, paused 0 total 160ms
10-25 16:12:30.940 1860-1872/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 50ms
10-25 16:12:31.300 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 10ms
10-25 16:12:31.540 1860-1872/com.squarespace.atpublishing.calculatorapp I/art: Background sticky concurrent mark sweep GC freed 437(19KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 942KB/1068KB, paused 0 total 240ms
10-25 16:12:31.680 1860-1900/com.squarespace.atpublishing.calculatorapp I/OpenGLRenderer: Initialized EGL, version 1.4
10-25 16:12:31.720 1860-1900/com.squarespace.atpublishing.calculatorapp D/OpenGLRenderer: Enabling debug mode 0
10-25 16:12:31.760 1860-1900/com.squarespace.atpublishing.calculatorapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-25 16:12:31.760 1860-1900/com.squarespace.atpublishing.calculatorapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fc39ece3040, error=EGL_SUCCESS
10-25 20:12:38.850 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 220ms
10-25 20:12:39.010 1860-1860/com.squarespace.atpublishing.calculatorapp I/Choreographer: Skipped 72 frames! The application may be doing too much work on its main thread.
10-25 20:12:39.790 1860-1860/com.squarespace.atpublishing.calculatorapp I/Choreographer: Skipped 46 frames! The application may be doing too much work on its main thread.
10-25 16:12:42.610 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 30ms
10-25 16:12:42.940 1860-1860/com.squarespace.atpublishing.calculatorapp I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
10-25 16:12:43.120 1860-1900/com.squarespace.atpublishing.calculatorapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-25 16:12:43.120 1860-1900/com.squarespace.atpublishing.calculatorapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fc3a5ff6fc0, error=EGL_SUCCESS
10-25 16:12:49.020 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 150ms
10-25 16:12:49.380 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 80ms
10-25 16:12:58.690 1860-1860/com.squarespace.atpublishing.calculatorapp D/AndroidRuntime: Shutting down VM
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: FATAL EXCEPTION: main
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: Process: com.squarespace.atpublishing.calculatorapp, PID: 1860
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: java.lang.NumberFormatException: Invalid int: ""
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.Integer.invalidInt(Integer.java:138)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:358)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:334)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at com.squarespace.atpublishing.calculatorapp.MainActivity$2.onClick(MainActivity.java:56)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.view.View.performClick(View.java:4756)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19749)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5221)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
10-25 16:13:05.160 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 250ms
Remove these lines
final String number1 = firstnumber.getText().toString();
final String number2 = secondnumber.getText().toString();
And adjust this one
int divide = Integer.parseInt(firstnumber.getText()) / Integer.parseInt(secondnumber.getText());
You don't read the values of the inputs when doing calculations, so the strings will be always empty.
Variables get their values when assigned, the assignment doesn't mean they're bound to the inputs and change their values when the inputs change.

java.lang.OutOfMemoryError in Bitmap.copy function

I thought there is two copies of same object.that may be the issue.but I do not know how to solve that.please help me.Thanks in advance
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap b = ((BitmapDrawable) drawable).getBitmap();
// I got error in this line.
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
int w = getWidth(), h = getHeight();
Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, w);
canvas.drawBitmap(roundBitmap, 0, 0, null);
}
logcat
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: java.lang.OutOfMemoryError
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.graphics.Bitmap.nativeCopy(Native Method)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.graphics.Bitmap.copy(Bitmap.java:403)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at com.example.rajitha.myapplication.RoundedImageView.onDraw(RoundedImageView.java:39)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.View.draw(View.java:11054)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.View.getDisplayList(View.java:10493)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:2958)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2596)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.View.getDisplayList(View.java:10491)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:2958)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2596)
10-18 11:04:33.208 32110-32110/com.example.rajitha.myapplication E/AndroidRuntime: at android.view.View.draw(View.java:11057)
10-18 11:04:33.208 32110-32110/com.e
java.lang.OutOfMemoryError: Requested size exceeds VM limit.
This error indicates that a Java application attempts ti allocate an array, whose size is larger than the heap size.
The OutOfMemoryError extends the VirtualMachineError class, which indicates that the JVM is broken, or it has run out of resources and cannot operate.
Verify that your application does not store unnecessary information.
Store and maintain only those pieces of information required for the
proper execution of your Java application.
Please Read Below Document
http://developer.android.com/intl/es/training/displaying-bitmaps/load-bitmap.html
Strange out of memory issue while loading an image to a Bitmap object

AChartEngine - Charts with data from parse.com won't display

I would like to create applications forming charts based on data from parse.com. I have read some examples and tutorials but still have problem with displaying charts. Below is my code:
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import java.util.ArrayList;
public class LineGraph {
public ArrayList<Integer> dataArray;
XYMultipleSeriesDataset dataset;
XYMultipleSeriesRenderer renderer;
public static boolean ClickEnabled = true;
public Intent getIntent(Context context) {
ArrayList<Integer> y = this.dataArray;
XYSeries seriesY = new XYSeries("Y");
for (int i = 0; i < y.size(); i++) {
seriesY.add(i, y.get(i));
}
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesY);
renderer.setPanEnabled(true, false);
renderer.setClickEnabled(ClickEnabled);
renderer.setBackgroundColor(Color.WHITE);
renderer.setApplyBackgroundColor(true);
renderer.setChartTitle("Simple data");
renderer.setAxesColor(Color.BLACK);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
renderer.setPointStyle(PointStyle.DIAMOND);
mRenderer.addSeriesRenderer(renderer);
Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph Title");
return intent;
}
public void getData() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Counters_data");
query.getInBackground("lxFzCTeOcl", new GetCallback<ParseObject>() {
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
String object = parseObject.getString("value");
Integer objectValue = Integer.parseInt(object);
if (dataArray == null) {
dataArray = new ArrayList<Integer>();
dataArray.add(objectValue);
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
}
}
And there is how I invoke charts:
public void lineGraphHandler(View view) {
LineGraph line = new LineGraph();
line.getData();
Intent lineIntent = line.getIntent(this);
startActivity(lineIntent);
}
And XML part:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/counters"
android:onClick="lineGraphHandler"
android:text="Charts"
android:id="#+id/charts"/>
There is my logcat:
03-26 08:42:13.096 1229-1229/com.example.tst D/dalvikvm﹕ Late-enabling
CheckJNI 03-26 08:42:13.487 1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libEGL_genymotion.so 03-26 08:42:13.491
1229-1229/com.example.tst D/﹕ HostConnection::get() New Host
Connection established 0xb94f4270, tid 1229 03-26 08:42:13.551
1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libGLESv1_CM_genymotion.so 03-26 08:42:13.551
1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libGLESv2_genymotion.so 03-26 08:42:14.035
1229-1229/com.example.tst W/EGL_genymotion﹕ eglSurfaceAttrib not
implemented 03-26 08:42:14.039 1229-1229/com.example.tst
E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from GradienCache 03-26
08:42:14.043 1229-1229/com.example.tst E/OpenGLRenderer﹕
MAX_TEXTURE_SIZE: 4096 03-26 08:42:14.055 1229-1229/com.example.tst
E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from
Caches::initConstraints() 03-26 08:42:14.063 1229-1229/com.example.tst
E/OpenGLRenderer﹕ MAX_TEXTURE_SIZE: 4096 03-26 08:42:14.063
1229-1229/com.example.tst D/OpenGLRenderer﹕ Enabling debug mode 0
03-26 08:42:50.327 1229-1229/com.example.tst D/dalvikvm﹕ GC_FOR_ALLOC
freed 200K, 8% free 2975K/3228K, paused 10ms, total 13ms 03-26
08:42:51.675 1229-1229/com.example.tst D/dalvikvm﹕ GC_FOR_ALLOC freed
431K, 14% free 3056K/3540K, paused 22ms, total 28ms 03-26 08:42:52.043
1229-1229/com.example.tst W/EGL_genymotion﹕ eglSurfaceAttrib not
implemented 03-26 08:42:53.543 1229-1229/com.example.tst
I/Choreographer﹕ Skipped 89 frames! The application may be doing too
much work on its main thread. 03-26 08:43:01.747
1229-1229/com.example.tst D/AndroidRuntime﹕ Shutting down VM 03-26
08:43:01.747 1229-1229/com.example.tst W/dalvikvm﹕ threadid=1: thread
exiting with uncaught exception (group=0xa4d8fb20) 03-26 08:43:01.767
1229-1229/com.example.tst E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.tst, PID: 1229 java.lang.IllegalStateException:
Could not execute method of the activity at
android.view.View$1.onClick(View.java:3823) at
android.view.View.performClick(View.java:4438) at
android.view.View$PerformClick.run(View.java:18422) at
android.os.Handler.handleCallback(Handler.java:733) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:136) at
android.app.ActivityThread.main(ActivityThread.java:5017) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.reflect.InvocationTargetException at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
android.view.View$1.onClick(View.java:3818) at
android.view.View.performClick(View.java:4438) at
android.view.View$PerformClick.run(View.java:18422) at
android.os.Handler.handleCallback(Handler.java:733) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:136) at
android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.NullPointerException at
com.example.tst.LineGraph.getIntent(LineGraph.java:36) at
com.example.tst.MainActivity.lineGraphHandler(MainActivity.java:44)
at java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
android.view.View$1.onClick(View.java:3818) at
android.view.View.performClick(View.java:4438) at
android.view.View$PerformClick.run(View.java:18422) at
android.os.Handler.handleCallback(Handler.java:733) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:136) at
android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method) 03-26 08:43:04.507
1229-1229/com.example.tst I/Process﹕ Sending signal. PID: 1229 SIG: 9
I don't understand where the problem is. My app starts but crashes immediately when I push "chart" button. Is it data type of problem or because I misunderstand something?
Thank you in advance.
I tried like this but still got crash:
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
String object = parseObject.getString("value");
Integer objectValue = Integer.parseInt(object);
if (dataArray == null) {
dataArray = new ArrayList<Integer>();
dataArray.add(objectValue);
ArrayList<Integer> y = dataArray;
XYSeries seriesY = new XYSeries("Y");
for (int i = 0; i < y.size(); i++) {
seriesY.add(i, y.get(i));
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesY);
}
}
Your getData() retrieves the data asynchronously. dataArray won't be initialized immediately when you call getIntent().
Wait for the async operation to complete before using the data there. For example, call the code requiring that data from the done() callback.

Google Maps Android API v2 ClassNotFound Runtime error

EDIT: For those struggling with this, checkout this link. Follow it carefully, but it does work! The crucial part is using keytool to generate your SHA1 hash against your debug keystore. Also, don't forget to add one for release too!
I've been trying to setup Google Maps Android API v2 and after setting everything up as said I'm getting this runtime exception ClassNotFound:
01-02 16:29:07.927: E/AndroidRuntime(12508): FATAL EXCEPTION: main
01-02 16:29:07.927: E/AndroidRuntime(12508): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.os.Looper.loop(Looper.java:130)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.main(ActivityThread.java:3701)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.reflect.Method.invoke(Method.java:507)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
01-02 16:29:07.927: E/AndroidRuntime(12508): at dalvik.system.NativeStart.main(Native Method)
01-02 16:29:07.927: E/AndroidRuntime(12508): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.Activity.setContentView(Activity.java:1657)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.example.app.MapActivity.onCreate(MapActivity.java:11)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
01-02 16:29:07.927: E/AndroidRuntime(12508): ... 11 more
01-02 16:29:07.927: E/AndroidRuntime(12508): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.app-1.apk]
01-02 16:29:07.927: E/AndroidRuntime(12508): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-02 16:29:07.927: E/AndroidRuntime(12508): ... 20 more
Has anyone ever come across this before?
XML:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
MapActivity:
import android.os.Bundle;
import android.app.Activity;
public class MapActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
}
}
Your Activity needs to extend FragmentActivity from the support library
Try this code working perfect help full to you.
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
Java
package com.example.androidmapsv2;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment
= (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
"isGooglePlayServicesAvailable SUCCESS",
Toast.LENGTH_LONG).show();
}else{
GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);
}
}
}
Did you run on AVD? if yes try on real devices

Google Maps android API, drawing polylines in a loop

I have two String arrays, latitude and longitude
I want to draw polylines on the map, the documentation says, that it's as easy as pie. And it is. If I add polylines manually like this, it works:
PolylineOptions rectOptions = new PolylineOptions()
.add(new LatLng(37.35, -122.0))
.add(new LatLng(37.45, -122.0))
.add(new LatLng(37.45, -122.2))
But the problem starts when I'm trying to loop adding polylines:
rectOptions = new PolylineOptions();
for(int i = 0; i<latitude.length(); i++){
rectOptions.add(new LatLng(Long.getLong(latitude[i]), Long.getLong(longitude[i])));
// Log.d("coordinates", latitude[i]+"|"+longitude[i]);
}
I get a java.lang.NullPointerException And I don't know why. I know the problem is in the rectOptions.add() method, because Log.d("coordinates", latitude[i]+"|"+longitude[i]); works fine in the same loop.
Here's the output of LogCat:
01-02 11:59:27.380: E/AndroidRuntime(25146): FATAL EXCEPTION: main
01-02 11:59:27.380: E/AndroidRuntime(25146): java.lang.NullPointerException
01-02 11:59:27.380: E/AndroidRuntime(25146): at com.shniv.MainActivity$1.onClick(MainActivity.java:82)
01-02 11:59:27.380: E/AndroidRuntime(25146): at android.view.View.performClick(View.java:3519)
01-02 11:59:27.380: E/AndroidRuntime(25146): at android.view.View$PerformClick.run(View.java:14140)
01-02 11:59:27.380: E/AndroidRuntime(25146): at android.os.Handler.handleCallback(Handler.java:605)
01-02 11:59:27.380: E/AndroidRuntime(25146): at android.os.Handler.dispatchMessage(Handler.java:92)
01-02 11:59:27.380: E/AndroidRuntime(25146): at android.os.Looper.loop(Looper.java:137)
01-02 11:59:27.380: E/AndroidRuntime(25146): at android.app.ActivityThread.main(ActivityThread.java:4456)
01-02 11:59:27.380: E/AndroidRuntime(25146): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 11:59:27.380: E/AndroidRuntime(25146): at java.lang.reflect.Method.invoke(Method.java:511)
01-02 11:59:27.380: E/AndroidRuntime(25146): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
01-02 11:59:27.380: E/AndroidRuntime(25146): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
01-02 11:59:27.380: E/AndroidRuntime(25146): at dalvik.system.NativeStart.main(Native Method)

Categories