2013-07-24 78 views
2

我已經編寫了一個代碼,允許用戶點擊列表視圖中的項目以轉到其他活動。但是發生了一個錯誤。模擬器問我是否在android-manifest中添加了新的活動!!
我已經這樣做了。
我想要做什麼?Android清單問題

這是完整的堆棧跟蹤。

07-24 12:20:35.263: E/AndroidRuntime(455): FATAL EXCEPTION: main 
07-24 12:20:35.263: E/AndroidRuntime(455): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.tstnetconnwithjson/com.example.tstnetconnwithjson.tables.full}; have you declared this activity in your AndroidManifest.xml? 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.app.Activity.startActivityForResult(Activity.java:2817) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.app.Activity.startActivity(Activity.java:2923) 
07-24 12:20:35.263: E/AndroidRuntime(455): at com.example.tstnetconnwithjson.MainActivity$conn$1.onItemClick(MainActivity.java:195) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.widget.ListView.performItemClick(ListView.java:3382) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.os.Handler.handleCallback(Handler.java:587) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.os.Handler.dispatchMessage(Handler.java:92) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.os.Looper.loop(Looper.java:123) 
07-24 12:20:35.263: E/AndroidRuntime(455): at android.app.ActivityThread.main(ActivityThread.java:4627) 
07-24 12:20:35.263: E/AndroidRuntime(455): at java.lang.reflect.Method.invokeNative(Native Method) 
07-24 12:20:35.263: E/AndroidRuntime(455): at java.lang.reflect.Method.invoke(Method.java:521) 
07-24 12:20:35.263: E/AndroidRuntime(455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
07-24 12:20:35.263: E/AndroidRuntime(455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
07-24 12:20:35.263: E/AndroidRuntime(455): at dalvik.system.NativeStart.main(Native Method) 

這裏是maifest文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.tstnetconnwithjson" 
    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" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 

這裏就是我所說的啓動活動代碼:

import java.util.ArrayList; 
import java.util.Collection; 

import org.apache.http.HttpResponse; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.impl.conn.DefaultClientConnection; 
import org.apache.http.protocol.HTTP; 
import org.apache.http.util.EntityUtils; 
import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 
import org.json.JSONTokener; 


import com.example.tstnetconnwithjson.tables.custome; 
import com.example.tstnetconnwithjson.tables.videos; 

import android.os.AsyncTask; 
import android.os.Bundle; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.AlertDialog.Builder; 
import android.app.ProgressDialog; 
import android.content.DialogInterface; 
import android.util.Log; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ListView; 
import android.widget.TextView; 

public class MainActivity extends Activity { 



    Button search; ; 
    TextView name ; 
    ListView listview ; 
    ArrayList<videos > videolist; 
    ArrayAdapter<videos> adapter ; 
    AlertDialog.Builder alert ; 
    ProgressDialog progressdialog ; 
    EditText name; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     videolist = new ArrayList<videos>(); 
     adapter = new ArrayAdapter<videos>(this, android.R.layout.simple_list_item_1 , android.R.id.text1,videolist); 
     name=(EditText) findViewById(R.id.editText1); 
     alert = new Builder(this); 
     alert.setTitle("Warnning") ; 
     alert.setMessage("You want to connect to the internet ..? "); 


     alert.setNegativeButton("No ", null); 
     alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 

      public void onClick(DialogInterface arg0, int arg1) { 
       String username=name.getText().toString(); 
          new connection().execute("https://gdata.youtube.com/feeds/api/videos?author="+username+"&v=2&alt=jsonc"); 

      } 
     }); 



     progressdialog = new ProgressDialog(this); 

     progressdialog.setMessage("Wait Loading .... "); 
     progressdialog.setCancelable(false); 





     search = (Button) findViewById(R.id.button1); 
     name = (TextView) findViewById(R.id.textView1); 

     listview = (ListView) findViewById(R.id.listView1); 

     listview.setAdapter(adapter); 


     search.setOnClickListener(new OnClickListener() { 

      public void onClick(View arg0) { 
      alert.show(); 


      } 
     }); 
    } 

    class connection extends AsyncTask<String, Integer, String>{ 


     @Override 
     protected void onPreExecute() { 
      progressdialog.show(); 
      super.onPreExecute(); 
     } 
     @Override 
     protected String doInBackground(String... arg0) { 

      String s = GetUrlBody(arg0[0]); 




      return s; 
     } 

     @Override 
     protected void onPostExecute(String result) { 

     try{ 

      JSONObject jo =(JSONObject) new JSONTokener(result).nextValue(); 

     JSONObject feed = jo.optJSONObject("data"); 
     JSONArray entry = feed.optJSONArray("items"); 


     for(int i = 0 ; i<entry.length() ; i++){ 

     String title = entry.getJSONObject(i).getString("title"); 

     String thumbURL = entry.getJSONObject(i).getJSONObject("thumbnail").getString("sqDefault"); 
     Log.d("after get image", "ok") 
     String url; 
     try { 
      url = entry.getJSONObject(i).getJSONObject("player").getString("mobile"); 
     } catch (JSONException ignore) { 
      url = entry.getJSONObject(i).getJSONObject("player").getString("default"); 
     } 

     String description = entry.getJSONObject(i).getString("description"); 
     Log.d("after get description", "ok"); 
     videos videoobject=new videos(); 
     videoobject.setDecscrption(description); 
     videoobject.setImageurl(thumbURL); 
     videoobject.setVediourl(url); 
     videoobject.setVideoname(title); 

     videolist.add(videoobject); 
     } 
     listview.setAdapter(new custome(MainActivity.this,videolist)); 
     Log.d("AFTER set custome ", "before notify changes"); 


     adapter.notifyDataSetChanged(); 

lview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
        long arg3) { 
       videos vobject=(videos)arg0.getItemAtPosition(arg2); 

       Intent intent = new Intent(getApplicationContext(),full.class); 

       intent.putExtra("title" ,vobject.getVideoname()); 



       intent.putExtra("description" ,vobject.getDecscrption()); 
       intent.putExtra("imageURL" ,vobject.getImageurl()); 
       intent.putExtra("videoURL" ,vobject.getVediourl()); 
       startActivity(intent); 

      } 
     }); 


     }catch(Exception exception) { 
      Log.d("exception ", "nock nock nock...."); 
      Log.e("json ", exception.getMessage()); 
     } 

      progressdialog.dismiss(); 
      super.onPostExecute(result); 

     } 




     String GetUrlBody (String Url){ 

      HttpClient client = new DefaultHttpClient(); 

      HttpGet gethttp = new HttpGet(Url); 

      try{ 
      HttpResponse response = client.execute(gethttp); 

      if(response.getStatusLine().getStatusCode() == 200){ 

       String save = 
      EntityUtils.toString(response.getEntity(), HTTP.UTF_8); 

       return save; 

      }else { 
       return "Not Found"; 
      } 

      }catch(Exception exception){} 




      return null; 
     } 



    } 


} 
+2

