Android - 单击发送到其他活动的图像时应用程序崩溃

时间:2014-09-05 11:16:24

标签: java android android-intent android-activity

因此,当我点击图片并发送切换活动的意图时,我的应用程序崩溃了。 如果有人想看,HERE就是项目。

//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);     
  }
} 

和logcat

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,因此找到崩溃背后的原因真的很难。 可能是什么问题?

2 个答案:

答案 0 :(得分: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 :(得分:1)

您必须在AndroidManifest.xml中将包名称放在布局名称之前 像这样:

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

或将Dot放在布局名称之前 像这样:

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