1

I got null exception errors I need some help to figure it out as I tried to update my Manifest and it's seems fine but still getting the error

here is the logcat

03-09 16:00:53.803: E/JSON(540): {"tag":"login","success":1,"error":0,"uid":"513b5349d86546.88432881","user":{"name":"p","email":"p","created_at":"2013-03-09 23:20:41","updated_at":null}}
03-09 16:00:54.863: E/AndroidRuntime(540): FATAL EXCEPTION: main
03-09 16:00:54.863: E/AndroidRuntime(540): java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.mohammed.watzIslam/com.mohammed.watzIslam.maincontentview}: java.lang.NullPointerException
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.os.Looper.loop(Looper.java:123)
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.app.ActivityThread.main(ActivityThread.java:4627)
03-09 16:00:54.863: E/AndroidRuntime(540):  at java.lang.reflect.Method.invokeNative(Native Method)
03-09 16:00:54.863: E/AndroidRuntime(540):  at java.lang.reflect.Method.invoke(Method.java:521)
03-09 16:00:54.863: E/AndroidRuntime(540):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-09 16:00:54.863: E/AndroidRuntime(540):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-09 16:00:54.863: E/AndroidRuntime(540):  at dalvik.system.NativeStart.main(Native Method)
03-09 16:00:54.863: E/AndroidRuntime(540): Caused by: java.lang.NullPointerException
03-09 16:00:54.863: E/AndroidRuntime(540):  at com.mohammed.watzIslam.maincontentview.onCreate(maincontentview.java:28)
03-09 16:00:54.863: E/AndroidRuntime(540):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-09 16:00:54.863: E/AndroidRuntime(540):  at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-09 16:00:54.863: E/AndroidRuntime(540):  ... 11 more

and this is my java file that can't be launched

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class maincontentview extends Activity {

public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    String[] contentarray = getResources().getStringArray(R.array.contnarr);
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.maincontentview,    R.id.label1, contentarray));




 ListView lv = getListView();

 // listening to single list item on click
 lv.setOnItemClickListener(new OnItemClickListener() {
   public void onItemClick(AdapterView<?> parent, View view,
       int position, long id) {
         // start different activities
       switch(position){
        case 0:
        Intent  txt = new Intent(view.getContext(),TextA.class);

          try{
            startActivity(txt);
          } catch(ActivityNotFoundException e) {
            e.printStackTrace();
          }
          break;
        case 1:
         Intent video = new Intent(view.getContext(),Videos.class);
          try{
            startActivity(video);
          }catch(ActivityNotFoundException e){
            e.printStackTrace();
          }
          break;

        default: break;

        }           



}
 });
}

    private ListView getListView() {
    // TODO Auto-generated method stub
    return null;
    }

    private void setListAdapter(ArrayAdapter<String> arrayAdapter) {
    // TODO Auto-generated method stub

    }

 }

and finally the chief Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mohammed.watzIslam"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
     >
    <activity
        android:name=".Mymain"
        android:label="@string/title_activity_mymain" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".DashboardActivity"
        android:label="@string/title_activity_mymain" >
        <intent-filter>
            <action android:name="com.mohammed.watzIslam.DashboardActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
     <!--  Login Activity -->
    <activity
        android:label="Login Account" 
        android:name=".LoginActivity"></activity>

    <!--  Register Activity -->
    <activity
        android:label="Register New Account" 
        android:name=".RegisterActivity"></activity>
    <activity
        android:label="application interface" 
        android:name=".Appinterface"></activity>
    <activity
        android:label="content list view" 
        android:name=".maincontentview"></activity>
    <activity
        android:label="forum view" 
        android:name=".Forum"></activity>

    <activity
        android:label="videos list" 
        android:name=".Videos"></activity>
    <activity
        android:label="videoa view" 
        android:name=".VideoA"></activity>
    <activity
        android:label="videob view" 
        android:name=".VideoB"></activity>


</application>

</manifest>
4

1 回答 1

1

You are extending your class from the Activity and still you are using getListView().

getListView() is used only while using ListActivity. For the normal Activity, you would need to use setContentView(View) to generate the layout.

Seeing your code, I think you should be using a ListActivity.

public class maincontentview extends ListActivity

于 2013-03-09T16:14:43.047 回答