你能告訴我們的清單文件? – gunar

+2

發佈您的清單文件 –

+0

@gunar:我已經更新了我的問題。 – Tolen

回答

2

作爲第一個音符: 1.不要啓動新的活動爲:

Intent intent = new Intent(getApplicationContext(),full.class); 

而是:

Intent intent = new Intent(MainActivity.this, full.class); 

2.你的代碼是不是連可以編譯,因爲您有兩個具有相同命名的類成員:name(一個EditText和一個TextView)。然後你有失蹤的冒號。

然後,確保full確實存在,並且它在Manifest中是正確的。 (無論如何,這個類名稱是合法的,但是類名稱的Java慣例慣例應該以大寫字母開頭)。類似於(@ Sanath的回答): <activity android:name=".tables.full"/><activity android:name="com.example.tstnetconnwithjson.tables.full"/>

然後,即使這沒有幫助,它可能會導致您的private libraries are not exported in Eclipse事實。但是,如果您的full活動從兼容性包FragmentActivity擴展。

這些是您的問題的可能原因。至少我能想到並且非常熟悉的那些。

+0

非常感謝。我認爲問題出現在我的日食中。 – Tolen

+1

所以你沒有解決你的問題呢? – gunar

+0

是的。很遺憾。 :( – Tolen

0

喜歡這裏描述(Add a new activity to the AndroidManifest?),你需要添加一個單獨的每個類的活動標記(它擴展了Activity),並分別通過startActivity()或startActivityForResult()啓動。就你而言,從你發佈的內容來看,清單中沒有「full.class」條目。因此,要擺脫你的錯誤,你需要指定一個像

<activity android:name=".full" /> 

的東西,如果滿級是不是在同一個包就像你MainActivity您可能需要指定包,以及像android:name=".tables.full"。也許你還想把班級的名字改成更具表現力的名字。

+0

@:andd:我已經更新了我的問題。 – Tolen

0

修改清單文件,像下面

<activity android:name=".tables.full"></activity> 

<activity android:name="com.example.tstnetconnwithjson.tables.full"></activity> 
+0

我已經試過這個,但它不工作。 – Tolen

1

你有聲明的所有活動,你有嗎?您必須在清單中聲明所有活動。 例子:

<activity 
      android:name=".YourActivity" 
      android:label="@string/title_activity_your" > 
      <intent-filter> 
      </intent-filter> 
     </activity> 
1

嘗試添加。全在你的清單是這樣的:

<activity 
     android:name=".full" > // not sure if you need tabels.full here or not. Try and see. 

     <intent-filter> 
      <action android:name="com.example.tstnetconnwithjson.tables.FULL" /> 

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

然後在你的onclick這樣開始的活動:

Intent a = new Intent("com.example.tstnetconnwithjson.tables.FULL"); 
startActivity(a);