2014-09-05 70 views
1

因此,當我點擊圖片併發送切換活動的意圖時,我的應用程序崩潰。 HERE是項目,如果有人想看。Android - 點擊發送給其他活動的圖片時應用程序崩潰

//MainActivity.java 

package com.example.sqllite; 

import java.util.ArrayList; 

import com.example.kontaktysqllite.R; 
import android.app.ListActivity; 
import android.app.ProgressDialog; 
import android.content.Context; 
import android.content.Intent; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.webkit.WebView; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class MainActivity extends ListActivity{ 

    private ProgressDialog m_ProgressDialog = null; 
    private ArrayList<Order> m_orders = null; 
    private OrderAdapter m_adapter; 
    private Runnable viewOrders; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     m_orders = new ArrayList<Order>(); 
     this.m_adapter = new OrderAdapter(this, R.layout.row, m_orders); 
     setListAdapter(this.m_adapter); 

     viewOrders = new Runnable(){ 

      @Override 
      public void run() { 
       getOrders(); 
      } 
     }; 
     Thread thread = new Thread(null, viewOrders, "MagentoBackground"); 
     thread.start(); 
     m_ProgressDialog = ProgressDialog.show(MainActivity.this,  
       "Please wait...", "Retrieving data ...", true); 
    } 
    private Runnable returnRes = new Runnable() { 
     @Override 
     public void run() { 
      if(m_orders != null && m_orders.size() > 0){ 
       m_adapter.notifyDataSetChanged(); 
       for(int i=0;i<m_orders.size();i++) 
       m_adapter.add(m_orders.get(i)); 
      } 
      m_ProgressDialog.dismiss(); 
      m_adapter.notifyDataSetChanged(); 
     } 
    }; 
    private void getOrders(){ 
      try{ 
       final ZarzadcaBazy zb = new ZarzadcaBazy(this); 


       m_orders = new ArrayList<Order>(); 
       Cursor k = zb.dajWszystkie(); 
       while (k.moveToNext()) { 
        String message = k.getString(1); 
        Order order = new Order(); 
        order.setOrderLink(message); 
        order.setOrderName("szablon"); 
        m_orders.add(order); 
        Log.i("ARRAY", ""+ m_orders.size()); 
       } 


      } catch (Exception e) { 
       Log.e("BACKGROUND_PROC", e.getMessage()); 
      } 
      runOnUiThread(returnRes); 
     } 
    private class OrderAdapter extends ArrayAdapter<Order> { 

     private ArrayList<Order> items; 

     public OrderAdapter(Context context, int textViewResourceId, ArrayList<Order> items) { 
       super(context, textViewResourceId, items); 
       this.items = items; 
     } 
     @Override 
     public View getView(int position, View convertView, ViewGroup parent) 
     { 
       View v = convertView; 
       if (v == null) 
       { 
        LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        v = vi.inflate(R.layout.row, null); 
       } 
       Order o = items.get(position); 
       if (o != null) 
       { 
         TextView name = (TextView) v.findViewById(R.id.row_textView); 
         ImageView img = (ImageView)v.findViewById(R.id.row_imageview); 
         if (name != null) 
         { 
          name.setText("Name: "+o.getOrderName());        
         } 

         img.setOnClickListener(new View.OnClickListener() 
         { 
          public void onClick(View view) 
          {  
           Intent intent = new Intent(MainActivity.this, Activity2.class); 
           //intent.putExtra("urlString", "https://beta2.createer.com/Action/Show/777203e8-5b53-462d-863b-c4e10a3abd5b/"); 
           startActivity(intent); 
          } 
         }); 
       } 

       return v; 
     } 
} 
} 

Activity2.java:

//Activity2.java 

package com.example.sqllite; 
import com.example.kontaktysqllite.R; 

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.View; 
import android.webkit.WebView; 
import android.widget.Button; 

public class Activity2 extends Activity 
{ 
    private WebView mWebView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.layout2);  
    } 
} 

09-05 13:12:56.915: D/AbsListView(16209): unregisterIRListener() is called 
09-05 13:13:16.354: D/AndroidRuntime(16209): Shutting down VM 
09-05 13:13:16.354: W/dalvikvm(16209): threadid=1: thread exiting with uncaught exception (group=0x418e7da0) 
09-05 13:13:16.364: E/AndroidRuntime(16209): FATAL EXCEPTION: main 
09-05 13:13:16.364: E/AndroidRuntime(16209): Process: com.example.kontaktysqllite, PID: 16209 
09-05 13:13:16.364: E/AndroidRuntime(16209): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.kontaktysqllite/com.example.sqllite.Activity2}; have you declared this activity in your AndroidManifest.xml? 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1648) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.app.Activity.startActivityForResult(Activity.java:3511) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.app.Activity.startActivityForResult(Activity.java:3472) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.app.Activity.startActivity(Activity.java:3714) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.app.Activity.startActivity(Activity.java:3682) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at com.example.sqllite.MainActivity$OrderAdapter$1.onClick(MainActivity.java:115) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.view.View.performClick(View.java:4633) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.view.View$PerformClick.run(View.java:19330) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.os.Handler.handleCallback(Handler.java:733) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.os.Handler.dispatchMessage(Handler.java:95) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.os.Looper.loop(Looper.java:157) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at android.app.ActivityThread.main(ActivityThread.java:5356) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at java.lang.reflect.Method.invokeNative(Native Method) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at java.lang.reflect.Method.invoke(Method.java:515) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
09-05 13:13:16.364: E/AndroidRuntime(16209): at dalvik.system.NativeStart.main(Native Method) 

我真的不能讀的logcat等找到我的暴跌背後的原因logcat的真的很難。 可能是什麼問題?

+3

您是否在清單中添加了「Activity2」? – Apoorv 2014-09-05 11:18:05

+1

https://stackoverflow.com/questions/3832619/add-a-new-activity-to-the-androidmanifest – fardjad 2014-09-05 11:19:34

+0

是的,先生,我做到了。這裏是清單http://pastebin.com/wiwvZeFt – 2014-09-05 11:20:21

回答

3

變化在AndroidManifest.xml這個

<activity 
    android:name="Activity2" 
    android:label="@string/app_name"> 
</activity> 

進入這個

<activity 
    android:name="com.example.sqllite.Activity2" 
    android:label="@string/app_name"> 
</activity> 
1
你必須把包名佈局名之前在AndroidManifest.xml 這樣

<activity 
    android:name="com.example.sqllite.Activity2" 
    android:label="@string/app_name"> 
</activity> 

或在佈局名稱 之前放點:

<activity 
    android:name=".Activity2" 
    android:label="@string/app_name"> 
</activity> 
相關問題