2013-01-13 20 views
0

我似乎無法左右我的頭,又一新手錯誤返回重新再出發的意圖問題

我想通過Simplay開始打算向一個新的類,我已經做了一些這對我的應用程序沒有任何問題。我manaifest似乎罰款(沒有拼寫錯誤或小寫/大寫字母那裏不應該是)和類名的拼寫是否正確等

繼承人的logcat的錯誤:

01-13 02:23:21.816: E/AndroidRuntime(283): FATAL EXCEPTION: main 
01-13 02:23:21.816: E/AndroidRuntime(283): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.search}: java.lang.NullPointerException 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.os.Handler.dispatchMessage(Handler.java:99) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.os.Looper.loop(Looper.java:123) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.app.ActivityThread.main(ActivityThread.java:4627) 
01-13 02:23:21.816: E/AndroidRuntime(283): at java.lang.reflect.Method.invokeNative(Native Method) 
01-13 02:23:21.816: E/AndroidRuntime(283): at java.lang.reflect.Method.invoke(Method.java:521) 
01-13 02:23:21.816: E/AndroidRuntime(283): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
01-13 02:23:21.816: E/AndroidRuntime(283): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
01-13 02:23:21.816: E/AndroidRuntime(283): at dalvik.system.NativeStart.main(Native Method) 
01-13 02:23:21.816: E/AndroidRuntime(283): Caused by: java.lang.NullPointerException 
01-13 02:23:21.816: E/AndroidRuntime(283): at com.example.flybase2.search.onCreate(search.java:27) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
01-13 02:23:21.816: E/AndroidRuntime(283): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.flybase2" 
android:versionCode="1" 
android:versionName="1.0" > 

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

  <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

     <activity 
     android:name=".search" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="com.example.flybase2.search" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

    <activity 
     android:name=".add" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="com.example.flybase2.add" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

     <activity 
     android:name=".view" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="com.example.flybase2.view" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 



</application> 

</manifest> 

我的IM類加載的意圖:

​​

並且是指「.search」類文件從意圖打開。

package com.example.flybase2; 

import android.app.ListActivity; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.support.v4.widget.SimpleCursorAdapter; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ListView; 

public class search extends ListActivity implements OnClickListener { 


Button searchButton; 
EditText searchName; 
ListView searchedListResults; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

searchButton = (Button) findViewById(R.id.btnSearch); 
searchName = (EditText) findViewById(R.id.inputName); 

searchButton.setOnClickListener(this); 

} 
@Override 
public void onClick(View clickedSearchButton) { 

String searchedName = searchName.getText().toString(); 

searchedListResults = (ListView)findViewById(android.R.id.list); 
DBHandler DBsearchRef = new DBHandler(this, null, null); 

DBHandler search = new DBHandler(this, null, null); 

search.open(); 
Cursor cursor = search.searchOnName(searchedName); 

startManagingCursor(cursor); 

@SuppressWarnings("static-access") 
String [] from = new String [] {DBsearchRef.KEY_NAME, DBsearchRef.KEY_TEL, DBsearchRef.KEY_EMAIL, DBsearchRef.KEY_COMMENTS}; 
int [] to = new int [] {R.id.txtNameList, R.id.txtTelList, R.id.txtEmailList, R.id.txtCommentsList}; 

@SuppressWarnings("deprecation") 
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.search, cursor, from, to); 
searchedListResults.setAdapter(cursorAdapter); 




} 
+0

搜索活動的第27行是什麼? '01-13 02:23:21.816:E/AndroidRuntime(283):引起於:java.lang.NullPointerException 01-13 02:23:21.816:E/AndroidRuntime(283):at com.example.flybase2.search .onCreate(search.java:27)' – t0mm13b

回答

1

您意圖啓動活動就好了。空指針異常亮起此行

searchButton.setOnClickListener(this); 

您沒有設置該活動的內容視圖,所以findViewById返回null。

1

我認爲你在你的搜索結果中缺少setContentView()。在訪問它之前設置佈局:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.YourLayOutName); 
+0

謝謝你,我添加了內容視圖。我仍然得到零點異常錯誤'01 -13 02:58:16.669:E/AndroidRuntime(273):java.lang.RuntimeException:無法啓動活動ComponentInfo {com.example.flybase2/com.example.flybase2。搜索}:java.lang.NullPointerException' – user1352057