我试着运行我在android studio中创建的应用程序, 编码没有错误,但应用程序强制关闭。
错误日志
01-14 03:49:32.389 8122-8122/com.kareem.kdevelop.listjualmobil E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 01-14 03:49:33.159 8122-8122/com.kareem.kdevelop.listjualmobil E/AndroidRuntime: FATAL EXCEPTION: main Process: com.kareem.kdevelop.listjualmobil, PID: 8122 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kareem.kdevelop.listjualmobil/com.kareem.kdevelop.listjualmobil.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5045) 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.ArrayIndexOutOfBoundsException: length=3; index=3 at com.kareem.kdevelop.listjualmobil.MainActivity.onCreate(MainActivity.java:44) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5045) 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)
MainActivity:
public class MainActivity extends AppCompatActivity {
String[][] data = new String[][]{
{"Honda, Brio, 1.2L CKD S A/T, 2015",
"http://imgcdn.rajamobil.com:8080/resize2/public/media/images/databasemobil/mobilbaru/color/Brio%20-%20Brilliant%20Sporty%20Blue%20Metallic.png?v=420","19 Juta", "Jakarta Selatan"},
{"Honda, Jazz, RS 1.5 A/T, 2015",
"http://imgcdn.rajamobil.com:8080/resize2/public/media/images/databasemobil/original/2016/12/15/S1V6xervpWJK8rWnOqhxSve86RCb7VxK.JPG?v=493.83983572895","19 Juta", "Jakarta Selatan"},
{"Mazda, Mazda2, V 1.5 M/T, 2014",
"http://imgcdn.rajamobil.com:8080/resize2/public/media/images/databasemobil/mobilbaru/color/mazda2-abutua.jpg?v=420", "Tangerang"},
{"Honda, Jazz, A 1.5 M/T, 2015",
"http://imgcdn.rajamobil.com:8080/resize2/public/media/images/databasemobil/original/2016/12/19/otxIMI39Mq7o6QROZ7GJr_sm-TkizvNz.jpg?v=526.36904761905","Rp. 207.500.000", "Jakarta Barat"},
{"Mitsubishi, Outlander, Sport PX, 2015",
"http://imgcdn.rajamobil.com:8080/resize2/public/media/images/databasemobil/original/2016/11/17/81y5XBNeCNUQ-wUvaB6q7eSYc7D3XGr8.JPG?v=492.82786885246","Call", "Tangerang"}
};
private ListView lvItem;
private ArrayList listItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvItem = (ListView)findViewById(R.id.lv_item);
listItem = new ArrayList<>();
MobilModel mobil = null;
for (int i = 0; i < data.length; i++){
mobil = new MobilModel();
mobil.setTitle(data[i][0]);
mobil.setImage(data[i][1]);
mobil.setHarga(data[i][2]);
mobil.setLokasi(data[i][3]);
listItem.add(mobil);
}
MobilAdapter adapter = new MobilAdapter(MainActivity.this, listItem);
lvItem.setAdapter(adapter);
lvItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MobilModel mbl = (MobilModel) listItem.get(position);
Intent intent = new Intent(MainActivity.this, DetailMobilActivity.class);
intent.putExtra(DetailMobilActivity.KEY_ITEM, mbl);
startActivityForResult(intent, 0);
}
});
}
答案 0 :(得分:0)
try
{
g.DrawLine(pen, x1 * eF, y1 * eF + yEx, x * eF, y2 * eF + yEx);
}
catch {} //Not usually a great idea to eat all exceptions, but for troubleshooting purposes this'll do
只有三个元素,因此没有索引3。
答案 1 :(得分:-2)
您的问题中的错误与您问题的标题不符。
您的问题中的错误是:
java.lang.ArrayIndexOutOfBoundsException: length=3; index=3 at com.kareem.kdevelop.listjualmobil.MainActivity.onCreate(MainActivity.java:44)
问题在于这一行:mobil.setLokasi(data[i][3]);
。您的数组只有三个元素,索引为0,1和2.您需要在数组中添加第四个元素以获得索引3.