编码-我的Activity跳转失败

问题描述

我的Activity跳转失败
设置Intent 和manifest无误 ,但 点击后就会 《已停止》

Main.java文件

package com.news_1;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class Main extends Activity {

private ListView listView = null;static String str[] strs;String ttt;Map<String Object> map;List<Map<String Object>> data;// List<Map<String Object>> list;Intent i1;int x i;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    final ProgressDialog myDialog = ProgressDialog.show(Main.this正在连接""please wait..."" true true);    Handler handler2 = new Handler();    new Thread() {        public void run() {            while (ttt == null) {                try {                    sleep(1000);                } catch (InterruptedException e) {                    e.printStackTrace();                }            }            myDialog.dismiss();        }    }.start();    Runnable mTasks = new Runnable() {        public void run() {            Intent intent = new Intent();            intent.setClass(Main.this Activity.class);            startActivity(intent);        }    };    data = new ArrayList<Map<String Object>>();    new Thread() {        @Override        public void run() {            // String myJsonUrl =            // ""http://wolfsayapi.sinaapp.com/news/api.php?act=index&type=1&page=1&size=10"";            String myJsonUrl = ""http://wolfsayapi.sinaapp.com/news/api.php?act=index&page=1&size=40"";            HttpGet httpRequest = new HttpGet(myJsonUrl);            String strResult = """";            try {                HttpClient httpClient = new DefaultHttpClient();                HttpResponse httpResponse = httpClient.execute(httpRequest);                if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {                    strResult = EntityUtils.toString(httpResponse                            .getEntity());                }            } catch (ClientProtocolException e) {                Log.i(""DDD""protocol error"");                e.printStackTrace();            } catch (IOException e) {                Log.i(""DDD""IO error"");                e.printStackTrace();            }            try {                JSONArray jsonObjs = new JSONObject(strResult)                        .getJSONArray(""data"");                for (int i = 0; i < jsonObjs.length(); i++) {                    JSONObject jsonObj = (JSONObject) jsonObjs.opt(i);                    ttt = jsonObj.getString(""title"");                    Log.i(""DDD""return: "" + ttt);                    map = new HashMap<String Object>();                    map.put(""id"" jsonObj.getString(""id""));                    map.put(""img"" jsonObj.getString(""image""));                    map.put(""title"" jsonObj.getString(""title""));                    map.put(""time"" jsonObj.getString(""time""));                    data.add(map);                }                // setData(data);                Message msg = new Message();                msg.what = 200;                handler.sendMessage(msg);            } catch (JSONException e) {                e.printStackTrace();            }        }    }.start();}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to the action bar if it is present.    getMenuInflater().inflate(R.menu.main menu);    return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {    int id = item.getItemId();    if (id == R.id.action_settings) {        return true;    }    return super.onOptionsItemSelected(item);}private Handler handler = new Handler() {    public void handleMessage(android.os.Message msg) {        if (msg.what == 200) {            setData();        }    };};public void setData() {    listView = (ListView) findViewById(R.id.list);    listView.setAdapter(new Myadapter(this data));    listView.setOnItemClickListener(bln);}// public List<Map<String Object>> getData() {// data = new ArrayList<Map<String Object>>();// for (i = 1; i <= 16; i++) {// map = new HashMap<String Object>();// map.put(""img"" R.drawable.wolfsay);// map.put(""title"" ttt);// map.put(""time""time"");// data.add(map);// }// return data;// }private ListView.OnItemClickListener bln = new ListView.OnItemClickListener() {    @Override    public void onItemClick(AdapterView<?> arg0 View arg1 int arg2            long arg3) {        // Log.i(""data->"""+data.get(arg2).get(""title""));        x = (Integer) map.get(arg1);        i1 = new Intent(Main.this NewsPage.class);        Bundle bundle = new Bundle();        bundle.putString(""title"" (String) data.get(arg2).get(""title""));        bundle.putInt(""id"" x);        i1.putExtras(bundle);        startActivity(i1);        return;    }};

}

NewsPage.java文件

package com.news_1;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;

