gpt4 book ai didi

android - 空指针错误

转载 作者:行者123 更新时间:2023-11-30 03:43:50 25 4
gpt4 key购买 nike

我遇到了空异常错误,我需要一些帮助来解决这个问题,因为我尝试更新我的 list ,它看起来很好,但仍然出现错误

这是日志

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

这是我无法启动的java文件

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

}

}

最后是主要 list

<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>

最佳答案

您正在从 Activity 扩展您的类,但您仍在使用 getListView()

getListView() 仅在使用 ListActivity 时使用。对于普通的 Activity,您需要使用 setContentView(View) 来生成布局。

看到你的代码,我认为你应该使用 ListActivity

公共(public)类 maincontentview 扩展 ListActivity

关于android - 空指针错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15312850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com