i can't to solve these following error in android. try to help me

  • Replies:3
amalthomas
  • Forum posts: 3

Mar 19, 2013, 8:07:29 AM via Website

E/AndroidRuntime(8250): FATAL EXCEPTION: main

E/AndroidRuntime(8250): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sample/com.example.sample.MainActivity}: java.lang.NullPointerException

E/AndroidRuntime(8250): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

E/AndroidRuntime(8250): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

E/AndroidRuntime(8250): at android.app.ActivityThread.access$600(ActivityThread.java:141)

E/AndroidRuntime(8250): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

E/AndroidRuntime(8250): at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime(8250): at android.os.Looper.loop(Looper.java:137)

E/AndroidRuntime(8250): at android.app.ActivityThread.main(ActivityThread.java:5039)

E/AndroidRuntime(8250): at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime(8250): at java.lang.reflect.Method.invoke(Method.java:511)

E/AndroidRuntime(8250): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

E/AndroidRuntime(8250): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

E/AndroidRuntime(8250): at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(8250): Caused by: java.lang.NullPointerException

E/AndroidRuntime(8250): at com.example.sample.MainActivity.onCreate(MainActivity.java:30)

E/AndroidRuntime(8250): at android.app.Activity.performCreate(Activity.java:5104)

E/AndroidRuntime(8250): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)

E/AndroidRuntime(8250): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

Reply
amalthomas
  • Forum posts: 3

Mar 19, 2013, 8:09:42 AM via Website

can anyone try to help me to clear this fatal exception error.

Reply
Petter Ljungqvist
  • Forum posts: 4

Mar 21, 2013, 10:11:25 PM via Website

Could you post the code where the error occurs?

Reply
amalthomas
  • Forum posts: 3

Mar 23, 2013, 6:23:41 AM via Website

package com.example.sample;

import android.os.Bundle;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ListActivity {

private static final Context context = null;
SQLiteDatabase sq;
public String DBPath;
public static Context currentContext;
String arg[]=new String[1000];
int i=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
sq=MainActivity.this.openOrCreateDatabase("sample" ,MODE_PRIVATE,null);
currentContext = context;
DBPath = "/data/data/" + context.getPackageName() + "/databases";
Cursor cur=sq.rawQuery("select * from labels",null);

if(cur!=null)
{
if(cur.moveToFirst())
{
do
{
arg[i]=cur.getString(cur.getColumnIndex(""));
i++;
}while(cur.moveToNext());
}
}
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_ list_item_1,arg);
setListAdapter(adapter);
}
protected void onListItemClick(ListView l,View v,int position,long id)
{
super.onListItemClick(l, v, position, id);
Intent in=new Intent(MainActivity.this,SubActivity.class);
startActivity(in);
in.putExtra("id",arg[position]);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }

Reply