public class NewsPage extends Activity
{
TextView t1t2;
String url=""http://wolfsayapi.sinaapp.com/news/api.php?act=content&id="";
String resulttext;
HttpResponse httpResponse2=null;
Bundle bundle = this.getIntent().getExtras();
String title = bundle.getString(""title"");
int id=bundle.getInt(""id"");
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.newspage);
new Thread() {
public void run()
{
HttpGet httpRequest2 = new HttpGet(url+id);
String strResult2 = """";
try {
HttpClient httpClient2 = new DefaultHttpClient();
HttpResponse httpResponse2 = httpClient2.execute(httpRequest2);
if (httpResponse2.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
strResult2 = EntityUtils.toString(httpResponse2
.getEntity());
}
} catch (ClientProtocolException e) {
Log.i(""AAA""protocol error"");
e.printStackTrace();
} catch (IOException e) {
Log.i(""AAA""IO error"");
e.printStackTrace();
}
try {
text=new JSONObject(strResult2).getString(""content"");
Log.i(""AAA""return: "" + text);
// setData(data);
Message msg2 = new Message();
msg2.what=200;
handler3.sendMessage(msg2);
} catch (JSONException e) {
e.printStackTrace();
}
}
}.start();
}
@SuppressLint(""HandlerLeak"")
private Handler handler3 =new Handler(){
public void handleMessage(android.os.Message msg2)
{
if(msg2.what==200)
{
setLayout();
}

    };};public void setLayout(){    t1=(TextView)this.findViewById(R.id.title);    t1.setText(title);    t2=(TextView)this.findViewById(R.id.content);    t2.setText(text);}

}

Manifest.xml文件

<?xml version=""1.0"" encoding=""utf-8""?>
package=""com.news_1""
android:versionCode=""1""
android:versionName=""1.0"" >

<uses-sdk    android:minSdkVersion=""8""    android:targetSdkVersion=""17"" /><application    android:allowBackup=""true""    android:icon=""@drawable/ic_launcher""    android:label=""@string/app_name""    android:theme=""@android:style/Theme.NoTitleBar"" >    <activity        android:name=""com.news_1.Main""        android:label=""@string/app_name"" >        <intent-filter>            <action android:name=""android.intent.action.MAIN"" />            <category android:name=""android.intent.category.LAUNCHER"" />        </intent-filter>    </activity>    <activity        android:name=""com.news_1.NewsPage""        android:label=""@string/app_name"" >    </activity></application><uses-permission android:name=""android.permission.INTERNET"" />

我不知道是什么错误,只要点击 进行跳转 就会 停止,Intent Manifest文件 网络权限都没问题 这个问题折磨了我很久
望大师指教

解决方案

ACtivity跳转

解决方案二:
你把错误报告贴出来看看,看代码头晕

时间: 2024-09-14 10:01:42

编码-我的Activity跳转失败的相关文章

页面跳转-请教一个Activity跳转到另外一个Activity失败的问题

问题描述 请教一个Activity跳转到另外一个Activity失败的问题 package com.example.t; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; impo

Activity跳转与返回

Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; m

Android 实现两个Activity跳转实例_Android

1.关于从Activity A跳转到Activity B 其中Activity A中有一个VideoView,Activity B中有一个MediaPlayer. 两个不同的视频的跳转,前面我是在onStop()方法中销毁VideoView(因为MediaPlayer是全局共用的,而VideoView内包含MediaPlayer),但是每次进入Activity B视频播放了一点 就会弹出了,导致视频B播放失败 public class MovieSynopsis extends BaseActi

activity跳转效果-Activity页面跳转怎样实现从下往上覆盖的效果

问题描述 Activity页面跳转怎样实现从下往上覆盖的效果 在网上搜索基本实现了activity跳转从下往上的功能,但是效果不是覆盖的感觉而是底下的activity变没了之后,怎么让底下的activity感觉是被另一个activity是从下被覆盖掉的. 解决方案 activity.overridePendingTransition(进场动画, 出场动画); 解决方案二: 在启动跳转的地方添加overridePendingTransition(int resId,int resId);这两个参数

navigateurl-xml 文件内的NavigateUrl路径在本机成功,服务器页面跳转失败。

问题描述 xml 文件内的NavigateUrl路径在本机成功,服务器页面跳转失败. xml 文件内容如下: <?xml version="1.0" encoding="utf-8" ?> 连接字符串如下: <!--连接字符串--> 服务器报错如下: A network-related or instance-specific error occurred while establishing a connection to SQL Serv

android 监听返回键怎么从activity 跳转到tabhost主页且选项卡不消失?

问题描述 android 监听返回键怎么从activity 跳转到tabhost主页且选项卡不消失? 我用activity 和tabhost配套使用,当监听返回键时跳转到tabhost主页,发现选项卡消失,不只是为什么?求各位大神解答?谢谢! 解决方案 那要看你点击返回键的函数里面是怎么跳转的

cas sso 配置了,登录有通过数据库,但是跳转失败

问题描述 cas sso 配置了,登录有通过数据库,但是跳转失败 1.生成安全证书:运行cmd 切换到tomcat的目录下:输入命令 " keytool -genkey -alias localhost -keyalg RSA -storepass localhost -keystore D:ssotomcat-caslocalhost.keystore -validity 3600 " //此时会生成别名为abc的abc.keystore 文件. 密码是abc 123 导出证书到ke

android的activity跳转到另一个activity_Android

开发环境:android4.1.1 实验功能:在第一个Hello World!为标签的activity中显示good,该界面中有一个名为Next的按钮.点击Next按钮进入到第二个activity中去,第二个界面中只有1个Close按钮.当然,据网上有人将要比较安全的实现关闭程序的功能也不是挺简单的,因为android有专门的退出键返回键等.所以该Close按钮暂时没去实现它.我的第1个activity为HelloworldActivity,第2个activity为NextActivity. 实

Android activity跳转与线程启动问题

问题描述 Android activity跳转与线程启动问题 package com.example.gteetcard; import android.annotation.SuppressLint;import android.app.Activity;import android.content.Intent;import android.media.MediaPlayer;import android.os.Bundle;import android.os.Handler;import